/** * Creates a new DbDataUtil instance using the specified Connection and the Schema * from the ConnectionInfo * @param connection Connection instance * @param ConnectionInfo to get the Schema to use * @Deprecated Use constructor with EntityManager */ public DbDataUtil(JuConnUtil connUtil, ConnectionInfo connectionInfo) { this(connUtil, connectionInfo.getSchema()); }
@Override public String getSchema() { return this.getConnectionInfo().getSchema(); }
@Override public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException { ResultSet rs = dbmd.getTables(connectionInfo.getSchema(), null, null, new String[]{"TABLE"}); List<String> tableNames = new ArrayList<>(); while (rs.next()) { String tableName = rs.getString("TABLE_NAME").toUpperCase(); // 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; } });
@Test public void dbConnection() { Assert.assertEquals("Derby Test DB", this.connectionInfo.getName()); Assert.assertNull(this.connectionInfo.getSchema()); CustomObject o = new CustomObject(); this.entityManager.persist(o); Assert.assertNotNull(o.getId()); }