List of usage examples for javax.sql.rowset CachedRowSet getBoolean
boolean getBoolean(int columnIndex) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:uk.ac.ox.it.ords.api.database.structure.services.impl.hibernate.StructureServiceImpl.java
protected List<HashMap<String, Object>> getIndexesFromPostgres(String databaseName, String databaseServer, String table) throws Exception { String query = "SELECT " + "i.relname as indexname, " + "idx.indrelid::regclass as tablename, " + "ARRAY( " + "SELECT pg_get_indexdef(idx.indexrelid, k + 1, true) " + "FROM generate_subscripts(idx.indkey, 1) as k " + "ORDER BY k " + ") as colnames, " + "indisunique as isunique, " + "indisprimary as isprimary " + "FROM " + "pg_index as idx " + "JOIN pg_class as i " + "ON i.oid = idx.indexrelid " + "WHERE CAST(idx.indrelid::regclass as text) = quote_ident(?)"; List<HashMap<String, Object>> indexes = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> index; String type;//from ww w . j av a2s . c o m ArrayList<Object> parameters = new ArrayList<Object>(); parameters.add(table); CachedRowSet rs = this.runJDBCQuery(query, parameters, databaseServer, databaseName); // List<Object[]> results = this.runSQLQuery(command, null, null, null); while (rs.next()) { index = new HashMap<String, Object>(); index.put("name", rs.getString("indexname")); ArrayList<String> columns = new ArrayList<String>(); Array sqlArray = rs.getArray("colnames"); Object[] cols = (Object[]) sqlArray.getArray(); // ResultSet columnSet = sqlArray.getResultSet(); for (Object column : cols) { // // PG may store the index columns as quoted identifiers, in which case we need // to unquote them to return via the API // columns.add(unquote(column.toString())); } index.put("columns", columns); if (rs.getBoolean("isprimary")) { type = "PRIMARY"; } else if (rs.getBoolean("isunique")) { type = "UNIQUE"; } else { type = "INDEX"; } index.put("type", type); indexes.add(index); } return indexes; }