mirror of
https://github.com/ethauvin/rife2.git
synced 2025-05-01 11:08:11 -07:00
Added and tested Oracle support
This commit is contained in:
parent
b941429fa7
commit
d95660d754
20 changed files with 4390 additions and 31 deletions
|
@ -34,6 +34,7 @@ dependencies {
|
|||
testImplementation("com.h2database:h2:2.1.214")
|
||||
testImplementation("org.apache.derby:derby:10.16.1.1")
|
||||
testImplementation("org.apache.derby:derbytools:10.16.1.1")
|
||||
testImplementation("com.oracle.database.jdbc:ojdbc11:21.7.0.0")
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
|
|
|
@ -82,7 +82,7 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
} else if (0 == fields_.size()) {
|
||||
throw new FieldsRequiredException("Insert");
|
||||
} else {
|
||||
Template template = TemplateFactory.SQL.get("sql." + StringUtils.encodeClassname(datasource_.getAliasedDriver()) + ".insert");
|
||||
var template = TemplateFactory.SQL.get("sql." + StringUtils.encodeClassname(datasource_.getAliasedDriver()) + ".insert");
|
||||
|
||||
if (hint_ != null) {
|
||||
if (!template.hasValueId("HINT")) {
|
||||
|
@ -95,21 +95,21 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
template.setValue("INTO", into_);
|
||||
|
||||
// obtain the maximum number of values that are present by counting those of each field
|
||||
int maximum_number_of_value_rows = 0;
|
||||
for (List<Object> values : fields_.values()) {
|
||||
var maximum_number_of_value_rows = 0;
|
||||
for (var values : fields_.values()) {
|
||||
if (values.size() > maximum_number_of_value_rows) {
|
||||
maximum_number_of_value_rows = values.size();
|
||||
}
|
||||
}
|
||||
|
||||
// create the different rows that will be inserted into the database
|
||||
ArrayList<String> value_rows = new ArrayList<String>();
|
||||
var value_rows = new ArrayList<String>();
|
||||
ArrayList<String> value_row = null;
|
||||
Object[] column_names = fields_.keySet().toArray();
|
||||
var column_names = fields_.keySet().toArray();
|
||||
String column_name = null;
|
||||
for (int current_value_row = 0; current_value_row < maximum_number_of_value_rows; current_value_row++) {
|
||||
for (var current_value_row = 0; current_value_row < maximum_number_of_value_rows; current_value_row++) {
|
||||
value_row = new ArrayList<String>();
|
||||
for (int i = 0; i < column_names.length; i++) {
|
||||
for (var i = 0; i < column_names.length; i++) {
|
||||
column_name = (String) column_names[i];
|
||||
if (current_value_row <= fields_.get(column_name).size() - 1) {
|
||||
value_row.add(fields_.get(column_name).get(current_value_row).toString());
|
||||
|
@ -130,7 +130,7 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
template.setValue("VALUE_ROWS", StringUtils.join(value_rows, template.getBlock("SEPARATOR")));
|
||||
}
|
||||
|
||||
String block = template.getBlock("VALUE_ROWS");
|
||||
var block = template.getBlock("VALUE_ROWS");
|
||||
if (0 == block.length()) {
|
||||
throw new UnsupportedSqlFeatureException("MULTIPLE INSERT ROWS", datasource_.getAliasedDriver());
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
public Insert field(String field, Select query) {
|
||||
if (null == query) throw new IllegalArgumentException("query can't be null.");
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
var buffer = new StringBuilder();
|
||||
buffer.append("(");
|
||||
buffer.append(query.toString());
|
||||
buffer.append(")");
|
||||
|
@ -267,7 +267,7 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
if (null == keyValues) throw new IllegalArgumentException("keyValues can't be null.");
|
||||
if (0 == keyValues.length) throw new IllegalArgumentException("keyValues can't be empty.");
|
||||
|
||||
for (int i = 0; i < keyValues.length; i += 2) {
|
||||
for (var i = 0; i < keyValues.length; i += 2) {
|
||||
if (null != keyValues[i]) {
|
||||
field(keyValues[i].toString(), keyValues[i + 1]);
|
||||
}
|
||||
|
@ -295,9 +295,9 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
throws DbQueryException {
|
||||
if (null == bean) throw new IllegalArgumentException("bean can't be null.");
|
||||
|
||||
Constrained constrained = ConstrainedUtils.makeConstrainedInstance(bean);
|
||||
Map<String, String> property_values = QueryHelper.getBeanPropertyValues(bean, includedFields, excludedFields, getDatasource());
|
||||
for (String property_name : property_values.keySet()) {
|
||||
var constrained = ConstrainedUtils.makeConstrainedInstance(bean);
|
||||
var property_values = QueryHelper.getBeanPropertyValues(bean, includedFields, excludedFields, getDatasource());
|
||||
for (var property_name : property_values.keySet()) {
|
||||
if (!ConstrainedUtils.saveConstrainedProperty(constrained, property_name, null)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -320,9 +320,9 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
|
||||
clearGenerated();
|
||||
|
||||
Constrained constrained = ConstrainedUtils.getConstrainedInstance(beanClass);
|
||||
Set<String> property_names = QueryHelper.getBeanPropertyNames(beanClass, excludedFields);
|
||||
for (String property_name : property_names) {
|
||||
var constrained = ConstrainedUtils.getConstrainedInstance(beanClass);
|
||||
var property_names = QueryHelper.getBeanPropertyNames(beanClass, excludedFields);
|
||||
for (var property_name : property_names) {
|
||||
if (!ConstrainedUtils.saveConstrainedProperty(constrained, property_name, null)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -335,14 +335,14 @@ public class Insert extends AbstractParametrizedQuery implements Cloneable {
|
|||
}
|
||||
|
||||
public Insert clone() {
|
||||
Insert new_instance = (Insert) super.clone();
|
||||
var new_instance = (Insert) super.clone();
|
||||
if (new_instance != null) {
|
||||
if (fields_ != null) {
|
||||
new_instance.fields_ = new LinkedHashMap<String, List<Object>>();
|
||||
|
||||
List<Object> values = null;
|
||||
|
||||
for (String field : fields_.keySet()) {
|
||||
for (var field : fields_.keySet()) {
|
||||
values = fields_.get(field);
|
||||
if (values != null) {
|
||||
values = new ArrayList<Object>(values);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class oracle_jdbc_driver_OracleDriver extends Common implements SqlConver
|
|||
return "'" + StringUtils.encodeSql(value.toString()) + "'";
|
||||
}
|
||||
} else if (value instanceof Character) {
|
||||
if (((Character) value).charValue() == 0) {
|
||||
if ((Character) value == 0) {
|
||||
return SqlNull.NULL.toString();
|
||||
} else {
|
||||
return "'" + StringUtils.encodeSql(value.toString()) + "'";
|
||||
|
@ -48,19 +48,15 @@ public class oracle_jdbc_driver_OracleDriver extends Common implements SqlConver
|
|||
return "TO_DATE('" + StringUtils.encodeSql(value.toString()) + "', 'HH24:MI:SS')";
|
||||
} else if (value instanceof Timestamp) {
|
||||
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
dateformat.setTimeZone(RifeConfig.tools().getDefaultTimeZone());
|
||||
return "TO_DATE('" + StringUtils.encodeSql(dateformat.format(value)) + "', 'YYYY/MM/DD HH24:MI:SS')";
|
||||
} else if (value instanceof java.sql.Date) {
|
||||
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd 00:00:00");
|
||||
dateformat.setTimeZone(RifeConfig.tools().getDefaultTimeZone());
|
||||
return "TO_DATE('" + StringUtils.encodeSql(dateformat.format(value)) + "', 'YYYY/MM/DD HH24:MI:SS')";
|
||||
} else if (value instanceof Date) {
|
||||
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
dateformat.setTimeZone(RifeConfig.tools().getDefaultTimeZone());
|
||||
return "TO_DATE('" + StringUtils.encodeSql(dateformat.format(new Timestamp(((Date) value).getTime()))) + "', 'YYYY/MM/DD HH24:MI:SS')";
|
||||
} else if (value instanceof Calendar) {
|
||||
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
dateformat.setTimeZone(RifeConfig.tools().getDefaultTimeZone());
|
||||
return "TO_DATE('" + StringUtils.encodeSql(dateformat.format(new Timestamp(((Calendar) value).getTime().getTime()))) + "', 'YYYY/MM/DD HH24:MI:SS')";
|
||||
}
|
||||
// make sure that the Boolean type is correctly caught
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{{b QUERY}}DELETE{{v HINT}}{{/v}} FROM {{v TABLE/}}{{v WHERE}}{{/v}}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} }}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} */{{/b}}
|
||||
{{b WHERE}} WHERE {{v CONDITION/}}{{/b}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{b QUERY}}INSERT{{v HINT}}{{/v}} INTO {{v INTO/}} ({{v COLUMNS/}}) VALUES {{v DATA/}}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} }}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} */{{/b}}
|
||||
{{b SEPARATOR}}, {{/b}}
|
||||
{{b VALUE_ROWS}}{{/b}}
|
||||
{{b VALUE_ROW}}({{v VALUES/}}){{/b}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{b QUERY}}SELECT{{v HINT}}{{/v}}{{v DISTINCT}}{{/v}} {{v FIELDS/}}{{v FROM}}{{/v}}{{v JOINS}}{{/v}}{{v WHERE}}{{/v}}{{v GROUPBY}}{{/v}}{{v HAVING}}{{/v}}{{v UNION}}{{/v}}{{v ORDERBY}}{{/v}}{{v LIMIT}}{{/v}}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} }}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} */{{/b}}
|
||||
{{b SEPARATOR}}, {{/b}}
|
||||
{{b FROM}} FROM {{v TABLE/}}{{/b}}
|
||||
{{b DISTINCT}} DISTINCT{{/b}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{b QUERY}}UPDATE{{v HINT}}{{/v}} {{v TABLE/}} SET {{v SET}}{{/v}}{{v WHERE}}{{/v}}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} }}{{/b}}
|
||||
{{b HINT}} /*+ {{v EXPRESSION/}} */{{/b}}
|
||||
{{b SEPARATOR}}, {{/b}}
|
||||
{{b SET}}{{v NAME/}} = {{v V/}}{{/b}}
|
||||
{{b WHERE}} WHERE {{v CONDITION/}}{{/b}}
|
||||
|
|
|
@ -14,8 +14,12 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
|
|||
|
||||
public class TestDatasources implements ArgumentsProvider {
|
||||
public static Datasource PGSQL = new Datasource("org.postgresql.Driver", "jdbc:postgresql://localhost:5432/unittests", "unittests", "password", 5);
|
||||
// TODO : oracle database
|
||||
public static Datasource ORACLE = null;
|
||||
// Oracle can be started up on macOS with:
|
||||
// docker run --name oracle-xe-slim -p 1521:1521 -e ORACLE_RANDOM_PASSWORD=true -e APP_USER=unittests -e APP_USER_PASSWORD=password gvenzl/oracle-xe:18-slim
|
||||
// on Apple Silicon, first install colima (https://github.com/abiosoft/colima#installation) and run it with:
|
||||
// colima start --arch x86_64 --memory 4
|
||||
// see blog post about this: https://blog.jdriven.com/2022/07/running-oracle-xe-on-apple-silicon/
|
||||
public static Datasource ORACLE = new Datasource("oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@localhost:1521/XEPDB1", "unittests", "password", 5);
|
||||
public static Datasource HSQLDB = new Datasource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:.", "sa", "", 5);
|
||||
public static Datasource H2 = new Datasource("org.h2.Driver", "jdbc:h2:./embedded_dbs/h2/unittests", "sa", "", 5);
|
||||
public static Datasource MYSQL = new Datasource("com.mysql.cj.jdbc.Driver", "jdbc:mysql://localhost:3306/unittests", "unittests", "password", 5);
|
||||
|
@ -25,6 +29,7 @@ public class TestDatasources implements ArgumentsProvider {
|
|||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||
return Stream.of(
|
||||
arguments(TestDatasources.PGSQL),
|
||||
arguments(TestDatasources.ORACLE),
|
||||
arguments(TestDatasources.DERBY),
|
||||
arguments(TestDatasources.MYSQL),
|
||||
arguments(TestDatasources.HSQLDB),
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.exceptions.SequenceNameRequiredException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateSequenceOracle extends TestCreateSequence {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
CreateSequence query = new CreateSequence(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateSequence");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
CreateSequence query = new CreateSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateSequence");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOracle() {
|
||||
CreateSequence query = new CreateSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
assertEquals(query.getSql(), "CREATE SEQUENCE sequencename");
|
||||
execute(ORACLE, query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
CreateSequence query = new CreateSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
CreateSequence query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
execute(ORACLE, query_clone);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,615 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.BeanImpl;
|
||||
import rife.database.BeanImplConstrained;
|
||||
import rife.database.exceptions.ColumnsRequiredException;
|
||||
import rife.database.exceptions.TableNameRequiredException;
|
||||
import rife.database.exceptions.UnsupportedSqlFeatureException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Blob;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateTableOracle extends TestCreateTable {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateTable");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteQueryOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateTable");
|
||||
}
|
||||
query.table("tablename");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (ColumnsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateTable");
|
||||
}
|
||||
query.table("tablename")
|
||||
.column("string", String.class);
|
||||
assertNotNull(query.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("string", String.class);
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "CreateTable");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename1")
|
||||
.column("string", String.class)
|
||||
.column("stringbuffer", StringBuffer.class)
|
||||
.column("characterobject", Character.class)
|
||||
.column("booleanobject", Boolean.class)
|
||||
.column("byteobject", Byte.class)
|
||||
.column("doubleobject", Double.class)
|
||||
.column("floatobject", Float.class)
|
||||
.column("integerobject", Integer.class)
|
||||
.column("longobject", Long.class)
|
||||
.column("shortobject", Short.class)
|
||||
.column("bigdecimal", BigDecimal.class)
|
||||
.column("charcolumn", char.class)
|
||||
.column("booleancolumn", boolean.class)
|
||||
.column("bytecolumn", byte.class)
|
||||
.column("doublecolumn", double.class)
|
||||
.column("floatcolumn", float.class)
|
||||
.column("intcolumn", int.class)
|
||||
.column("longcolumn", long.class)
|
||||
.column("shortcolumn", short.class)
|
||||
.column("blobcolumn", Blob.class);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename1 (string VARCHAR2(4000), stringbuffer VARCHAR2(4000), characterobject CHAR, booleanobject NUMBER(1), byteobject NUMBER(3), doubleobject FLOAT, floatobject FLOAT, integerobject NUMBER(10), longobject NUMBER(19), shortobject NUMBER(5), bigdecimal NUMERIC, charcolumn CHAR, booleancolumn NUMBER(1), bytecolumn NUMBER(3), doublecolumn FLOAT, floatcolumn FLOAT, intcolumn NUMBER(10), longcolumn NUMBER(19), shortcolumn NUMBER(5), blobcolumn BLOB)");
|
||||
// this is invalid to execute with Oracle
|
||||
// VARCHAR2 and CHAR need size specification
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnPrecisionOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename1")
|
||||
.column("string", String.class, 255)
|
||||
.column("stringbuffer", StringBuffer.class, 100)
|
||||
.column("characterobject", Character.class, 20)
|
||||
.column("booleanobject", Boolean.class, 7)
|
||||
.column("byteobject", Byte.class, 9)
|
||||
.column("doubleobject", Double.class, 30, 2)
|
||||
.column("floatobject", Float.class, 20, 2)
|
||||
.column("integerobject", Integer.class, 10)
|
||||
.column("longobject", Long.class, 8)
|
||||
.column("shortobject", Short.class, 8)
|
||||
.column("bigdecimal", BigDecimal.class, 19, 9)
|
||||
.column("charcolumn", char.class, 10)
|
||||
.column("booleancolumn", boolean.class, 4)
|
||||
.column("bytecolumn", byte.class, 8)
|
||||
.column("doublecolumn", double.class, 12, 3)
|
||||
.column("floatcolumn", float.class, 13, 2)
|
||||
.column("intcolumn", int.class, 10)
|
||||
.column("longcolumn", long.class, 12)
|
||||
.column("shortcolumn", short.class, 9)
|
||||
.column("blobcolumn", Blob.class, 20);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename1 (string VARCHAR2(255), stringbuffer VARCHAR2(100), characterobject CHAR(20), booleanobject NUMBER(1), byteobject NUMBER(3), doubleobject FLOAT, floatobject FLOAT, integerobject NUMBER(10), longobject NUMBER(19), shortobject NUMBER(5), bigdecimal NUMERIC(19,9), charcolumn CHAR(10), booleancolumn NUMBER(1), bytecolumn NUMBER(3), doublecolumn FLOAT, floatcolumn FLOAT, intcolumn NUMBER(10), longcolumn NUMBER(19), shortcolumn NUMBER(5), blobcolumn BLOB)");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columns(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBigDecimal NUMERIC, propertyBoolean NUMBER(1), propertyBooleanObject NUMBER(1), propertyByte NUMBER(3), propertyByteObject NUMBER(3), propertyCalendar DATE, propertyChar CHAR, propertyCharacterObject CHAR, propertyDate DATE, propertyDouble FLOAT, propertyDoubleObject FLOAT, propertyEnum VARCHAR(255), propertyFloat FLOAT, propertyFloatObject FLOAT, propertyInt NUMBER(10), propertyIntegerObject NUMBER(10), propertyLong NUMBER(19), propertyLongObject NUMBER(19), propertyShort NUMBER(5), propertyShortObject NUMBER(5), propertySqlDate DATE, propertyString VARCHAR2(4000), propertyStringbuffer VARCHAR2(4000), propertyTime DATE, propertyTimestamp DATE, CHECK (propertyEnum IS NULL OR propertyEnum IN ('VALUE_ONE','VALUE_TWO','VALUE_THREE')))");
|
||||
// this is invalid to execute with Oracle
|
||||
// VARCHAR2 and CHAR need size specification
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanIncludedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columnsIncluded(BeanImpl.class, new String[]{"propertyBigDecimal", "propertyByte", "propertyFloat", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBigDecimal NUMERIC, propertyByte NUMBER(3), propertyFloat FLOAT, propertyStringbuffer VARCHAR2(4000), propertyTime DATE)");
|
||||
// this is invalid to execute with Oracle
|
||||
// VARCHAR2 and CHAR need size specification
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanExcludedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columnsExcluded(BeanImpl.class, new String[]{"propertyBigDecimal", "propertyByte", "propertyFloat", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBoolean NUMBER(1), propertyBooleanObject NUMBER(1), propertyByteObject NUMBER(3), propertyCalendar DATE, propertyChar CHAR, propertyCharacterObject CHAR, propertyDate DATE, propertyDouble FLOAT, propertyDoubleObject FLOAT, propertyEnum VARCHAR(255), propertyFloatObject FLOAT, propertyInt NUMBER(10), propertyIntegerObject NUMBER(10), propertyLong NUMBER(19), propertyLongObject NUMBER(19), propertyShort NUMBER(5), propertyShortObject NUMBER(5), propertySqlDate DATE, propertyString VARCHAR2(4000), propertyTimestamp DATE, CHECK (propertyEnum IS NULL OR propertyEnum IN ('VALUE_ONE','VALUE_TWO','VALUE_THREE')))");
|
||||
// this is invalid to execute with Oracle
|
||||
// VARCHAR2 and CHAR need size specification
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanFilteredOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columnsFiltered(BeanImpl.class, new String[]{"propertyBigDecimal", "propertyByte", "propertyFloat", "propertyStringbuffer", "propertyTime"}, new String[]{"propertyByte", "propertyStringbuffer"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBigDecimal NUMERIC, propertyFloat FLOAT, propertyTime DATE)");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanPrecisionOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columns(BeanImpl.class)
|
||||
.precision("propertyBigDecimal", 19, 9)
|
||||
.precision("propertyBoolean", 4)
|
||||
.precision("propertyBooleanObject", 7)
|
||||
.precision("propertyByte", 8)
|
||||
.precision("propertyByteObject", 9)
|
||||
.precision("propertyCalendar", 20)
|
||||
.precision("propertyChar", 10)
|
||||
.precision("propertyCharacterObject", 12)
|
||||
.precision("propertyDate", 7)
|
||||
.precision("propertyDouble", 12, 3)
|
||||
.precision("propertyDoubleObject", 14, 4)
|
||||
.precision("propertyFloat", 13, 2)
|
||||
.precision("propertyFloatObject", 12, 1)
|
||||
.precision("propertyInt", 10)
|
||||
.precision("propertyIntegerObject", 8)
|
||||
.precision("propertyLong", 12)
|
||||
.precision("propertyLongObject", 11)
|
||||
.precision("propertyShort", 9)
|
||||
.precision("propertyShortObject", 6)
|
||||
.precision("propertySqlDate", 8)
|
||||
.precision("propertyString", 255)
|
||||
.precision("propertyStringbuffer", 100)
|
||||
.precision("propertyTime", 9)
|
||||
.precision("propertyTimestamp", 30, 2)
|
||||
.precision("propertyEnum", 14);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBigDecimal NUMERIC(19,9), propertyBoolean NUMBER(1), propertyBooleanObject NUMBER(1), propertyByte NUMBER(3), propertyByteObject NUMBER(3), propertyCalendar DATE, propertyChar CHAR(10), propertyCharacterObject CHAR(12), propertyDate DATE, propertyDouble FLOAT, propertyDoubleObject FLOAT, propertyEnum VARCHAR(255), propertyFloat FLOAT, propertyFloatObject FLOAT, propertyInt NUMBER(10), propertyIntegerObject NUMBER(10), propertyLong NUMBER(19), propertyLongObject NUMBER(19), propertyShort NUMBER(5), propertyShortObject NUMBER(5), propertySqlDate DATE, propertyString VARCHAR2(255), propertyStringbuffer VARCHAR2(100), propertyTime DATE, propertyTimestamp DATE, CHECK (propertyEnum IS NULL OR propertyEnum IN ('VALUE_ONE','VALUE_TWO','VALUE_THREE')))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnsBeanConstrainedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columns(BeanImplConstrained.class);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (propertyBigDecimal NUMERIC(17,6), propertyBoolean NUMBER(1), propertyBooleanObject NUMBER(1), propertyByte NUMBER(3), propertyByteObject NUMBER(3) NOT NULL, propertyCalendar DATE, propertyChar CHAR, propertyCharacterObject CHAR, propertyDate DATE, propertyDouble FLOAT, propertyDoubleObject FLOAT, propertyFloat FLOAT, propertyFloatObject FLOAT, propertyInt NUMBER(10) DEFAULT 23, propertyIntegerObject NUMBER(10), propertyLongObject NUMBER(19), propertyShort NUMBER(5), propertySqlDate DATE, propertyString VARCHAR2(30) DEFAULT 'one' NOT NULL, propertyStringbuffer VARCHAR2(20) NOT NULL, propertyTime DATE, propertyTimestamp DATE, PRIMARY KEY (propertyString), UNIQUE (propertyStringbuffer, propertyByteObject), UNIQUE (propertyStringbuffer), CHECK (propertyByteObject != -1), CHECK (propertyInt != 0), CHECK (propertyLongObject IS NULL OR propertyLongObject IN (89,1221,66875,878)), CHECK (propertyString IS NULL OR propertyString IN ('one','tw''''o','someotherstring')), CHECK (propertyStringbuffer != ''), CHECK (propertyStringbuffer != 'some''blurp'))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullableOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn1", int.class, CreateTable.NULL)
|
||||
.column("stringColumn", String.class, 12, CreateTable.NOTNULL)
|
||||
.column("intColumn2", int.class)
|
||||
.column("intColumn3", int.class)
|
||||
.column("floatColumn", float.class, 13, 6, CreateTable.NOTNULL)
|
||||
.nullable("intColumn2", CreateTable.NULL)
|
||||
.nullable("intColumn3", CreateTable.NOTNULL)
|
||||
.nullable("floatColumn", null);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn1 NUMBER(10) NULL, stringColumn VARCHAR2(12) NOT NULL, intColumn2 NUMBER(10) NULL, intColumn3 NUMBER(10) NOT NULL, floatColumn FLOAT)");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename1")
|
||||
.column("string", String.class, 255)
|
||||
.column("stringbuffer", StringBuffer.class, 100)
|
||||
.column("characterobject", Character.class, 22)
|
||||
.column("booleanobject", Boolean.class, 7)
|
||||
.column("byteobject", Byte.class, 9)
|
||||
.column("doubleobject", Double.class, 30, 2)
|
||||
.column("floatobject", Float.class, 20, 2)
|
||||
.column("integerobject", Integer.class, 10)
|
||||
.column("longobject", Long.class, 8)
|
||||
.column("shortobject", Short.class, 8)
|
||||
.column("bigdecimal", BigDecimal.class, 19, 9)
|
||||
.column("charcolumn", char.class, 10)
|
||||
.column("booleancolumn", boolean.class, 4)
|
||||
.column("bytecolumn", byte.class, 8)
|
||||
.column("doublecolumn", double.class, 12, 3)
|
||||
.column("floatcolumn", float.class, 13, 2)
|
||||
.column("intcolumn", int.class, 10)
|
||||
.column("longcolumn", long.class, 12)
|
||||
.column("shortcolumn", short.class, 9)
|
||||
.defaultValue("string", "stringDefault")
|
||||
.defaultValue("stringbuffer", "stringbufferDefault")
|
||||
.defaultValue("characterobject", "characterobjectDefault")
|
||||
.defaultValue("booleanobject", true)
|
||||
.defaultValue("byteobject", (byte) 34)
|
||||
.defaultValue("doubleobject", 234.87d)
|
||||
.defaultValue("floatobject", 834.43f)
|
||||
.defaultValue("integerobject", 463)
|
||||
.defaultValue("longobject", 34876L)
|
||||
.defaultValue("shortobject", (short) 98)
|
||||
.defaultValue("bigdecimal", new BigDecimal("347.14"))
|
||||
.defaultValue("charcolumn", "OSJFDZ")
|
||||
.defaultValue("booleancolumn", false)
|
||||
.defaultValue("bytecolumn", (byte) 27)
|
||||
.defaultValue("doublecolumn", 934.5d)
|
||||
.defaultValue("floatcolumn", 35.87f)
|
||||
.defaultValue("intcolumn", 983734)
|
||||
.defaultValue("longcolumn", 2343345L)
|
||||
.defaultValue("shortcolumn", 12);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename1 (string VARCHAR2(255) DEFAULT 'stringDefault', stringbuffer VARCHAR2(100) DEFAULT 'stringbufferDefault', characterobject CHAR(22) DEFAULT 'characterobjectDefault', booleanobject NUMBER(1) DEFAULT 1, byteobject NUMBER(3) DEFAULT 34, doubleobject FLOAT DEFAULT 234.87, floatobject FLOAT DEFAULT 834.43, integerobject NUMBER(10) DEFAULT 463, longobject NUMBER(19) DEFAULT 34876, shortobject NUMBER(5) DEFAULT 98, bigdecimal NUMERIC(19,9) DEFAULT 347.14, charcolumn CHAR(10) DEFAULT 'OSJFDZ', booleancolumn NUMBER(1) DEFAULT 0, bytecolumn NUMBER(3) DEFAULT 27, doublecolumn FLOAT DEFAULT 934.5, floatcolumn FLOAT DEFAULT 35.87, intcolumn NUMBER(10) DEFAULT 983734, longcolumn NUMBER(19) DEFAULT 2343345, shortcolumn NUMBER(5) DEFAULT 12)");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFunctionOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename1")
|
||||
.column("intcolumn", int.class)
|
||||
.defaultFunction("intcolumn", "6+1");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename1 (intcolumn NUMBER(10) DEFAULT 6+1)");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAttributeOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename1")
|
||||
.column("intColumn", Integer.class)
|
||||
.customAttribute("intColumn", "CHECK (intColumn > 0)");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename1 (intColumn NUMBER(10) CHECK (intColumn > 0))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporaryOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.temporary(true)
|
||||
.column("boolColumn", boolean.class);
|
||||
assertEquals(query.getSql(), "CREATE GLOBAL TEMPORARY TABLE tablename (boolColumn NUMBER(1))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimaryKeySimpleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.primaryKey("intColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10) NOT NULL, PRIMARY KEY (intColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimaryKeyMultipleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.primaryKey(new String[]{"intColumn", "stringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10) NOT NULL, stringColumn VARCHAR2(50) NOT NULL, PRIMARY KEY (intColumn, stringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimaryKeyNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.primaryKey("constraint_name", "intColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10) NOT NULL, CONSTRAINT constraint_name PRIMARY KEY (intColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimaryKeyMultipleNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.primaryKey("constraint_name", new String[]{"intColumn", "stringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10) NOT NULL, stringColumn VARCHAR2(50) NOT NULL, CONSTRAINT constraint_name PRIMARY KEY (intColumn, stringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueSimpleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.unique("intColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), UNIQUE (intColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueMultipleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.unique(new String[]{"intColumn", "stringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), stringColumn VARCHAR2(50), UNIQUE (intColumn, stringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.unique("constraint_name", "intColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), CONSTRAINT constraint_name UNIQUE (intColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueMultipleNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.unique("constraint_name", new String[]{"intColumn", "stringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), stringColumn VARCHAR2(50), CONSTRAINT constraint_name UNIQUE (intColumn, stringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeySimpleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), FOREIGN KEY (intColumn) REFERENCES foreigntable (foreignIntColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeyMultipleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.foreignKey("foreigntable", new String[]{"intColumn", "foreignIntColumn", "stringColumn", "foreignStringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), stringColumn VARCHAR2(50), FOREIGN KEY (intColumn, stringColumn) REFERENCES foreigntable (foreignIntColumn, foreignStringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeySimpleNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("constraint_name", "foreigntable", "intColumn", "foreignIntColumn");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), CONSTRAINT constraint_name FOREIGN KEY (intColumn) REFERENCES foreigntable (foreignIntColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeyMultipleNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.foreignKey("constraint_name", "foreigntable", new String[]{"intColumn", "foreignIntColumn", "stringColumn", "foreignStringColumn"});
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), stringColumn VARCHAR2(50), CONSTRAINT constraint_name FOREIGN KEY (intColumn, stringColumn) REFERENCES foreigntable (foreignIntColumn, foreignStringColumn))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeyViolationsSingleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.CASCADE, null);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.NOACTION, null);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.RESTRICT, null);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.SETDEFAULT, null);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.SETNULL, null);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", null, CreateTable.CASCADE);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), FOREIGN KEY (intColumn) REFERENCES foreigntable (foreignIntColumn) ON DELETE CASCADE)");
|
||||
execute(query);
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", null, CreateTable.NOACTION);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", null, CreateTable.RESTRICT);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", null, CreateTable.SETDEFAULT);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.clear();
|
||||
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", null, CreateTable.SETNULL);
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), FOREIGN KEY (intColumn) REFERENCES foreigntable (foreignIntColumn) ON DELETE SET NULL)");
|
||||
execute(query);
|
||||
query.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeyViolationsOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.foreignKey("foreigntable", "intColumn", "foreignIntColumn", CreateTable.CASCADE, CreateTable.NOACTION);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForeignKeyMultipleViolationsOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.column("stringColumn", String.class, 50)
|
||||
.foreignKey("foreigntable", new String[]{"intColumn", "foreignIntColumn", "stringColumn", "foreignStringColumn"}, CreateTable.RESTRICT, CreateTable.CASCADE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckSimpleOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.check("intColumn > 0");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), CHECK (intColumn > 0))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckNamedOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.column("intColumn", int.class)
|
||||
.check("NAME_CK", "intColumn > 0");
|
||||
assertEquals(query.getSql(), "CREATE TABLE tablename (intColumn NUMBER(10), CONSTRAINT NAME_CK CHECK (intColumn > 0))");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
CreateTable query = new CreateTable(ORACLE);
|
||||
query.table("tablename")
|
||||
.columns(BeanImpl.class)
|
||||
.precision("propertyBigDecimal", 19, 9)
|
||||
.precision("propertyBoolean", 4)
|
||||
.precision("propertyByte", 8)
|
||||
.precision("propertyCalendar", 20)
|
||||
.precision("propertyChar", 10)
|
||||
.precision("propertyDate", 7)
|
||||
.precision("propertyDouble", 12, 3)
|
||||
.precision("propertyFloat", 13, 2)
|
||||
.precision("propertyInt", 10)
|
||||
.precision("propertyLong", 12)
|
||||
.precision("propertyShort", 9)
|
||||
.precision("propertySqlDate", 8)
|
||||
.precision("propertyString", 255)
|
||||
.precision("propertyStringbuffer", 100)
|
||||
.precision("propertyTime", 9)
|
||||
.precision("propertyTimestamp", 30, 2)
|
||||
.nullable("propertyString", CreateTable.NULL)
|
||||
.nullable("propertyInt", CreateTable.NOTNULL)
|
||||
.defaultValue("propertyStringbuffer", "stringDefault")
|
||||
.defaultFunction("propertyLong", "6+1")
|
||||
.customAttribute("propertyInt", "CHECK (propertyInt > 0)")
|
||||
.primaryKey("constraint_name1", new String[]{"propertyInt", "propertyString"})
|
||||
.unique("constraint_name2", new String[]{"propertyLong", "propertyString"})
|
||||
.foreignKey("foreigntable", new String[]{"propertyInt", "foreignIntColumn", "propertyString", "foreignStringColumn"}, null, CreateTable.CASCADE)
|
||||
.check("NAME_CK", "propertyInt > 0");
|
||||
CreateTable query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
execute(query_clone);
|
||||
}
|
||||
}
|
601
lib/src/test/java/rife/database/queries/TestDeleteOracle.java
Normal file
601
lib/src/test/java/rife/database/queries/TestDeleteOracle.java
Normal file
|
@ -0,0 +1,601 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.BeanImpl;
|
||||
import rife.database.BeanImplConstrained;
|
||||
import rife.database.DbPreparedStatement;
|
||||
import rife.database.DbPreparedStatementHandler;
|
||||
import rife.database.exceptions.TableNameRequiredException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestDeleteOracle extends TestDelete {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Delete");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteQueryOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Delete");
|
||||
}
|
||||
query.where("this = that");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Delete");
|
||||
}
|
||||
query.from("tablename");
|
||||
assertNotNull(query.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("this = that");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Delete");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename");
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHintOracle() {
|
||||
Delete query = new Delete(ORACLE)
|
||||
.hint("NO_INDEX")
|
||||
.from("tablename")
|
||||
.where("propertyByte", "=", 89);
|
||||
assertEquals(query.getSql(), "DELETE /*+ NO_INDEX */ FROM tablename WHERE propertyByte = 89");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyByte = 89");
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyByte = 89");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereTypedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2003, Calendar.MARCH, 3, 10, 1, 28);
|
||||
cal.set(Calendar.MILLISECOND, 154);
|
||||
|
||||
query
|
||||
.where("propertyBigDecimal", ">=", new BigDecimal("53443433.9784567"))
|
||||
.whereAnd("propertyBoolean", "=", false)
|
||||
.whereOr("propertyByte", "=", (byte) 54)
|
||||
.whereAnd("propertyCalendar", "<=", cal)
|
||||
.whereOr("propertyChar", "=", 'f')
|
||||
.whereAnd("propertyDate", "=", cal.getTime())
|
||||
.whereAnd("propertyDouble", "!=", 73453.71d)
|
||||
.whereOr("propertyFloat", ">=", 1987.14f)
|
||||
.whereAnd("propertyInt", "=", 973)
|
||||
.whereAnd("propertyLong", "<", 347678L)
|
||||
.whereAnd("propertyShort", "=", (short) 78)
|
||||
.whereOr("propertySqlDate", "=", new java.sql.Date(cal.getTime().getTime()))
|
||||
.whereAnd("propertyString", "LIKE", "someotherstring%")
|
||||
.whereAnd("propertyStringbuffer", "=", new StringBuffer("someotherstringbuff"))
|
||||
.whereOr("propertyTime", "=", new Time(cal.getTime().getTime()))
|
||||
.whereAnd("propertyTimestamp", "<=", new Timestamp(cal.getTime().getTime()));
|
||||
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = TO_DATE('2003/03/03 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertFalse(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereTypedMixedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(2003, Calendar.MARCH, 3, 10, 1, 28);
|
||||
cal.set(Calendar.MILLISECOND, 154);
|
||||
|
||||
query
|
||||
.where("propertyBigDecimal", ">=", new BigDecimal("53443433.9784567"))
|
||||
.whereAnd("propertyBoolean", "=", false)
|
||||
.whereOr("propertyByte = 54")
|
||||
.whereAnd("propertyCalendar", "<=", cal)
|
||||
.whereOr("propertyChar", "=", 'f')
|
||||
.whereAnd("propertyDate", "=", cal.getTime())
|
||||
.whereAnd("propertyDouble", "!=", 73453.71d)
|
||||
.whereOr("propertyFloat >= 1987.14")
|
||||
.whereAnd("propertyInt", "=", 973)
|
||||
.whereAnd("propertyLong", "<", 347678L)
|
||||
.whereAnd("propertyShort", "=", (short) 78)
|
||||
.whereParameterOr("propertySqlDate", "=")
|
||||
.whereAnd("propertyString", "LIKE", "someotherstring%")
|
||||
.whereAnd("propertyStringbuffer", "=", new StringBuffer("someotherstringbuff"))
|
||||
.whereOr("propertyTime", "=", new Time(cal.getTime().getTime()))
|
||||
.whereAnd("propertyTimestamp", "<=", new Timestamp(cal.getTime().getTime()));
|
||||
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = ? AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
|
||||
assertFalse(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setDate("propertySqlDate", new java.sql.Date(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
|
||||
query.whereParameter("propertyInt", "=")
|
||||
.whereParameterAnd("propertyLong", "<")
|
||||
.whereParameterOr("propertyChar", "=");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 3);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyChar");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyInt", "propertyLong", "propertyChar"});
|
||||
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setInt(1, 545)
|
||||
.setLong(2, 50000)
|
||||
.setString(3, "v");
|
||||
}
|
||||
}));
|
||||
|
||||
query.where("propertyInt = 545");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = 545");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersMixedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyInt = 545")
|
||||
.whereParameterAnd("propertyLong", "<")
|
||||
.whereParameterOr("propertyChar", "=");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyChar");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyLong", "propertyChar"});
|
||||
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = 545 AND propertyLong < ? OR propertyChar = ?");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setLong(1, 50000)
|
||||
.setString(2, "v");
|
||||
}
|
||||
}));
|
||||
|
||||
query.where("propertyInt = 545");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = 545");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereConstructionOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyInt = 545")
|
||||
.whereAnd("propertyLong < 50000")
|
||||
.whereOr("propertyChar = 'v'");
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = 545 AND propertyLong < 50000 OR propertyChar = 'v'");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereConstructionGroupOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyInt = 545")
|
||||
.whereAnd("propertyLong < 50000")
|
||||
.startWhereOr()
|
||||
.whereParameter("propertyString", "=")
|
||||
.whereAnd("propertyByte", "<=", (byte) 0)
|
||||
.startWhereAnd()
|
||||
.where("propertyBoolean", "!=", true)
|
||||
.whereParameterOr("propertyStringbuffer", "LIKE")
|
||||
.end()
|
||||
.end()
|
||||
.whereOr("propertyChar = 'v'");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyStringbuffer");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyString", "propertyStringbuffer"});
|
||||
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyInt = 545 AND propertyLong < 50000 OR (propertyString = ? AND propertyByte <= 0 AND (propertyBoolean != 1 OR propertyStringbuffer LIKE ?)) OR propertyChar = 'v'");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("propertyString", "someotherstring")
|
||||
.setString("propertyStringbuffer", "stringbuff");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImpl.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertyShortObject = 68 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanConstrainedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImplConstrained.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanNullValuesOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImpl.getNullBean());
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBoolean = 0 AND propertyBooleanObject = 0 AND propertyByte = 0 AND propertyByteObject = 0 AND propertyDouble = 0.0 AND propertyDoubleObject = 0.0 AND propertyFloat = 0.0 AND propertyFloatObject = 0.0 AND propertyInt = 0 AND propertyIntegerObject = 0 AND propertyLong = 0 AND propertyLongObject = 0 AND propertyShort = 0 AND propertyShortObject = 0");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanIncludedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereIncluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyByte = 89 AND propertyDouble = 53348.34 AND propertyShort = 43 AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanExcludedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereExcluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShortObject = 68 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanFilteredOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereFiltered(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"}, new String[]{"propertyByte", "propertyShort", "propertyTime"});
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyDouble = 53348.34 AND propertyStringbuffer = 'someotherstringbuff'");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParameters(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLong = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 25);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(21), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(22), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(23), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(24), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByte", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLong", "propertyLongObject", "propertyShort", "propertyShortObject", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
// don't check if actual rows were returned, since Oracle doesn't
|
||||
// match on the date types
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, true)
|
||||
.setBoolean(3, false)
|
||||
.setByte(4, (byte) 89)
|
||||
.setByte(5, (byte) 34)
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(7, "v")
|
||||
.setString(8, "r")
|
||||
.setTimestamp(9, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(10, 53348.34d)
|
||||
.setDouble(11, 143298.692d)
|
||||
.setString(12, "VALUE_THREE")
|
||||
.setFloat(13, 98634.2f)
|
||||
.setFloat(14, 8734.7f)
|
||||
.setInt(15, 545)
|
||||
.setInt(16, 968)
|
||||
.setLong(17, 34563L)
|
||||
.setLong(18, 66875L)
|
||||
.setShort(19, (short) 43)
|
||||
.setShort(20, (short) 68)
|
||||
.setDate(21, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(22, "someotherstring")
|
||||
.setString(23, "someotherstringbuff")
|
||||
.setTime(24, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(25, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanConstrainedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParameters(BeanImplConstrained.class);
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 22);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(21), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByte", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
// don't check if actual rows were returned, since Oracle doesn't
|
||||
// match on the float
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, true)
|
||||
.setBoolean(3, false)
|
||||
.setByte(4, (byte) 89)
|
||||
.setByte(5, (byte) 34)
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(7, "v")
|
||||
.setString(8, "r")
|
||||
.setTimestamp(9, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(10, 53348.34d)
|
||||
.setDouble(11, 143298.692d)
|
||||
.setFloat(12, 98634.2f)
|
||||
.setFloat(13, 8734.7f)
|
||||
.setInt(14, 545)
|
||||
.setInt(15, 968)
|
||||
.setLong(16, 66875L)
|
||||
.setShort(17, (short) 43)
|
||||
.setDate(18, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(19, "someotherstring")
|
||||
.setString(20, "someotherstringbuff")
|
||||
.setTime(21, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(22, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanExcludedOracle() {
|
||||
Delete query = new Delete(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParametersExcluded(BeanImpl.class,
|
||||
new String[]{"propertyBoolean", "propertyByte", "propertyChar",
|
||||
"propertyDouble", "propertyInt", "propertyLong",
|
||||
"propertySqlDate", "propertyStringbuffer", "propertyTimestamp",
|
||||
"propertyCalendar", "propertyDate", "propertyTime"});
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyBigDecimal = ? AND propertyBooleanObject = ? AND propertyByteObject = ? AND propertyCharacterObject = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertyString = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 13);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyString");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBooleanObject", "propertyByteObject", "propertyCharacterObject", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertyShortObject", "propertyString"});
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, false)
|
||||
.setByte(3, (byte) 34)
|
||||
.setString(4, "r")
|
||||
.setDouble(5, 143298.692d)
|
||||
.setString(6, "VALUE_THREE")
|
||||
.setFloat(7, 98634.2f)
|
||||
.setFloat(8, 8734.7f)
|
||||
.setInt(9, 968)
|
||||
.setLong(10, 66875L)
|
||||
.setShort(11, (short) 43)
|
||||
.setShort(12, (short) 68)
|
||||
.setString(13, "someotherstring");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSubselectParamsOracle() {
|
||||
Select wherequery = new Select(ORACLE);
|
||||
wherequery
|
||||
.from("table2")
|
||||
.field("max(propertyShort)")
|
||||
.whereParameter("propertyShort", "!=");
|
||||
Delete query = new Delete(ORACLE);
|
||||
query
|
||||
.where("propertyShort >= (" + wherequery + ")")
|
||||
.whereSubselect(wherequery)
|
||||
.whereParameterOr("propertyString", "=")
|
||||
.from("tablename");
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyShort >= (SELECT max(propertyShort) FROM table2 WHERE propertyShort != ?) OR propertyString = ?");
|
||||
String[] parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(2, parameters.length);
|
||||
assertEquals(parameters[0], "propertyShort");
|
||||
assertEquals(parameters[1], "propertyString");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setShort("propertyShort", (short) 5)
|
||||
.setString("propertyString", "thestring");
|
||||
}
|
||||
}));
|
||||
|
||||
// Automated subselect creation
|
||||
query = new Delete(ORACLE);
|
||||
query
|
||||
.where("propertyShort", ">=", wherequery)
|
||||
.whereParameterOr("propertyString", "=")
|
||||
.whereOr("tablename.propertyFloat", ">", new Select(ORACLE)
|
||||
.from("table2")
|
||||
.field("max(propertyLong)")
|
||||
.whereParameter("propertyLong", "!="))
|
||||
.whereAnd("tablename.propertyDouble", "<=", new Select(ORACLE)
|
||||
.from("table2")
|
||||
.field("max(propertyFloat)")
|
||||
.whereParameter("propertyFloat", "!="))
|
||||
.from("tablename");
|
||||
assertEquals(query.getSql(), "DELETE FROM tablename WHERE propertyShort >= (SELECT max(propertyShort) FROM table2 WHERE propertyShort != ?) OR propertyString = ? OR tablename.propertyFloat > (SELECT max(propertyLong) FROM table2 WHERE propertyLong != ?) AND tablename.propertyDouble <= (SELECT max(propertyFloat) FROM table2 WHERE propertyFloat != ?)");
|
||||
parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(4, parameters.length);
|
||||
assertEquals(parameters[0], "propertyShort");
|
||||
assertEquals(parameters[1], "propertyString");
|
||||
assertEquals(parameters[2], "propertyLong");
|
||||
assertEquals(parameters[3], "propertyFloat");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setShort("propertyShort", (short) 5)
|
||||
.setString("propertyString", "thestring")
|
||||
.setLong("propertyLong", 99999999)
|
||||
.setFloat("propertyFloat", -1f);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
Select wherequery = new Select(ORACLE);
|
||||
wherequery
|
||||
.from("table2")
|
||||
.field("max(propertyShort)")
|
||||
.whereParameter("propertyShort", "!=");
|
||||
|
||||
Delete query = new Delete(ORACLE);
|
||||
query
|
||||
.hint("NO_INDEX")
|
||||
.from("tablename")
|
||||
.where("propertyShort >= (" + wherequery + ")")
|
||||
.whereSubselect(wherequery)
|
||||
.whereParameterOr("propertyString", "=")
|
||||
.whereOr("propertyByte", "=", (byte) 54)
|
||||
.whereAnd("propertyDouble", "!=", 73453.71d)
|
||||
.whereParameterOr("propertyInt", "=")
|
||||
.whereParameterAnd("propertyLong", "<")
|
||||
.whereParameterOr("propertyChar", "=");
|
||||
|
||||
Delete query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("propertyChar", "M")
|
||||
.setInt("propertyInt", 34)
|
||||
.setString("propertyString", "string'value")
|
||||
.setLong("propertyLong", 34543)
|
||||
.setShort("propertyShort", (short) 4);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.exceptions.SequenceNameRequiredException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestDropSequenceOracle extends TestDropSequence {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
DropSequence query = new DropSequence(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "DropSequence");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
DropSequence query = new DropSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "DropSequence");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOracle() {
|
||||
DropSequence query = new DropSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
assertEquals(query.getSql(), "DROP SEQUENCE sequencename");
|
||||
execute(ORACLE, query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
DropSequence query = new DropSequence(ORACLE);
|
||||
query.name("sequencename");
|
||||
DropSequence query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
execute(ORACLE, query_clone);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.exceptions.TableNameRequiredException;
|
||||
import rife.database.exceptions.UnsupportedSqlFeatureException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestDropTableOracle extends TestDropTable {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "DropTable");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteQueryOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "DropTable");
|
||||
}
|
||||
query.table("tablename");
|
||||
assertNotNull(query.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
query.table("tablename");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "DropTable");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneTableOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
query.table("tabletodrop");
|
||||
assertEquals(query.getSql(), "DROP TABLE tabletodrop");
|
||||
execute(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleTablesOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
query.table("tabletodrop1")
|
||||
.table("tabletodrop2")
|
||||
.table("tabletodrop3");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
DropTable query = new DropTable(ORACLE);
|
||||
query.table("tabletodrop");
|
||||
DropTable query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertTrue(query != query_clone);
|
||||
execute(query_clone);
|
||||
}
|
||||
}
|
677
lib/src/test/java/rife/database/queries/TestInsertOracle.java
Normal file
677
lib/src/test/java/rife/database/queries/TestInsertOracle.java
Normal file
|
@ -0,0 +1,677 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.BeanImpl;
|
||||
import rife.database.BeanImplConstrained;
|
||||
import rife.database.DbPreparedStatement;
|
||||
import rife.database.DbPreparedStatementHandler;
|
||||
import rife.database.exceptions.FieldsRequiredException;
|
||||
import rife.database.exceptions.TableNameRequiredException;
|
||||
import rife.database.exceptions.UnsupportedSqlFeatureException;
|
||||
import rife.database.types.SqlNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestInsertOracle extends TestInsert {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Insert");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteQueryOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Insert");
|
||||
}
|
||||
query.into("tablename");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (FieldsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Insert");
|
||||
}
|
||||
query.field("col1", "val1");
|
||||
assertNotNull(query.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.field("col1", "val1");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Insert");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHintOracle() {
|
||||
Insert query = new Insert(ORACLE)
|
||||
.hint("APPEND")
|
||||
.into("tablename")
|
||||
.field("propertyDouble", 12.3d);
|
||||
assertEquals(query.getSql(), "INSERT /*+ APPEND */ INTO tablename (propertyDouble) VALUES (12.3)");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldParameter("col1");
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (col1) VALUES (?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldOracle() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.field("nullColumn", SqlNull.NULL)
|
||||
.field("propertyBigDecimal", new BigDecimal("98347.876438637"))
|
||||
.field("propertyBoolean", true)
|
||||
.field("propertyByte", (byte) 16)
|
||||
.field("propertyCalendar", cal.getTime())
|
||||
.field("propertyChar", 'M')
|
||||
.field("propertyDate", cal)
|
||||
.field("propertyDouble", 12.3d)
|
||||
.field("propertyFloat", 13.4f)
|
||||
.field("propertyInt", 34)
|
||||
.field("propertyLong", 45L)
|
||||
.field("propertyShort", (short) 12)
|
||||
.field("propertySqlDate", new java.sql.Date(cal.getTime().getTime()))
|
||||
.field("propertyString", "string'value")
|
||||
.field("propertyStringbuffer", new StringBuffer("stringbuffer'value"))
|
||||
.field("propertyTime", new Time(cal.getTime().getTime()))
|
||||
.field("propertyTimestamp", new Timestamp(cal.getTime().getTime()));
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (nullColumn, propertyBigDecimal, propertyBoolean, propertyByte, propertyCalendar, propertyChar, propertyDate, propertyDouble, propertyFloat, propertyInt, propertyLong, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (NULL, 98347.876438637, 1, 16, TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), 'M', TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), 12.3, 13.4, 34, 45, 12, TO_DATE('2002/08/19 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), 'string''value', 'stringbuffer''value', TO_DATE('12:17:52', 'HH24:MI:SS'), TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldCustomOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldCustom("propertySqlDate", "(SELECT sysdate FROM dual)");
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertySqlDate) VALUES ((SELECT sysdate FROM dual))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsOracle() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fields(new Object[]{
|
||||
"nullColumn", SqlNull.NULL,
|
||||
"propertyBigDecimal", new BigDecimal("98347.876438637"),
|
||||
"propertyBoolean", true,
|
||||
"propertyByte", (byte) 16,
|
||||
"propertyCalendar", cal.getTime(),
|
||||
"propertyChar", 'M',
|
||||
"propertyDate", cal,
|
||||
"propertyDouble", 12.3d,
|
||||
"propertyFloat", 13.4f,
|
||||
"propertyInt", 34,
|
||||
"propertyLong", 45L,
|
||||
"propertyShort", (short) 12,
|
||||
"propertySqlDate", new java.sql.Date(cal.getTime().getTime()),
|
||||
"propertyString", new String("string'value"),
|
||||
"propertyStringbuffer", new StringBuffer("stringbuffer'value"),
|
||||
"propertyTime", new Time(cal.getTime().getTime()),
|
||||
"propertyTimestamp", new Timestamp(cal.getTime().getTime())
|
||||
});
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (nullColumn, propertyBigDecimal, propertyBoolean, propertyByte, propertyCalendar, propertyChar, propertyDate, propertyDouble, propertyFloat, propertyInt, propertyLong, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (NULL, 98347.876438637, 1, 16, TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), 'M', TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), 12.3, 13.4, 34, 45, 12, TO_DATE('2002/08/19 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), 'string''value', 'stringbuffer''value', TO_DATE('12:17:52', 'HH24:MI:SS'), TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldParametersOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
|
||||
query.fieldParameter("nullColumn")
|
||||
.fieldParameter("propertyBigDecimal")
|
||||
.fieldParameter("propertyBoolean")
|
||||
.fieldParameter("propertyByte")
|
||||
.fieldParameter("propertyCalendar")
|
||||
.fieldParameter("propertyChar")
|
||||
.fieldParameter("propertyDate")
|
||||
.fieldParameter("propertyDouble")
|
||||
.fieldParameter("propertyFloat")
|
||||
.fieldParameter("propertyInt")
|
||||
.fieldParameter("propertyLong")
|
||||
.fieldParameter("propertyShort")
|
||||
.fieldParameter("propertySqlDate")
|
||||
.fieldParameter("propertyString")
|
||||
.fieldParameter("propertyStringbuffer")
|
||||
.fieldParameter("propertyTime")
|
||||
.fieldParameter("propertyTimestamp");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 17);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "nullColumn");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{
|
||||
"nullColumn",
|
||||
"propertyBigDecimal",
|
||||
"propertyBoolean",
|
||||
"propertyByte",
|
||||
"propertyCalendar",
|
||||
"propertyChar",
|
||||
"propertyDate",
|
||||
"propertyDouble",
|
||||
"propertyFloat",
|
||||
"propertyInt",
|
||||
"propertyLong",
|
||||
"propertyShort",
|
||||
"propertySqlDate",
|
||||
"propertyString",
|
||||
"propertyStringbuffer",
|
||||
"propertyTime",
|
||||
"propertyTimestamp"});
|
||||
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (nullColumn, propertyBigDecimal, propertyBoolean, propertyByte, propertyCalendar, propertyChar, propertyDate, propertyDouble, propertyFloat, propertyInt, propertyLong, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
statement
|
||||
.setString(1, null)
|
||||
.setBigDecimal(2, new BigDecimal("98347.876438637"))
|
||||
.setBoolean(3, true)
|
||||
.setByte(4, (byte) 16)
|
||||
.setDate(5, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(6, "M")
|
||||
.setDate(7, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setDouble(8, 12.3d)
|
||||
.setFloat(9, 13.4f)
|
||||
.setInt(10, 34)
|
||||
.setLong(11, 45L)
|
||||
.setShort(12, (short) 12)
|
||||
.setDate(13, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(14, "string'value")
|
||||
.setString(15, "string'value2")
|
||||
.setTime(16, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(17, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldParametersMixedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
query.fieldParameter("nullColumn")
|
||||
.field("propertyBigDecimal", new BigDecimal("98347.876438637"))
|
||||
.fieldParameter("propertyBoolean")
|
||||
.fieldParameter("propertyByte")
|
||||
.field("propertyCalendar", cal.getTime())
|
||||
.fieldParameter("propertyChar")
|
||||
.field("propertyDate", cal)
|
||||
.field("propertyDouble", 12.3d)
|
||||
.fieldParameter("propertyFloat")
|
||||
.fieldParameter("propertyInt")
|
||||
.field("propertyLong", 45L)
|
||||
.field("propertyShort", (short) 12)
|
||||
.fieldParameter("propertySqlDate")
|
||||
.fieldParameter("propertyString")
|
||||
.field("propertyStringbuffer", new StringBuffer("stringbuffer'value"))
|
||||
.field("propertyTime", new Time(cal.getTime().getTime()))
|
||||
.fieldParameter("propertyTimestamp");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 9);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "nullColumn");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{
|
||||
"nullColumn",
|
||||
"propertyBoolean",
|
||||
"propertyByte",
|
||||
"propertyChar",
|
||||
"propertyFloat",
|
||||
"propertyInt",
|
||||
"propertySqlDate",
|
||||
"propertyString",
|
||||
"propertyTimestamp"});
|
||||
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (nullColumn, propertyBigDecimal, propertyBoolean, propertyByte, propertyCalendar, propertyChar, propertyDate, propertyDouble, propertyFloat, propertyInt, propertyLong, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (?, 98347.876438637, ?, ?, TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), ?, TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), 12.3, ?, ?, 45, 12, ?, ?, 'stringbuffer''value', TO_DATE('12:17:52', 'HH24:MI:SS'), ?)");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString(1, null)
|
||||
.setBoolean(2, true)
|
||||
.setByte(3, (byte) 16)
|
||||
.setString(4, "M")
|
||||
.setFloat(5, 13.4f)
|
||||
.setInt(6, 34)
|
||||
.setDate(7, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(8, "string'value")
|
||||
.setTimestamp(9, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fields(BeanImpl.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (219038743.392874, 1, 0, 89, 34, TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 'v', 'r', TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 53348.34, 143298.692, 'VALUE_THREE', 98634.2, 8734.7, 545, 968, 34563, 66875, 43, 68, TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), 'someotherstring', 'someotherstringbuff', TO_DATE('15:26:14', 'HH24:MI:SS'), TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanConstrainedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fields(BeanImplConstrained.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLongObject, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (219038743.392874, 1, 0, 34, TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 'v', 'r', TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 53348.34, 143298.692, 98634.2, 8734.7, 545, 968, 66875, 43, TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), 'someotherstring', 'someotherstringbuff', TO_DATE('15:26:14', 'HH24:MI:SS'), TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanNullValuesOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fields(BeanImpl.getNullBean());
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyDouble, propertyDoubleObject, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject) VALUES (0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0)");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanIncludedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsIncluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyByte, propertyDouble, propertyShort, propertyStringbuffer, propertyTime) VALUES (89, 53348.34, 43, 'someotherstringbuff', TO_DATE('15:26:14', 'HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanExcludedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsExcluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShortObject, propertySqlDate, propertyString, propertyTimestamp) VALUES (219038743.392874, 1, 0, 34, TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 'v', 'r', TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 143298.692, 'VALUE_THREE', 98634.2, 8734.7, 545, 968, 34563, 66875, 68, TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), 'someotherstring', TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'))");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsBeanFilteredOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsFiltered(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"}, new String[]{"propertyByte", "propertyShort", "propertyTime"});
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyDouble, propertyStringbuffer) VALUES (53348.34, 'someotherstringbuff')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleRowsOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.field("propertyChar", 'M')
|
||||
.field("propertyDouble", 12.3d)
|
||||
.field("propertyFloat", 13.4f)
|
||||
.field("propertyInt", 34);
|
||||
query.field("propertyChar", 'S')
|
||||
.field("propertyDouble", 45.1d)
|
||||
.field("propertyFloat", 27.9f);
|
||||
query.field("propertyChar", 'T');
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsParametersBeanOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsParameters(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 25);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(21), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(22), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(23), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(24), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByte", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLong", "propertyLongObject", "propertyShort", "propertyShortObject", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("98347.876438637"))
|
||||
.setBoolean(2, false)
|
||||
.setBoolean(3, true)
|
||||
.setByte(4, (byte) 16)
|
||||
.setByte(5, (byte) 72)
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(7, "M")
|
||||
.setString(8, "p")
|
||||
.setTimestamp(9, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(10, 12.3d)
|
||||
.setDouble(11, 68.7d)
|
||||
.setString(12, "VALUE_THREE")
|
||||
.setFloat(13, 13.4f)
|
||||
.setFloat(14, 42.1f)
|
||||
.setInt(15, 92)
|
||||
.setInt(16, 34)
|
||||
.setLong(17, 687L)
|
||||
.setLong(18, 92)
|
||||
.setShort(19, (short) 7)
|
||||
.setShort(20, (short) 12)
|
||||
.setDate(21, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(22, "string'value")
|
||||
.setString(23, "string'value2")
|
||||
.setTime(24, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(25, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsParametersBeanConstrainedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsParameters(BeanImplConstrained.class);
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLongObject, propertyShort, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 21);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("98347.876438637"))
|
||||
.setBoolean(2, false)
|
||||
.setBoolean(3, true)
|
||||
.setByte(4, (byte) 72)
|
||||
.setTimestamp(5, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(6, "M")
|
||||
.setString(7, "p")
|
||||
.setTimestamp(8, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(9, 12.3d)
|
||||
.setDouble(10, 68.7d)
|
||||
.setFloat(11, 13.4f)
|
||||
.setFloat(12, 42.1f)
|
||||
.setInt(13, 92)
|
||||
.setInt(14, 34)
|
||||
.setLong(15, 92)
|
||||
.setShort(16, (short) 7)
|
||||
.setDate(17, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(18, "string'value")
|
||||
.setString(19, "string'value2")
|
||||
.setTime(20, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(21, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsParametersBeanExcludedOracle() {
|
||||
Insert query = new Insert(ORACLE);
|
||||
query.into("tablename")
|
||||
.fieldsParametersExcluded(BeanImpl.class,
|
||||
new String[]{"propertyBoolean", "propertyByte", "propertyChar",
|
||||
"propertyDouble", "propertyInt", "propertyLong",
|
||||
"propertySqlDate", "propertyStringbuffer", "propertyTimestamp"});
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyBigDecimal, propertyBooleanObject, propertyByteObject, propertyCalendar, propertyCharacterObject, propertyDate, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyIntegerObject, propertyLongObject, propertyShort, propertyShortObject, propertyString, propertyTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 16);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyTime");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBooleanObject", "propertyByteObject", "propertyCalendar", "propertyCharacterObject", "propertyDate", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertyShortObject", "propertyString", "propertyTime"});
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("98347.876438637"))
|
||||
.setBoolean(2, true)
|
||||
.setByte(3, (byte) 72)
|
||||
.setTimestamp(4, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(5, "o")
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(7, 86.7d)
|
||||
.setString(8, "VALUE_THREE")
|
||||
.setFloat(9, 13.4f)
|
||||
.setFloat(10, 32.8f)
|
||||
.setInt(11, 358)
|
||||
.setLong(12, 9680L)
|
||||
.setShort(13, (short) 12)
|
||||
.setShort(14, (short) 78)
|
||||
.setString(15, "string'value")
|
||||
.setTime(16, new Time(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertSubselectParamsOracle() {
|
||||
Select fieldquery = new Select(ORACLE);
|
||||
fieldquery
|
||||
.from("table2")
|
||||
.field("max(propertyLong)")
|
||||
.whereParameter("propertyInt", ">");
|
||||
|
||||
// Manual subselect creation
|
||||
Insert query = new Insert(ORACLE);
|
||||
// shuffled the structure around a bit to test the correct order usage
|
||||
query
|
||||
.into("tablename")
|
||||
.fieldParameter("propertyString")
|
||||
.fieldCustom("propertyLong", "(" + fieldquery + ")")
|
||||
.fieldSubselect(fieldquery);
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyString, propertyLong) VALUES (?, (SELECT max(propertyLong) FROM table2 WHERE propertyInt > ?))");
|
||||
String[] parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(2, parameters.length);
|
||||
assertEquals(parameters[0], "propertyString");
|
||||
assertEquals(parameters[1], "propertyInt");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("propertyString", "thestring")
|
||||
.setLong("propertyInt", 90);
|
||||
}
|
||||
}));
|
||||
|
||||
// Automated subselect creation
|
||||
query = new Insert(ORACLE);
|
||||
// shuffled the structure around a bit to test the correct order usage
|
||||
query
|
||||
.into("tablename")
|
||||
.fieldParameter("propertyString")
|
||||
.field("propertyLong", fieldquery);
|
||||
assertEquals(query.getSql(), "INSERT INTO tablename (propertyString, propertyLong) VALUES (?, (SELECT max(propertyLong) FROM table2 WHERE propertyInt > ?))");
|
||||
parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(2, parameters.length);
|
||||
assertEquals(parameters[0], "propertyString");
|
||||
assertEquals(parameters[1], "propertyInt");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("propertyString", "thestring")
|
||||
.setLong("propertyInt", 90);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
Select fieldquery = new Select(ORACLE);
|
||||
fieldquery
|
||||
.from("table2")
|
||||
.field("max(propertyLong)")
|
||||
.whereParameter("propertyInt", ">");
|
||||
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.AUGUST, 19, 12, 17, 52);
|
||||
cal.set(Calendar.MILLISECOND, 462);
|
||||
Insert query = new Insert(ORACLE);
|
||||
query
|
||||
.hint("APPEND")
|
||||
.into("tablename")
|
||||
.fieldParameter("nullColumn")
|
||||
.field("propertyBigDecimal", new BigDecimal("98347.876438637"))
|
||||
.fieldParameter("propertyBoolean")
|
||||
.fieldParameter("propertyByte")
|
||||
.field("propertyCalendar", cal.getTime())
|
||||
.fieldParameter("propertyChar")
|
||||
.field("propertyDate", cal)
|
||||
.field("propertyDouble", 12.3d)
|
||||
.fieldParameter("propertyFloat")
|
||||
.fieldParameter("propertyInt")
|
||||
.field("propertyShort", (short) 12)
|
||||
.fieldParameter("propertySqlDate")
|
||||
.fieldParameter("propertyString")
|
||||
.field("propertyStringbuffer", new StringBuffer("stringbuffer'value"))
|
||||
.field("propertyTime", new Time(cal.getTime().getTime()))
|
||||
.fieldParameter("propertyTimestamp")
|
||||
.fieldCustom("propertyLong", "(" + fieldquery + ")")
|
||||
.fieldSubselect(fieldquery);
|
||||
|
||||
Insert query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("nullColumn", null)
|
||||
.setBoolean("propertyBoolean", true)
|
||||
.setByte("propertyByte", (byte) 16)
|
||||
.setString("propertyChar", "M")
|
||||
.setFloat("propertyFloat", 13.4f)
|
||||
.setInt("propertyInt", 34)
|
||||
.setDate("propertySqlDate", new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString("propertyString", "string'value")
|
||||
.setTimestamp("propertyTimestamp", new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -9,8 +9,7 @@ import rife.database.TestDatasources;
|
|||
|
||||
public class TestQuery {
|
||||
protected static Datasource PGSQL = TestDatasources.PGSQL;
|
||||
// TODO : oracle database
|
||||
protected static Datasource ORACLE = null;
|
||||
protected static Datasource ORACLE = TestDatasources.ORACLE;
|
||||
protected static Datasource HSQLDB = TestDatasources.HSQLDB;
|
||||
protected static Datasource H2 = TestDatasources.H2;
|
||||
protected static Datasource MYSQL = TestDatasources.MYSQL;
|
||||
|
|
972
lib/src/test/java/rife/database/queries/TestSelectOracle.java
Normal file
972
lib/src/test/java/rife/database/queries/TestSelectOracle.java
Normal file
|
@ -0,0 +1,972 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.BeanImpl;
|
||||
import rife.database.BeanImplConstrained;
|
||||
import rife.database.DbPreparedStatement;
|
||||
import rife.database.DbPreparedStatementHandler;
|
||||
import rife.database.exceptions.TableNameOrFieldsRequiredException;
|
||||
import rife.database.exceptions.UnsupportedSqlFeatureException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestSelectOracle extends TestSelect {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameOrFieldsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Select");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncompleteQueryOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameOrFieldsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Select");
|
||||
}
|
||||
query.from("tablename");
|
||||
assertNotNull(query.getSql());
|
||||
|
||||
query = new Select(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameOrFieldsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Select");
|
||||
}
|
||||
query.field("field");
|
||||
assertNotNull(query.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename");
|
||||
assertNotNull(query.getSql());
|
||||
query.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (TableNameOrFieldsRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "Select");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHintOracle() {
|
||||
Select query = new Select(ORACLE)
|
||||
.hint("NO_INDEX")
|
||||
.from("tablename");
|
||||
assertEquals(query.getSql(), "SELECT /*+ NO_INDEX */ * FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderByAscendingOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.orderBy("propertyInt", Select.ASC);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename ORDER BY propertyInt ASC");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderByDescendingOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.orderBy("propertyInt", Select.DESC);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename ORDER BY propertyInt DESC");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fields(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "SELECT propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanConstrainedOracle() {
|
||||
Select query = new Select(ORACLE, BeanImplConstrained.class);
|
||||
query.from("tablename");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename ORDER BY propertyString ASC, propertyInt DESC");
|
||||
assertTrue(execute(query));
|
||||
|
||||
query = new Select(ORACLE, BeanImplConstrained.class);
|
||||
query.from("tablename")
|
||||
.orderBy("propertyByte");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename ORDER BY propertyByte ASC");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanExcludedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fieldsExcluded(BeanImpl.class, "propertyCalendar", "propertyFloat", "propertyShort");
|
||||
assertEquals(query.getSql(), "SELECT propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanTableOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fields("tablename", BeanImpl.class);
|
||||
assertEquals(query.getSql(), "SELECT tablename.propertyBigDecimal, tablename.propertyBoolean, tablename.propertyBooleanObject, tablename.propertyByte, tablename.propertyByteObject, tablename.propertyCalendar, tablename.propertyChar, tablename.propertyCharacterObject, tablename.propertyDate, tablename.propertyDouble, tablename.propertyDoubleObject, tablename.propertyEnum, tablename.propertyFloat, tablename.propertyFloatObject, tablename.propertyInt, tablename.propertyIntegerObject, tablename.propertyLong, tablename.propertyLongObject, tablename.propertyShort, tablename.propertyShortObject, tablename.propertySqlDate, tablename.propertyString, tablename.propertyStringbuffer, tablename.propertyTime, tablename.propertyTimestamp FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanExcludedTableOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fieldsExcluded("tablename", BeanImpl.class, "propertyCalendar", "propertyFloat", "propertyShort");
|
||||
assertEquals(query.getSql(), "SELECT tablename.propertyBigDecimal, tablename.propertyBoolean, tablename.propertyBooleanObject, tablename.propertyByte, tablename.propertyByteObject, tablename.propertyChar, tablename.propertyCharacterObject, tablename.propertyDate, tablename.propertyDouble, tablename.propertyDoubleObject, tablename.propertyEnum, tablename.propertyFloatObject, tablename.propertyInt, tablename.propertyIntegerObject, tablename.propertyLong, tablename.propertyLongObject, tablename.propertyShortObject, tablename.propertySqlDate, tablename.propertyString, tablename.propertyStringbuffer, tablename.propertyTime, tablename.propertyTimestamp FROM tablename");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereTypedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2003, Calendar.MARCH, 3, 10, 1, 28);
|
||||
cal.set(Calendar.MILLISECOND, 154);
|
||||
|
||||
query
|
||||
.where("propertyBigDecimal", ">=", new BigDecimal("53443433.9784567"))
|
||||
.whereAnd("propertyBoolean", "=", false)
|
||||
.whereOr("propertyByte", "=", (byte) 54)
|
||||
.whereAnd("propertyCalendar", "<=", cal)
|
||||
.whereOr("propertyChar", "=", 'f')
|
||||
.whereAnd("propertyDate", "=", cal.getTime())
|
||||
.whereAnd("propertyDouble", "!=", 73453.71d)
|
||||
.whereOr("propertyFloat", ">=", 1987.14f)
|
||||
.whereAnd("propertyInt", "=", 973)
|
||||
.whereAnd("propertyLong", "<", 347678L)
|
||||
.whereAnd("propertyShort", "=", (short) 78)
|
||||
.whereOr("propertySqlDate", "=", new java.sql.Date(cal.getTime().getTime()))
|
||||
.whereAnd("propertyString", "LIKE", "someotherstring%")
|
||||
.whereAnd("propertyStringbuffer", "=", new StringBuffer("someotherstringbuff"))
|
||||
.whereOr("propertyTime", "=", new Time(cal.getTime().getTime()))
|
||||
.whereAnd("propertyTimestamp", "<=", new Timestamp(cal.getTime().getTime()));
|
||||
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = TO_DATE('2003/03/03 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertFalse(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereTypedMixedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(2003, Calendar.MARCH, 3, 10, 1, 28);
|
||||
cal.set(Calendar.MILLISECOND, 154);
|
||||
|
||||
query
|
||||
.where("propertyBigDecimal", ">=", new BigDecimal("53443433.9784567"))
|
||||
.whereAnd("propertyBoolean", "=", false)
|
||||
.whereOr("propertyByte = 54")
|
||||
.whereAnd("propertyCalendar", "<=", cal)
|
||||
.whereOr("propertyChar", "=", 'f')
|
||||
.whereAnd("propertyDate", "=", cal.getTime())
|
||||
.whereAnd("propertyDouble", "!=", 73453.71d)
|
||||
.whereOr("propertyFloat >= 1987.14")
|
||||
.whereAnd("propertyInt", "=", 973)
|
||||
.whereAnd("propertyLong", "<", 347678L)
|
||||
.whereAnd("propertyShort", "=", (short) 78)
|
||||
.whereParameterOr("propertySqlDate", "=")
|
||||
.whereAnd("propertyString", "LIKE", "someotherstring%")
|
||||
.whereAnd("propertyStringbuffer", "=", new StringBuffer("someotherstringbuff"))
|
||||
.whereOr("propertyTime", "=", new Time(cal.getTime().getTime()))
|
||||
.whereAnd("propertyTimestamp", "<=", new Timestamp(cal.getTime().getTime()));
|
||||
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = ? AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
|
||||
assertFalse(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setDate("propertySqlDate", new java.sql.Date(cal.getTime().getTime()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
|
||||
query.whereParameter("propertyInt", "=")
|
||||
.whereParameterAnd("propertyLong", "<")
|
||||
.whereParameterOr("propertyChar", "=");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 3);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyChar");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyInt", "propertyLong", "propertyChar"});
|
||||
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setInt(1, 545)
|
||||
.setLong(2, 50000)
|
||||
.setString(3, "v");
|
||||
}
|
||||
}));
|
||||
|
||||
query.where("propertyInt = 545");
|
||||
|
||||
assertNull(query.getParameters());
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyInt = 545");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersMixedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyInt = 545")
|
||||
.whereParameterAnd("propertyLong", "<")
|
||||
.whereParameterOr("propertyChar", "=");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyChar");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyLong", "propertyChar"});
|
||||
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyInt = 545 AND propertyLong < ? OR propertyChar = ?");
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setLong(1, 50000)
|
||||
.setString(2, "v");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereConstructionOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.where("propertyInt = 545")
|
||||
.whereAnd("propertyLong < 50000")
|
||||
.whereOr("propertyChar = 'v'");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyInt = 545 AND propertyLong < 50000 OR propertyChar = 'v'");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereConstructionGroupOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.startWhere()
|
||||
.where("propertyInt", "=", 545)
|
||||
.whereAnd("propertyByte", "=", 89)
|
||||
.end()
|
||||
.whereAnd("propertyLong < 50000")
|
||||
.startWhereOr()
|
||||
.whereParameter("propertyString", "=")
|
||||
.whereAnd("propertyByte", "<=", (byte) 0)
|
||||
.startWhereAnd()
|
||||
.where("propertyBoolean", "!=", true)
|
||||
.whereParameterOr("propertyStringbuffer", "LIKE")
|
||||
.end()
|
||||
.end()
|
||||
.whereOr("propertyChar = 'v'");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyStringbuffer");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyString", "propertyStringbuffer"});
|
||||
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE (propertyInt = 545 AND propertyByte = 89) AND propertyLong < 50000 OR (propertyString = ? AND propertyByte <= 0 AND (propertyBoolean != 1 OR propertyStringbuffer LIKE ?)) OR propertyChar = 'v'");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setString("propertyString", "someotherstring")
|
||||
.setString("propertyStringbuffer", "stringbuff");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImpl.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertyShortObject = 68 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanConstrainedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImplConstrained.getPopulatedBean());
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanNullValuesOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.where(BeanImpl.getNullBean());
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBoolean = 0 AND propertyBooleanObject = 0 AND propertyByte = 0 AND propertyByteObject = 0 AND propertyDouble = 0.0 AND propertyDoubleObject = 0.0 AND propertyFloat = 0.0 AND propertyFloatObject = 0.0 AND propertyInt = 0 AND propertyIntegerObject = 0 AND propertyLong = 0 AND propertyLongObject = 0 AND propertyShort = 0 AND propertyShortObject = 0");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanIncludedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereIncluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyByte = 89 AND propertyDouble = 53348.34 AND propertyShort = 43 AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanExcludedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereExcluded(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"});
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShortObject = 68 AND propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereBeanFilteredOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereFiltered(BeanImpl.getPopulatedBean(), new String[]{"propertyByte", "propertyDouble", "propertyShort", "propertyStringbuffer", "propertyTime"}, new String[]{"propertyByte", "propertyShort", "propertyTime"});
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyDouble = 53348.34 AND propertyStringbuffer = 'someotherstringbuff'");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParameters(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLong = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 25);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyLong");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(21), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(22), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(23), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(24), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByte", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLong", "propertyLongObject", "propertyShort", "propertyShortObject", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
// don't check if actual rows were returned, since Oracle doesn't
|
||||
// match on the date types
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, true)
|
||||
.setBoolean(3, false)
|
||||
.setByte(4, (byte) 89)
|
||||
.setByte(5, (byte) 34)
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(7, "v")
|
||||
.setString(8, "r")
|
||||
.setTimestamp(9, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(10, 53348.34d)
|
||||
.setDouble(11, 143298.692d)
|
||||
.setString(12, "VALUE_THREE")
|
||||
.setFloat(13, 98634.2f)
|
||||
.setFloat(14, 8734.7f)
|
||||
.setInt(15, 545)
|
||||
.setInt(16, 968)
|
||||
.setLong(17, 34563L)
|
||||
.setLong(18, 66875L)
|
||||
.setShort(19, (short) 43)
|
||||
.setShort(20, (short) 68)
|
||||
.setDate(21, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(22, "someotherstring")
|
||||
.setString(23, "someotherstringbuff")
|
||||
.setTime(24, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(25, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanConstrainedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParameters(BeanImplConstrained.class);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 22);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBoolean");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyByte");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyCalendar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyChar");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyDouble");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(13), "propertyInt");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(14), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(15), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(16), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(17), "propertySqlDate");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(18), "propertyString");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(19), "propertyStringbuffer");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(20), "propertyTime");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(21), "propertyTimestamp");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBoolean", "propertyBooleanObject", "propertyByte", "propertyByteObject", "propertyCalendar", "propertyChar", "propertyCharacterObject", "propertyDate", "propertyDouble", "propertyDoubleObject", "propertyFloat", "propertyFloatObject", "propertyInt", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertySqlDate", "propertyString", "propertyStringbuffer", "propertyTime", "propertyTimestamp"});
|
||||
|
||||
// don't check if actual rows were returned, since Oracle doesn't
|
||||
// match on the date types
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, true)
|
||||
.setBoolean(3, false)
|
||||
.setByte(4, (byte) 89)
|
||||
.setByte(5, (byte) 34)
|
||||
.setTimestamp(6, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setString(7, "v")
|
||||
.setString(8, "r")
|
||||
.setTimestamp(9, new java.sql.Timestamp(cal.getTime().getTime()))
|
||||
.setDouble(10, 53348.34d)
|
||||
.setDouble(11, 143298.692d)
|
||||
.setFloat(12, 98634.2f)
|
||||
.setFloat(13, 8734.7f)
|
||||
.setInt(14, 545)
|
||||
.setInt(15, 968)
|
||||
.setLong(16, 66875L)
|
||||
.setShort(17, (short) 43)
|
||||
.setDate(18, new java.sql.Date(cal.getTime().getTime()))
|
||||
.setString(19, "someotherstring")
|
||||
.setString(20, "someotherstringbuff")
|
||||
.setTime(21, new Time(cal.getTime().getTime()))
|
||||
.setTimestamp(22, new Timestamp(cal.getTime().getTime()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereParametersBeanExcludedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.whereParametersExcluded(BeanImpl.class,
|
||||
new String[]{"propertyBoolean", "propertyByte", "propertyChar",
|
||||
"propertyDouble", "propertyInt", "propertyLong",
|
||||
"propertySqlDate", "propertyStringbuffer", "propertyTimestamp",
|
||||
"propertyCalendar", "propertyDate", "propertyTime"});
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename WHERE propertyBigDecimal = ? AND propertyBooleanObject = ? AND propertyByteObject = ? AND propertyCharacterObject = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertyString = ?");
|
||||
|
||||
assertEquals(query.getParameters().getOrderedNames().size(), 13);
|
||||
assertEquals(query.getParameters().getOrderedNames().get(0), "propertyBigDecimal");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(1), "propertyBooleanObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(2), "propertyByteObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(3), "propertyCharacterObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(4), "propertyDoubleObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(5), "propertyEnum");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(6), "propertyFloat");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(7), "propertyFloatObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(8), "propertyIntegerObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(9), "propertyLongObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(10), "propertyShort");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(11), "propertyShortObject");
|
||||
assertEquals(query.getParameters().getOrderedNames().get(12), "propertyString");
|
||||
assertArrayEquals(query.getParameters().getOrderedNamesArray(), new String[]{"propertyBigDecimal", "propertyBooleanObject", "propertyByteObject", "propertyCharacterObject", "propertyDoubleObject", "propertyEnum", "propertyFloat", "propertyFloatObject", "propertyIntegerObject", "propertyLongObject", "propertyShort", "propertyShortObject", "propertyString"});
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2002, Calendar.JUNE, 18, 15, 26, 14);
|
||||
cal.set(Calendar.MILLISECOND, 764);
|
||||
statement
|
||||
.setBigDecimal(1, new BigDecimal("219038743.392874"))
|
||||
.setBoolean(2, false)
|
||||
.setByte(3, (byte) 34)
|
||||
.setString(4, "r")
|
||||
.setDouble(5, 143298.692d)
|
||||
.setString(6, "VALUE_THREE")
|
||||
.setFloat(7, 98634.2f)
|
||||
.setFloat(8, 8734.7f)
|
||||
.setInt(9, 968)
|
||||
.setLong(10, 66875L)
|
||||
.setShort(11, (short) 43)
|
||||
.setShort(12, (short) 68)
|
||||
.setString(13, "someotherstring");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistincOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.distinct()
|
||||
.where("propertyByte = 89")
|
||||
.orderBy("propertyDouble")
|
||||
.orderBy("propertyShort")
|
||||
.orderBy("propertyTime");
|
||||
assertEquals(query.getSql(), "SELECT DISTINCT * FROM tablename WHERE propertyByte = 89 ORDER BY propertyDouble ASC, propertyShort ASC, propertyTime ASC");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistinctOnOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.distinctOn("propertyDouble")
|
||||
.distinctOn("propertyShort")
|
||||
.distinctOn("propertyTime")
|
||||
.where("propertyByte = 89")
|
||||
.orderBy("propertyDouble")
|
||||
.orderBy("propertyShort")
|
||||
.orderBy("propertyTime");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.field("field1")
|
||||
.field("field2")
|
||||
.field("field3")
|
||||
.join("table2")
|
||||
.joinCross("table3")
|
||||
.where("this = that")
|
||||
.groupBy("gexpr1")
|
||||
.groupBy("gexpr2")
|
||||
.having("hexpr1")
|
||||
.having("hexpr2")
|
||||
.distinct()
|
||||
.unionAll("uexpr1")
|
||||
.union("uexpr2")
|
||||
.limit(3)
|
||||
.offset(1);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupByBeanOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fields(BeanImpl.class)
|
||||
.groupBy(BeanImpl.class);
|
||||
assertEquals(query.getSql(), "SELECT propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp FROM tablename GROUP BY propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyCalendar, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloat, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShort, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupByBeanExcludedOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.fieldsExcluded(BeanImpl.class, "propertyCalendar", "propertyFloat", "propertyShort")
|
||||
.groupByExcluded(BeanImpl.class, "propertyCalendar", "propertyFloat", "propertyShort");
|
||||
assertEquals(query.getSql(), "SELECT propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp FROM tablename GROUP BY propertyBigDecimal, propertyBoolean, propertyBooleanObject, propertyByte, propertyByteObject, propertyChar, propertyCharacterObject, propertyDate, propertyDouble, propertyDoubleObject, propertyEnum, propertyFloatObject, propertyInt, propertyIntegerObject, propertyLong, propertyLongObject, propertyShortObject, propertySqlDate, propertyString, propertyStringbuffer, propertyTime, propertyTimestamp");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.join("table2")
|
||||
.join("table3");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename, table2, table3");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinCustomOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.joinCustom("INNER JOIN table3 USING (propertyInt)")
|
||||
.joinCustom("CROSS JOIN table2");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename INNER JOIN table3 USING (propertyInt) CROSS JOIN table2");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinCrossOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.joinCross("table2")
|
||||
.joinCross("table3");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename CROSS JOIN table2 CROSS JOIN table3");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinInnerOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.joinInner("table2", Select.NATURAL, null);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename NATURAL INNER JOIN table2");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinInner("table2", Select.ON, "tablename.propertyInt = table2.propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename INNER JOIN table2 ON (tablename.propertyInt = table2.propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinInner("table2", Select.USING, "propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename INNER JOIN table2 USING (propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinOuterOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.FULL, Select.NATURAL, null);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename NATURAL FULL OUTER JOIN table2");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.LEFT, Select.NATURAL, null);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename NATURAL LEFT OUTER JOIN table2");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.RIGHT, Select.NATURAL, null);
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename NATURAL RIGHT OUTER JOIN table2");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.FULL, Select.ON, "tablename.propertyInt = table2.propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename FULL OUTER JOIN table2 ON (tablename.propertyInt = table2.propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.LEFT, Select.ON, "tablename.propertyInt = table2.propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename LEFT OUTER JOIN table2 ON (tablename.propertyInt = table2.propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.RIGHT, Select.ON, "tablename.propertyInt = table2.propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename RIGHT OUTER JOIN table2 ON (tablename.propertyInt = table2.propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.FULL, Select.USING, "propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename FULL OUTER JOIN table2 USING (propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.LEFT, Select.USING, "propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename LEFT OUTER JOIN table2 USING (propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
query.from("tablename")
|
||||
.joinOuter("table2", Select.RIGHT, Select.USING, "propertyInt");
|
||||
assertEquals(query.getSql(), "SELECT * FROM tablename RIGHT OUTER JOIN table2 USING (propertyInt)");
|
||||
assertTrue(execute(query));
|
||||
query.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.limit(3);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
query.offset(1);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitParameterOracle() {
|
||||
Select query = new Select(ORACLE);
|
||||
query.from("tablename")
|
||||
.limitParameter("limit");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
query.offsetParameter("offset");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (UnsupportedSqlFeatureException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubselectParamsOracle() {
|
||||
Select fieldquery = new Select(ORACLE);
|
||||
fieldquery
|
||||
.from("table2")
|
||||
.field("min(propertyLong)")
|
||||
.whereParameter("propertyInt", ">");
|
||||
Select tablequery = new Select(ORACLE);
|
||||
tablequery
|
||||
.from("table2")
|
||||
.whereParameter("propertyLong", "<");
|
||||
Select wherequery = new Select(ORACLE);
|
||||
wherequery
|
||||
.from("table3")
|
||||
.field("max(propertyShort)")
|
||||
.whereParameter("propertyShort", "!=");
|
||||
Select unionquery1 = new Select(ORACLE);
|
||||
unionquery1
|
||||
.from("table2")
|
||||
.field("propertyString")
|
||||
.field("max(propertyByte)")
|
||||
.whereParameter("propertyByte", "=")
|
||||
.groupBy("propertyString");
|
||||
Select unionquery2 = new Select(ORACLE);
|
||||
unionquery2
|
||||
.from("table2")
|
||||
.field("propertyStringbuffer")
|
||||
.field("min(propertyByte)")
|
||||
.whereParameter("propertyByte", ">")
|
||||
.groupBy("propertyStringbuffer");
|
||||
|
||||
// Manual subselect creation
|
||||
Select query = new Select(ORACLE);
|
||||
// shuffled the structure around a bit to test the correct order usage
|
||||
query
|
||||
.unionAll(unionquery1)
|
||||
.union(unionquery2)
|
||||
.where("tablename.propertyShort >= (" + wherequery + ")")
|
||||
.whereSubselect(wherequery)
|
||||
.whereParameterOr("tablename.propertyString", "propertyString", "=")
|
||||
.from("tablename")
|
||||
.join("(" + tablequery + ") tablesubselect")
|
||||
.tableSubselect(tablequery)
|
||||
.field("tablename.propertyString")
|
||||
.field("(" + fieldquery + ") AS propertyLong")
|
||||
.fieldSubselect(fieldquery);
|
||||
assertEquals(query.getSql(), "SELECT tablename.propertyString, (SELECT min(propertyLong) FROM table2 WHERE propertyInt > ?) AS propertyLong FROM tablename, (SELECT * FROM table2 WHERE propertyLong < ?) tablesubselect WHERE tablename.propertyShort >= (SELECT max(propertyShort) FROM table3 WHERE propertyShort != ?) OR tablename.propertyString = ? UNION ALL SELECT propertyString, max(propertyByte) FROM table2 WHERE propertyByte = ? GROUP BY propertyString UNION SELECT propertyStringbuffer, min(propertyByte) FROM table2 WHERE propertyByte > ? GROUP BY propertyStringbuffer");
|
||||
String[] parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(6, parameters.length);
|
||||
assertEquals(parameters[0], "propertyInt");
|
||||
assertEquals(parameters[1], "propertyLong");
|
||||
assertEquals(parameters[2], "propertyShort");
|
||||
assertEquals(parameters[3], "propertyString");
|
||||
assertEquals(parameters[4], "propertyByte");
|
||||
assertEquals(parameters[5], "propertyByte");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setInt("propertyInt", 1)
|
||||
.setLong("propertyLong", 99999999)
|
||||
.setShort("propertyShort", (short) 5)
|
||||
.setString("propertyString", "thestring")
|
||||
.setByte("propertyByte", (byte) 4);
|
||||
}
|
||||
}));
|
||||
|
||||
//Automated subselect creation
|
||||
query = new Select(ORACLE);
|
||||
query
|
||||
.union(unionquery1)
|
||||
.union(unionquery2)
|
||||
.where("tablename.propertyShort", ">=", wherequery)
|
||||
.whereParameterOr("tablename.propertyString", "propertyString", "=")
|
||||
.whereOr("tablename.propertyFloat", ">", new Select(ORACLE)
|
||||
.from("table3")
|
||||
.field("max(propertyLong)")
|
||||
.whereParameter("propertyLong", "!="))
|
||||
.from("tablename", new Select(ORACLE)
|
||||
.from("tablename"))
|
||||
.join("tablesubselect", tablequery)
|
||||
.whereAnd("tablename.propertyDouble", "<=", new Select(ORACLE)
|
||||
.from("table2")
|
||||
.field("max(propertyFloat)")
|
||||
.whereParameter("propertyFloat", "!="))
|
||||
.field("tablename.propertyString")
|
||||
.field("propertyLong", fieldquery);
|
||||
assertEquals(query.getSql(), "SELECT tablename.propertyString, (SELECT min(propertyLong) FROM table2 WHERE propertyInt > ?) AS propertyLong FROM (SELECT * FROM tablename) tablename, (SELECT * FROM table2 WHERE propertyLong < ?) tablesubselect WHERE tablename.propertyShort >= (SELECT max(propertyShort) FROM table3 WHERE propertyShort != ?) OR tablename.propertyString = ? OR tablename.propertyFloat > (SELECT max(propertyLong) FROM table3 WHERE propertyLong != ?) AND tablename.propertyDouble <= (SELECT max(propertyFloat) FROM table2 WHERE propertyFloat != ?) UNION SELECT propertyString, max(propertyByte) FROM table2 WHERE propertyByte = ? GROUP BY propertyString UNION SELECT propertyStringbuffer, min(propertyByte) FROM table2 WHERE propertyByte > ? GROUP BY propertyStringbuffer");
|
||||
parameters = query.getParameters().getOrderedNamesArray();
|
||||
assertEquals(8, parameters.length);
|
||||
assertEquals(parameters[0], "propertyInt");
|
||||
assertEquals(parameters[1], "propertyLong");
|
||||
assertEquals(parameters[2], "propertyShort");
|
||||
assertEquals(parameters[3], "propertyString");
|
||||
assertEquals(parameters[4], "propertyLong");
|
||||
assertEquals(parameters[5], "propertyFloat");
|
||||
assertEquals(parameters[6], "propertyByte");
|
||||
assertEquals(parameters[7], "propertyByte");
|
||||
|
||||
assertTrue(execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setInt("propertyInt", 1)
|
||||
.setLong("propertyLong", 99999999)
|
||||
.setShort("propertyShort", (short) 5)
|
||||
.setString("propertyString", "thestring")
|
||||
.setFloat("propertyFloat", -1f)
|
||||
.setByte("propertyByte", (byte) 4);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
Select fieldquery = new Select(ORACLE);
|
||||
fieldquery
|
||||
.from("table2")
|
||||
.field("min(propertyLong)")
|
||||
.whereParameter("propertyInt", ">");
|
||||
Select tablequery = new Select(ORACLE);
|
||||
tablequery
|
||||
.from("table2")
|
||||
.whereParameter("propertyLong", "<");
|
||||
Select wherequery = new Select(ORACLE);
|
||||
wherequery
|
||||
.from("table3")
|
||||
.field("max(propertyShort)")
|
||||
.whereParameter("propertyShort", "!=");
|
||||
Select unionquery1 = new Select(ORACLE);
|
||||
unionquery1
|
||||
.from("table2")
|
||||
.field("propertyString")
|
||||
.field("max(propertyByte)")
|
||||
.whereParameter("propertyByte", "=")
|
||||
.groupBy("propertyString");
|
||||
Select unionquery2 = new Select(ORACLE);
|
||||
unionquery2
|
||||
.from("table2")
|
||||
.field("propertyStringbuffer")
|
||||
.field("min(propertyByte)")
|
||||
.whereParameter("propertyByte", ">")
|
||||
.groupBy("propertyStringbuffer");
|
||||
Select query = new Select(ORACLE);
|
||||
query
|
||||
.hint("NO_INDEX")
|
||||
.from("tablename")
|
||||
.join("(" + tablequery + ") tablesubselect")
|
||||
.tableSubselect(tablequery)
|
||||
.joinCross("table3")
|
||||
.joinOuter("table2", Select.RIGHT, Select.ON, "table3.propertyInt = table2.propertyInt")
|
||||
.field("tablename.propertyString")
|
||||
.field("(" + fieldquery + ") propertyLongNew")
|
||||
.fieldSubselect(fieldquery)
|
||||
.where("tablename.propertyShort >= (" + wherequery + ")")
|
||||
.whereSubselect(wherequery)
|
||||
.whereParameterOr("tablename.propertyString", "propertyString", "=")
|
||||
.whereOr("tablename.propertyByte", "=", (byte) 54)
|
||||
.whereAnd("tablename.propertyDouble", "!=", 73453.71d)
|
||||
.whereParameterOr("tablename.propertyInt", "propertyInt", "=")
|
||||
.whereParameterAnd("tablename.propertyLong", "propertyLong", "<")
|
||||
.whereParameterOr("tablename.propertyChar", "propertyChar", "=")
|
||||
.groupBy("tablename.propertyShort")
|
||||
.groupBy("tablename.propertyLong")
|
||||
.groupBy("tablename.propertyString")
|
||||
.having("tablename.propertyLong = 1")
|
||||
.unionAll(unionquery1)
|
||||
.union(unionquery2);
|
||||
Select query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
execute(query, new DbPreparedStatementHandler<>() {
|
||||
public void setParameters(DbPreparedStatement statement) {
|
||||
statement
|
||||
.setInt("propertyInt", 1)
|
||||
.setLong("propertyLong", 99999999)
|
||||
.setShort("propertyShort", (short) 5)
|
||||
.setString("propertyString", "thestring")
|
||||
.setByte("propertyByte", (byte) 4)
|
||||
.setString("propertyChar", "c");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin <gbevin[remove] at uwyn dot com>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.database.queries;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.database.exceptions.SequenceNameRequiredException;
|
||||
import rife.database.exceptions.SequenceOperationRequiredException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestSequenceValueOracle extends TestSequenceValue {
|
||||
@Test
|
||||
public void testInstantiationOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
assertNotNull(query);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "SequenceValue");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "SequenceValue");
|
||||
}
|
||||
query.name("sequencename");
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceOperationRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "SequenceValue");
|
||||
}
|
||||
query.clear();
|
||||
query.next();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "SequenceValue");
|
||||
}
|
||||
query.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
query
|
||||
.name("sequencename")
|
||||
.next();
|
||||
assertNotNull(query.getSql());
|
||||
query
|
||||
.clear();
|
||||
try {
|
||||
query.getSql();
|
||||
fail();
|
||||
} catch (SequenceNameRequiredException e) {
|
||||
assertEquals(e.getQueryName(), "SequenceValue");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
query
|
||||
.name("sequencename")
|
||||
.next();
|
||||
assertEquals(query.getSql(), "SELECT sequencename.nextval FROM DUAL");
|
||||
assertTrue(execute(ORACLE, query) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
query
|
||||
.name("sequencename")
|
||||
.current();
|
||||
assertEquals(query.getSql(), "SELECT sequencename.currval FROM DUAL");
|
||||
assertTrue(execute(ORACLE, query) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneOracle() {
|
||||
SequenceValue query = new SequenceValue(ORACLE);
|
||||
query
|
||||
.name("sequencename")
|
||||
.next();
|
||||
SequenceValue query_clone = query.clone();
|
||||
assertEquals(query.getSql(), query_clone.getSql());
|
||||
assertNotSame(query, query_clone);
|
||||
assertTrue(execute(ORACLE, query_clone) >= 0);
|
||||
}
|
||||
}
|
1188
lib/src/test/java/rife/database/queries/TestUpdateOracle.java
Normal file
1188
lib/src/test/java/rife/database/queries/TestUpdateOracle.java
Normal file
File diff suppressed because it is too large
Load diff
|
@ -22,3 +22,7 @@ dependencies {
|
|||
runtimeOnly("org.eclipse.jetty:jetty-server:11.0.12")
|
||||
runtimeOnly("org.eclipse.jetty:jetty-servlet:11.0.12")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
enabled = false
|
||||
}
|
|
@ -19,3 +19,7 @@ tasks.war {
|
|||
webAppDirectory.set(file("../app/src/main/webapp"))
|
||||
webXml = file("src/web.xml") // copies a file to WEB-INF/web.xml
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
enabled = false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue