throws ClassNotFoundException, SQLException, NullPointerException,
AccessControlException,UnsatisfiedLinkError,NumberFormatException {
int i;
Connection oConn;
DatabaseMetaData oMData;
Statement oAcct = null;
ResultSet oRSet;
String TableTypes[] = new String[1];
DBTable oTable;
String sCatalog;
String sSchema;
String sTableName;
Iterator oTableIterator;
String[] aExclude;
oTableMap = new HashMap<String,DBTable>(255);
oGlobalTableMap = oTableMap ;
if (DebugFile.trace)
{
DebugFile.writeln("hipergate package build " + DBBind.VERSION);
DebugFile.envinfo();
DebugFile.writeln("Begin DBBind.initialize("+sProfile+")");
DebugFile.incIdent();
}
sProfileName = sProfile;
// ****************
// Load JDBC driver
loadDriver(oProfEnvProps);
if (DebugFile.trace) DebugFile.writeln("Load Driver " + oProfEnvProps.getProperty("driver") + " : OK\n" );
if (DebugFile.trace) DebugFile.writeln("Trying to connect to " + oProfEnvProps.getProperty("dburl") + " with user " + oProfEnvProps.getProperty("dbuser"));
// **********************************************************
// Get database connection parameters from file hipergate.cnf
// New for v2.2 *
try {
DriverManager.setLoginTimeout(Integer.parseInt(oProfEnvProps.getProperty("logintimeout", "20")));
} catch (Exception x) {
if (DebugFile.trace) DebugFile.writeln("DriverManager.setLoginTimeout() "+x.getClass().getName()+" "+x.getMessage());
}
// **************
try {
oConn = DriverManager.getConnection(oProfEnvProps.getProperty("dburl"),
oProfEnvProps.getProperty("dbuser"),
oProfEnvProps.getProperty("dbpassword"));
}
catch (SQLException e) {
if (DebugFile.trace) DebugFile.writeln("DriverManager.getConnection("+oProfEnvProps.getProperty("dburl")+","+oProfEnvProps.getProperty("dbuser")+", ...) SQLException [" + e.getSQLState() + "]:" + String.valueOf(e.getErrorCode()) + " " + e.getMessage());
oConnectXcpt = new SQLException("DriverManager.getConnection("+oProfEnvProps.getProperty("dburl")+","+oProfEnvProps.getProperty("dbuser")+", ...) "+e.getMessage(), e.getSQLState(), e.getErrorCode());
throw (SQLException) oConnectXcpt;
}
if (DebugFile.trace) {
DebugFile.writeln("Database Connection to " + oProfEnvProps.getProperty("dburl") + " : OK\n" );
DebugFile.writeln("Calling Connection.getMetaData()");
}
oMData = oConn.getMetaData();
if (DebugFile.trace) DebugFile.writeln("Calling DatabaseMetaData.getDatabaseProductName()");
sDatabaseProductName = oMData.getDatabaseProductName();
if (DebugFile.trace) {
DebugFile.writeln("Database is \"" + sDatabaseProductName + "\"");
DebugFile.writeln("Product version " + oMData.getDatabaseProductVersion());
DebugFile.writeln(oMData.getDriverName() + " " + oMData.getDriverVersion());
DebugFile.writeln("Max connections " + String.valueOf(oMData.getMaxConnections()));
DebugFile.writeln("Max statements " + String.valueOf(oMData.getMaxStatements()));
}
if (sDatabaseProductName.equals(DBMSNAME_POSTGRESQL))
iDatabaseProductId = DBMS_POSTGRESQL;
else if (sDatabaseProductName.equals(DBMSNAME_MSSQL))
iDatabaseProductId = DBMS_MSSQL;
else if (sDatabaseProductName.equals(DBMSNAME_ORACLE))
iDatabaseProductId = DBMS_ORACLE;
else if (sDatabaseProductName.equals(DBMSNAME_MYSQL))
iDatabaseProductId = DBMS_MYSQL;
else if (sDatabaseProductName.equals(DBMSNAME_ACCESS))
iDatabaseProductId = DBMS_ACCESS;
else if (sDatabaseProductName.equals(DBMSNAME_SQLITE))
iDatabaseProductId = DBMS_SQLITE;
else if (sDatabaseProductName.equals("StelsDBF JDBC driver") ||
sDatabaseProductName.equals("HXTT DBF"))
iDatabaseProductId = DBMS_XBASE;
else
iDatabaseProductId = DBMS_GENERIC;
Functions.setForDBMS(sDatabaseProductName);
// **********************
// Cache database catalog
sCatalog = oConn.getCatalog();
if (DebugFile.trace) DebugFile.writeln("Catalog is \"" + sCatalog + "\"");
if (DebugFile.trace) DebugFile.writeln("Gather metadata : OK" );
sSchema = oProfEnvProps.getProperty("schema", "");
if (DebugFile.trace) DebugFile.writeln("Schema is \"" + sSchema + "\"");
i = 0;
TableTypes[0] = "TABLE";
if (DBMS_ORACLE==iDatabaseProductId) {
aExclude = new String[]{ "AUDIT_ACTIONS", "STMT_AUDIT_OPTION_MAP", "DUAL",
"PSTUBTBL", "USER_CS_SRS", "USER_TRANSFORM_MAP", "CS_SRS", "HELP",
"SDO_ANGLE_UNITS", "SDO_AREA_UNITS", "SDO_DIST_UNITS", "SDO_DATUMS",
"SDO_CMT_CBK_DML_TABLE", "SDO_CMT_CBK_FN_TABLE", "SDO_CMT_CBK_DML_TABLE",
"SDO_PROJECTIONS", "SDO_ELLIPSOIDS", "SDO_GEOR_XMLSCHEMA_TABLE",
"SDO_GR_MOSAIC_0", "SDO_GR_MOSAIC_1", "SDO_GR_MOSAIC_2", "SDO_GR_MOSAIC_3",
"SDO_TOPO_RELATION_DATA", "SDO_TOPO_TRANSACT_DATA", "SDO_TXN_IDX_DELETES",
"DO_TXN_IDX_EXP_UPD_RGN", "SDO_TXN_IDX_INSERTS", "SDO_CS_SRS", "IMPDP_STATS",
"OLAP_SESSION_CUBES", "OLAP_SESSION_DIMS", "OLAPI_HISTORY",
"OLAPI_IFACE_OBJECT_HISTORY", "OLAPI_IFACE_OP_HISTORY", "OLAPI_MEMORY_HEAP_HISTORY",
"OLAPI_MEMORY_OP_HISTORY", "OLAPI_SESSION_HISTORY", "OLAPTABLEVELS","OLAPTABLEVELTUPLES",
"OLAP_OLEDB_FUNCTIONS_PVT", "OLAP_OLEDB_KEYWORDS", "OLAP_OLEDB_MDPROPS","OLAP_OLEDB_MDPROPVALS",
"OGIS_SPATIAL_REFERENCE_SYSTEMS", "SYSTEM_PRIVILEGE_MAP", "TABLE_PRIVILEGE_MAP" };
if (DebugFile.trace) {
ResultSet oSchemas = null;
try {
int iSchemaCount = 0;
oSchemas = oMData.getSchemas();
while (oSchemas.next()) {
DebugFile.writeln("schema name = " + oSchemas.getString(1));
iSchemaCount++;
}
oSchemas.close();
oSchemas = null;
if (0==iSchemaCount) DebugFile.writeln("no schemas found");
}
catch (Exception sqle) {
try { if (null!=oSchemas) oSchemas.close();} catch (Exception ignore) {}
DebugFile.writeln("SQLException at DatabaseMetaData.getSchemas() " + sqle.getMessage());
}
DebugFile.writeln("DatabaseMetaData.getTables(" + sCatalog + ", null, %, {TABLE})");
}
oRSet = oMData.getTables(sCatalog, null, "%", TableTypes);
while (oRSet.next()) {
if (oRSet.getString(3).indexOf('$')<0 && !in(oRSet.getString(3).toUpperCase(), aExclude)) {
oTable = new DBTable(sCatalog, sSchema, oRSet.getString(3), ++i);
sTableName = oTable.getName().toLowerCase();
if (oTableMap.containsKey(sTableName))
oTableMap.remove(sTableName);
oTableMap.put(sTableName, oTable);
if (DebugFile.trace)
DebugFile.writeln("Reading table " + oTable.getName());
}
else if (DebugFile.trace)
DebugFile.writeln("Skipping table " + oRSet.getString(3));
} // wend
}
else {
if (DBMS_POSTGRESQL==iDatabaseProductId)
aExclude = new String[]{ "sql_languages", "sql_features",
"sql_implementation_info", "sql_packages",
"sql_sizing", "sql_sizing_profiles",
"pg_ts_cfg", "pg_logdir_ls",
"pg_ts_cfgmap", "pg_ts_dict", "pg_ts_parses",
"pg_ts_parser", "pg_reload_conf" };
else if (DBMS_MSSQL==iDatabaseProductId)
aExclude = new String[]{ "syscolumns", "syscomments", "sysdepends",
"sysfilegroups", "sysfiles" , "sysfiles1",
"sysforeignkeys", "sysfulltextcatalogs",
"sysfulltextnotify", "sysindexes",
"sysindexkeys", "sysmembers", "sysobjects",
"syspermissions", "sysproperties",
"sysprotects", "sysreferences", "systypes",
"sysusers" };
else
aExclude = null;
if (DebugFile.trace)
DebugFile.writeln("DatabaseMetaData.getTables(" + sCatalog + ", " + sSchema + ", %, {TABLE})");
if ((DBMS_ACCESS==iDatabaseProductId)) {
oAcct = oConn.createStatement();
oRSet = oAcct.executeQuery("SELECT NULL,NULL,Name FROM MSysObjects WHERE Type=1 AND Flags<>-2147483648");
} else {
oRSet = oMData.getTables(sCatalog, sSchema, "%", TableTypes);
}
// For each table, keep its name in a memory map
if (sSchema.length()>0) {