public SortedMap < String , Schema > getSchemas ( ) throws SQLException { synchronized ( getSchemasLock ) { if ( getSchemasCache == null ) { SortedMap < String , Schema > newSchemas = new TreeMap <> ( DatabaseMetaData . getCollator ( ) ) ; try ( ResultSet results = metaData . getMetaData ( ) . getSchemas ( ) ) { ResultSetMetaData resultsMeta = results . getMetaData ( ) ; while ( results . next ( ) ) { int colCount = resultsMeta . getColumnCount ( ) ; //System.err.println("DEBUG: Catalog: getSchemas(): colCount=" + colCount); //for(int i=1; i<=colCount; i++) { // resultsMeta.getColumnName(i); // System.err.println("DEBUG: Catalog: getSchemas(): resultsMeta.getColumnName("+i+")=" + resultsMeta.getColumnName(i)); //} //System.err.println("DEBUG: Catalog: getSchemas(): results.getString(\"table_catalog\")=" + results.getString("table_catalog")); //System.err.println("DEBUG: Catalog: getSchemas(): results.getString(\"TABLE_CATALOG\")=" + results.getString("TABLE_CATALOG")); if ( colCount == 1 // PostgreSQL 8.3 only returns one column || results . getString ( "TABLE_CATALOG" ) == null // PostgreSQL 9.4 driver returns null || name . equals ( results . getString ( "TABLE_CATALOG" ) ) // Other driver ) { Schema newSchema = new Schema ( this , results . getString ( "TABLE_SCHEM" ) ) ; if ( newSchemas . put ( newSchema . getName ( ) , newSchema ) != null ) throw new AssertionError ( "Duplicate schema: " + newSchema ) ; } } } getSchemasCache = AoCollections . optimalUnmodifiableSortedMap ( newSchemas ) ; } return getSchemasCache ; } }
Gets all schemas for this catalog keyed by unique name .