test table creation in lowercase on Oracle
This commit is contained in:
parent
6c064531ab
commit
0dd8138237
2 changed files with 56 additions and 50 deletions
|
@ -14,6 +14,9 @@ import org.xbib.jdbc.query.OptionsOverride;
|
|||
import org.xbib.jdbc.query.Schema;
|
||||
import org.xbib.jdbc.test.CommonTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Exercise Database functionality with a real Oracle database.
|
||||
*/
|
||||
|
@ -78,4 +81,16 @@ public class OracleTest extends CommonTest {
|
|||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableExists() {
|
||||
db.dropTableQuietly("dbtest");
|
||||
new Schema().addTable("dbtest").addColumn("pk").primaryKey().schema().execute(db);
|
||||
assertTrue(db.tableExists("dbtest"));
|
||||
db.dropTableQuietly("dbtest");
|
||||
assertFalse(db.tableExists("dbtest"));
|
||||
db.ddl("create table \"dbtest\" (pk varchar(1))").execute();
|
||||
assertTrue(db.tableExists("dbtest"));
|
||||
db.dropTableQuietly("dbtest");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,14 +200,24 @@ public class DatabaseImpl implements Database {
|
|||
public boolean tableExists(String tableName, String schemaName) throws DatabaseException {
|
||||
if (tableName != null && connection != null) {
|
||||
try {
|
||||
// schema based check
|
||||
DatabaseMetaData metadata = connection.getMetaData();
|
||||
String normalizedTable = flavor().normalizeTableName(tableName);
|
||||
ResultSet resultSet = metadata.getTables(connection.getCatalog(), schemaName, normalizedTable, new String[]{"TABLE", "VIEW"});
|
||||
try (ResultSet resultSet = metadata.getTables(connection.getCatalog(), schemaName, normalizedTable, new String[]{"TABLE", "VIEW"})) {
|
||||
while (resultSet.next()) {
|
||||
if (normalizedTable.equals(resultSet.getString("TABLE_NAME"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// otherwise, do a simple check
|
||||
try (ResultSet resultSet = metadata.getTables(null, null, tableName, null) ) {
|
||||
while (resultSet.next()) {
|
||||
if (tableName.equals(resultSet.getString("TABLE_NAME"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException exc) {
|
||||
throw new DatabaseException("Unable to look up table " + tableName
|
||||
+ " in schema " + schemaName + " : " + exc.getMessage(),
|
||||
|
@ -455,19 +465,14 @@ public class DatabaseImpl implements Database {
|
|||
return;
|
||||
}
|
||||
params.forEach((k, v) -> {
|
||||
if (v instanceof String) {
|
||||
sql.argString(k, (String) v);
|
||||
} else if (v instanceof Integer) {
|
||||
sql.argInteger(k, (Integer) v);
|
||||
} else if (v instanceof Long) {
|
||||
sql.argLong(k, (Long) v);
|
||||
} else if (v instanceof Boolean) {
|
||||
sql.argBoolean(k, (Boolean) v);
|
||||
} else if (v instanceof LocalDate) {
|
||||
sql.argLocalDate(k, (LocalDate) v);
|
||||
} else if (v instanceof LocalDateTime) {
|
||||
sql.argLocalDateTime(k, (LocalDateTime) v);
|
||||
} else {
|
||||
switch (v) {
|
||||
case String s -> sql.argString(k, s);
|
||||
case Integer i -> sql.argInteger(k, i);
|
||||
case Long l -> sql.argLong(k, l);
|
||||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case null, default ->
|
||||
throw new DatabaseException("unknown type for param: " + (v != null ? v.getClass() : "null"));
|
||||
}
|
||||
});
|
||||
|
@ -478,22 +483,15 @@ public class DatabaseImpl implements Database {
|
|||
return;
|
||||
}
|
||||
params.forEach((k, v) -> {
|
||||
if (v instanceof String) {
|
||||
sql.argString(k, (String) v);
|
||||
} else if (v instanceof Integer) {
|
||||
sql.argInteger(k, (Integer) v);
|
||||
} else if (v instanceof Long) {
|
||||
sql.argLong(k, (Long) v);
|
||||
} else if (v instanceof Boolean) {
|
||||
sql.argBoolean(k, (Boolean) v);
|
||||
} else if (v instanceof LocalDate) {
|
||||
sql.argLocalDate(k, (LocalDate) v);
|
||||
} else if (v instanceof LocalDateTime) {
|
||||
sql.argLocalDateTime(k, (LocalDateTime) v);
|
||||
} else if (v == null) {
|
||||
sql.argNull(k);
|
||||
} else {
|
||||
throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
switch (v) {
|
||||
case String s -> sql.argString(k, s);
|
||||
case Integer i -> sql.argInteger(k, i);
|
||||
case Long l -> sql.argLong(k, l);
|
||||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case null -> sql.argNull(k);
|
||||
default -> throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -503,22 +501,15 @@ public class DatabaseImpl implements Database {
|
|||
return;
|
||||
}
|
||||
params.forEach((k, v) -> {
|
||||
if (v instanceof String) {
|
||||
sql.argString(k, (String) v);
|
||||
} else if (v instanceof Integer) {
|
||||
sql.argInteger(k, (Integer) v);
|
||||
} else if (v instanceof Long) {
|
||||
sql.argLong(k, (Long) v);
|
||||
} else if (v instanceof Boolean) {
|
||||
sql.argBoolean(k, (Boolean) v);
|
||||
} else if (v instanceof LocalDate) {
|
||||
sql.argLocalDate(k, (LocalDate) v);
|
||||
} else if (v instanceof LocalDateTime) {
|
||||
sql.argLocalDateTime(k, (LocalDateTime) v);
|
||||
} else if (v == null) {
|
||||
sql.argNull(k);
|
||||
} else {
|
||||
throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
switch (v) {
|
||||
case String s -> sql.argString(k, s);
|
||||
case Integer i -> sql.argInteger(k, i);
|
||||
case Long l -> sql.argLong(k, l);
|
||||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case null -> sql.argNull(k);
|
||||
default -> throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue