Commits

tbrugz  committed c522992

dbms: added initial MSAccessDatabaseMetaData ; + some small fixes

  • Participants
  • Parent commits 690429b

Comments (0)

Files changed (5)

File src/tbrugz/sqldump/JDBCSchemaGrabber.java

 	static String[] DEFAULT_SCHEMA_NAMES = {
 		"public", //postgresql, h2, hsqldb
 		"APP",    //derby
+		"",       //"schema-less" databases
 	};
 	
 	Connection conn;
 
 		feats = DBMSResources.instance().databaseSpecificFeaturesClass();
 		DatabaseMetaData dbmd = feats.getMetadataDecorator(conn.getMetaData());
+		//log.info("feats/metadata: "+feats+" / "+dbmd);
 		SQLUtils.ConnectionUtil.showDBInfo(conn.getMetaData());
 		
 		SchemaModel schemaModel = new SchemaModel();
 		String schemaPattern = papp.getProperty(SQLDump.PROP_DUMPSCHEMAPATTERN);
 		
 		if(schemaPattern==null) {
-			List<String> schemas = SQLUtils.getSchemaNames(conn.getMetaData());
+			List<String> schemas = SQLUtils.getSchemaNames(dbmd);
 			log.info("schemaPattern not defined. schemas avaiable: "+schemas);
 			schemaPattern = Utils.getEqualIgnoreCaseFromList(schemas, papp.getProperty(SQLDump.CONN_PROPS_PREFIX + SQLUtils.ConnectionUtil.SUFFIX_USER));
 			boolean equalsUsername = false;
 			return null;
 		}
 		
-		log.info("schema dump... schema(s): "+schemaPattern);
+		log.info("schema dump... schema(s): '"+schemaPattern+"'");
 
 		//init stat objects
 		tablesCountByTableType = new HashMap<TableType, Integer>();
 			catch(AbstractMethodError e) {
 				log.warn("abstract method error: "+e);
 			}
+			catch(RuntimeException e) {
+				log.warn("runtime exception grabbing functions: "+e);
+			}
 			catch(SQLException e) {
 				log.warn("sql exception grabbing procedures: "+e);
 			}
 			catch(AbstractMethodError e) {
 				log.warn("abstract method error: "+e);
 			}
+			catch(RuntimeException e) {
+				log.warn("runtime exception grabbing functions: "+e);
+			}
 			catch(SQLException e) {
 				log.warn("sql exception grabbing functions: "+e);
 			}
 			dbmsfeatures.addTableSpecificFeatures(table, rs);
 			
 			try {
-				String fullTablename = (schemaPattern==null?"":table.getSchemaName()+".")+tableName;
+				String fullTablename = table.getQualifiedName();
 				log.debug("getting columns from "+fullTablename);
 
 				//columns

File src/tbrugz/sqldump/SQLUtils.java

 	}
 
 	public static List<String> getSchemaNames(DatabaseMetaData dbmd) throws SQLException {
+		if(dbmd.getSchemas()==null) {
+			List<String> schemas = new ArrayList<String>();
+			schemas.add("");
+			return schemas;
+		}
 		return getColumnValues(dbmd.getSchemas(), "table_schem");
 	}
 

File src/tbrugz/sqldump/dbmsfeatures/MSAccessDatabaseMetaData.java

+package tbrugz.sqldump.dbmsfeatures;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import tbrugz.sqldump.def.AbstractDatabaseMetaDataDecorator;
+
+public class MSAccessDatabaseMetaData extends AbstractDatabaseMetaDataDecorator {
+
+	static Log log = LogFactory.getLog(MSAccessDatabaseMetaData.class);
+
+	public MSAccessDatabaseMetaData(DatabaseMetaData metadata) {
+		this.metadata = metadata;
+	}
+	
+	@Override
+	public ResultSet getSchemas() throws SQLException {
+		return null;
+	}
+	
+	@Override
+	public ResultSet getTables(String catalog, String schemaPattern,
+			String tableNamePattern, String[] types) throws SQLException {
+		Connection conn = metadata.getConnection();
+		
+		String sql = "select null as TABLE_CAT, null as TABLE_SCHEM, name as TABLE_NAME, '' as REMARKS, "
+				+"iif([Flags] = 0, 'TABLE', 'SYSTEM TABLE') as TABLE_TYPE\n"
+				//+"[Type] as TABLE_TYPE\n"
+				+"from [MSysObjects] "
+				+"where [Type] = 1 "
+				+"order by [Type], [Name]";
+		PreparedStatement st = conn.prepareStatement(sql);
+		log.debug("sql:\n"+sql);
+		return st.executeQuery();
+	}
+	
+	@Override
+	public ResultSet getColumns(String catalog, String schemaPattern,
+			String tableNamePattern, String columnNamePattern)
+			throws SQLException {
+		log.info("getColumns() from: "+tableNamePattern); 
+		//return null;
+		return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern);
+	}
+	
+	@Override
+	public ResultSet getPrimaryKeys(String catalog, String schema, String table)
+			throws SQLException {
+		//return null;
+		return super.getPrimaryKeys(catalog, schema, table);
+	}
+}

File src/tbrugz/sqldump/dbmsfeatures/MSAccessFeatures.java

 package tbrugz.sqldump.dbmsfeatures;
 
+import java.sql.DatabaseMetaData;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 	public Map<Class<?>, Class<?>> getColumnTypeMapper() {
 		return columnTypeMapper;
 	}
+	
+	@Override
+	public DatabaseMetaData getMetadataDecorator(DatabaseMetaData metadata) {
+		return new MSAccessDatabaseMetaData(metadata);
+	}
 
 }

File src/tbrugz/sqldump/util/Utils.java

 	
 	public static String getEqualIgnoreCaseFromList(Collection<String> col, String str) {
 		for(String s: col) {
+			if(s==null) { continue; }
 			if(s.equalsIgnoreCase(str)) { return s; }
 		}
 		return null;