/** * Assumes that the DB represented by JuConnUtil is none of the * DbTypes specified. * @param connUtil JuConnUtil * @param types Types we assume the DB is not */ public static void dbIsNot(JuConnUtil connUtil, DbType... types) { DbType actualType = connUtil.getDbType(); for (DbType type : types) { Assume.assumeFalse("Assumed DB was not " + type, type == actualType); } }
@Override public void createSchema(DbSchemaBuilder builder) { throw new JuDbException("Schema Creation not yet implemented for " + this.connUtil.getDbType()); }
@Override public void dropSchema(SchemaInfo schemaInfo, String... users) { throw new JuDbException("Schema Dropping not yet implemented for " + this.connUtil.getDbType()); } }
@Override public List<String> getSequenceNames() { throw new JuDbException("Sequences not supported by " + this.connUtil.getDbType()); }
@Override public Long getNextValueFromSequence(String sequenceName) { throw new JuDbException("Sequences not supported by " + this.connUtil.getDbType()); }
@Override public List<String> processMetaData(DatabaseMetaData dbmd) throws SQLException { // TODO: Consider Schema names for other DBs; refactor String schemaName = null; if (connUtil.getDbType() == DbType.ORACLE) { schemaName = getUserName(); } ResultSet rs = dbmd.getTables(schemaName, schemaName, null, new String[]{"TABLE"}); List<String> tableNames = new ArrayList<>(); while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); // We check if the TableName already exists in the list as // Oracle seems to return the same table names multiple times on some // Schemas... if (!tableNames.contains(tableName)) { tableNames.add(tableName); } } rs.close(); Collections.sort(tableNames); return tableNames; } });
@Override public SchemaInfo getSchemaInfo() { if (this.connUtil.getDbType() == DbType.MYSQL) { // Get the Schema info from the URL (has the form jdbc:mysql://host/schema) RegexUtil ru = new RegexUtil(".*/([^/]+)"); if (!ru.matches(this.getUrl())) { return null; } else { String schemaName = ru.getMatches(this.getUrl())[0].getGroups()[0]; return new SchemaInfoImpl(schemaName, null); } } else if (this.connUtil.getDbType() == DbType.ORACLE){ return new SchemaInfoImpl(this.getUserName(), null); } else { throw new UnsupportedOperationException("Not yet implemented for " + this.connUtil.getDbType()); } }
@Override public List<String> getPrimaryKeyColumns(String tableName) { final String actualTableName = this.connUtil.getDbType().getDbSpecificHandler(this.connUtil).convertTableNameCasing(tableName); List<String> columnNames = this.connUtil.extractDatabaseMetaData(new DatabaseMetaDataCallback<List<String>>() { @Override public List<String> processMetaData(DatabaseMetaData dbmd) throws SQLException { ResultSet rs = dbmd.getPrimaryKeys(null, null, actualTableName); List<String> columnNames = new ArrayList<>(); while (rs.next()) { columnNames.add(rs.getString("COLUMN_NAME")); } rs.close(); return columnNames; } }); return columnNames; }
if (this.connUtil.getDbType() == DbType.MYSQL) { schemaInfos = this.connUtil.extractDatabaseMetaData(new DatabaseMetaDataCallback<SchemaInfos>() { @Override
if (this.connUtil.getDbType() == DbType.ORACLE && connection instanceof Proxy) { try { unwrappedConn = connection.unwrap(Connection.class);
final DbType dbType = this.connUtil.getDbType(); final String metaDataUserName = this.connUtil.getMetaDataInfo().getUserName();
Assert.assertEquals("Catalogs not supported yet", 1, schemaInfos.size()); if (adminConnUtil.getDbType() == DbType.MYSQL) {