updating SQL plugin with latest Quantum code
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / adapters / GenericAdapter.java
1 package net.sourceforge.phpdt.sql.adapters;
2
3 import java.sql.Connection;
4 import java.sql.DatabaseMetaData;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
11 import net.sourceforge.phpdt.sql.model.Entity;
12 import net.sourceforge.phpdt.sql.model.EntityFactory;
13
14
15 public class GenericAdapter extends DatabaseAdapter {
16
17         public String getShowTableQuery(DatabaseInfo info) {
18                 return null;
19         }
20     public String getShowViewQuery(DatabaseInfo info) {
21                 return null;
22     }
23     
24     public String getShowSequenceQuery(DatabaseInfo info) {
25         return null;
26     }
27
28     /**
29      * @param connection -
30      *      a database 
31      * @param schema - 
32      *      a schema name to filter on, or null to return all entities from all filters
33      * @param type - 
34      *      the type of entities (TABLES, VIEWS, etc.) to get
35      * @return
36      */
37     protected List getEntitiesList(Bookmark bookmark, Connection connection, String type) 
38         throws SQLException {
39         
40         List list = new ArrayList();
41         DatabaseMetaData metaData = connection.getMetaData();
42         ResultSet set = metaData.getTables(
43             null, bookmark.getSchema(), "%", new String[] { type }); 
44         while (set.next()) {
45             String schema = set.getString("TABLE_SCHEM");  
46             schema = (schema == null) ? "" : schema.trim();
47             String tableName = set.getString("TABLE_NAME").trim();
48             
49             if (tableName.length() > 0) {
50                 Entity entity = EntityFactory.getInstance().create(
51                         bookmark, schema, tableName, type);
52                 if (entity != null) {
53                     list.add(entity);
54                 }
55             }
56         }
57         set.close();
58         return list;
59     }
60     
61 }