1 19 20 package org.netbeans.modules.j2ee.persistence.editor.completion.db; 21 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.util.Map ; 25 import java.util.TreeMap ; 26 27 31 public class Catalog { 32 33 private final DBMetaDataProvider provider; 34 private final String name; 35 36 private Map schemas; 37 38 Catalog(DBMetaDataProvider provider, String name) { 39 this.provider = provider; 40 this.name = name; 41 } 42 43 public String getName() { 44 return name; 45 } 46 47 public synchronized Schema[] getSchemas() throws SQLException { 48 if (schemas == null) { 49 schemas = new TreeMap (); 50 ResultSet rs = null; 51 52 if (name == null) { 53 rs = provider.getMetaData().getSchemas(); 55 } else { 56 rs = provider.getMetaData().getTables(name, "%", "%", new String [] { "TABLE", "VIEW" }); } 64 65 try { 66 while (rs.next()) { 67 String schemaName = rs.getString("TABLE_SCHEM"); Schema schema = new Schema(provider, this, schemaName); 69 schemas.put(schemaName, schema); 70 } 71 } finally { 72 rs.close(); 73 } 74 } 75 76 return (Schema[])schemas.values().toArray(new Schema[schemas.size()]); 77 } 78 79 public synchronized Schema getSchema(String name) throws SQLException { 80 if (schemas == null) { 81 getSchemas(); 82 } 83 84 return (Schema)schemas.get(name); 85 } 86 87 public String toString() { 88 return "Catalog[name='" + name + "']"; } 90 } 91 | Popular Tags |