mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
commit
7c74da7e62
@ -323,6 +323,7 @@ public class FilterFactory {
|
||||
rv.add(expr.notLike("%"+knownValue.substring(1,2)+"%"));
|
||||
|
||||
if (!target.equals(Target.DERBY)
|
||||
&& !target.equals(Target.DB2)
|
||||
&& !target.equals(Target.FIREBIRD)
|
||||
&& !target.equals(Target.HSQLDB)
|
||||
&& !target.equals(Target.H2)
|
||||
|
||||
@ -248,6 +248,7 @@ public class MatchingFiltersFactory {
|
||||
|| (!target.equals(Target.HSQLDB)
|
||||
&& !target.equals(Target.FIREBIRD)
|
||||
&& !target.equals(Target.H2)
|
||||
&& !target.equals(Target.DB2)
|
||||
&& !target.equals(Target.DERBY)
|
||||
&& !target.equals(Target.SQLITE)
|
||||
&& !target.equals(Target.SQLSERVER))) {
|
||||
|
||||
@ -22,6 +22,10 @@ public enum Target{
|
||||
* CUBRID
|
||||
*/
|
||||
CUBRID,
|
||||
/**
|
||||
* DB2
|
||||
*/
|
||||
DB2,
|
||||
/**
|
||||
* Derby
|
||||
*/
|
||||
|
||||
@ -410,6 +410,9 @@ Configuration configuration = new Configuration(templates);
|
||||
<listitem>
|
||||
<para>CUBRIDTemplates (tested with CUBRID 8.4)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>DB2Templates (tested with DB2 10.1.2)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>DerbyTemplates (tested with Derby 10.8.2.2)</para>
|
||||
</listitem>
|
||||
|
||||
@ -401,6 +401,9 @@ Configuration configuration = new Configuration(templates);
|
||||
<listitem>
|
||||
<para>CUBRIDTemplates (tested with CUBRID 8.4)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>DB2Templates (tested with DB2 10.1.2)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>DerbyTemplates (tested with Derby 10.8.2.2)</para>
|
||||
</listitem>
|
||||
|
||||
@ -510,6 +510,7 @@
|
||||
<excludedGroups>com.mysema.testutil.Performance</excludedGroups>
|
||||
<excludes>
|
||||
<exclude>**/*$*</exclude>
|
||||
<exclude>**/DB2*SuiteTest.java</exclude>
|
||||
<exclude>**/MSSQL*SuiteTest.java</exclude>
|
||||
<exclude>**/Teradata*SuiteTest.java</exclude>
|
||||
</excludes>
|
||||
@ -530,6 +531,7 @@
|
||||
<excludedGroups>com.mysema.testutil.Performance</excludedGroups>
|
||||
<excludes>
|
||||
<exclude>**/*$*</exclude>
|
||||
<exclude>**/DB2*SuiteTest.java</exclude>
|
||||
<exclude>**/ExportOracleTest.java</exclude>
|
||||
<exclude>**/ExportTeradataTest.java</exclude>
|
||||
<exclude>**/Oracle*SuiteTest.java</exclude>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -191,7 +191,6 @@
|
||||
<version>1.2</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -316,6 +315,16 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>db2</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ibm.db2</groupId>
|
||||
<artifactId>db2-jdbc</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@ -17,6 +17,7 @@ import java.sql.Types;
|
||||
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.QueryModifiers;
|
||||
import com.mysema.query.sql.types.NumericBooleanType;
|
||||
import com.mysema.query.types.Ops;
|
||||
|
||||
/**
|
||||
@ -54,6 +55,7 @@ public class CUBRIDTemplates extends SQLTemplates {
|
||||
public CUBRIDTemplates(char escape, boolean quote) {
|
||||
super("\"", escape, quote);
|
||||
setDummyTable(null);
|
||||
addCustomType(NumericBooleanType.DEFAULT);
|
||||
setParameterMetadataAvailable(false);
|
||||
setNullsFirst(null);
|
||||
setNullsLast(null);
|
||||
@ -79,6 +81,7 @@ public class CUBRIDTemplates extends SQLTemplates {
|
||||
add(Ops.MathOps.SINH, "(exp({0}) - exp({0} * -1)) / 2");
|
||||
add(Ops.MathOps.TANH, "(exp({0} * 2) - 1) / (exp({0} * 2) + 1)");
|
||||
|
||||
addTypeNameToCode("numeric(1,0)", Types.BOOLEAN, true);
|
||||
addTypeNameToCode("numeric(3,0)", Types.TINYINT, true);
|
||||
addTypeNameToCode("numeric(38,0)", Types.BIGINT, true);
|
||||
addTypeNameToCode("bit varying", Types.LONGVARBINARY);
|
||||
|
||||
@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Copyright 2014, Timo Westkämper
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.mysema.query.QueryFlag;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.QueryModifiers;
|
||||
import com.mysema.query.types.Ops;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
|
||||
/**
|
||||
* DB2Templates is an SQL dialect for DB2 10.1.2
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public class DB2Templates extends SQLTemplates {
|
||||
|
||||
protected static final Set<String> DB2_RESERVED_WORDS = ImmutableSet.of(
|
||||
"ACCORDING", "ACCTNG", "ACTION", "ACTIVATE", "ADD", "AFTER",
|
||||
"ALIAS","ALL","ALLOCATE","ALLOW","ALTER","AND","ANY","APPEND",
|
||||
"APPLNAME","ARRAY","ARRAY_AGG","AS","ASC","ASENSITIVE","ASSOCIATE",
|
||||
"ASUTIME","AT","ATOMIC","ATTRIBUTES","AUDIT","AUTHORIZATION","AUX",
|
||||
"AUXILIARY","BEFORE","BEGIN","BETWEEN","BINARY","BIND","BIT",
|
||||
"BUFFERPOOL","BY","CACHE","CALL","CALLED","CAPTURE","CARDINALITY",
|
||||
"CASCADED","CASE","CAST","CCSID","CHAR","CHARACTER","CHECK","CL",
|
||||
"CLIENT","CLONE","CLOSE","CLUSTER","COLLECT","COLLECTION","COLLID",
|
||||
"COLUMN","COMMENT","COMMIT","COMPACT","COMPRESS","CONCAT","CONCURRENT",
|
||||
"CONDITION","CONNECT","CONNECT_BY_ROOT","CONNECTION","CONSTRAINT",
|
||||
"CONTAINS","CONTENT","CONTINUE","COPY","COUNT","COUNT_BIG","CREATE",
|
||||
"CROSS","CUBE","CURRENT","CURRENT_DATE","CURRENT_LC_CTYPE",
|
||||
"CURRENT_PATH","CURRENT_SCHEMA","CURRENT_SERVER","CURRENT_TIME",
|
||||
"CURRENT_TIMESTAMP","CURRENT_TIMEZONE","CURRENT_USER","CURSOR",
|
||||
"CYCLE","DATA","DATABASE","DATAPARTITIONNAME","DATAPARTITIONNUM",
|
||||
"DATE","DAY","DAYS","DB2GENERAL","DB2GENRL","DB2SQL","DBINFO",
|
||||
"DBPARTITIONNAME","DBPARTITIONNUM","DEACTIVATE","DEALLOCATE","DECLARE",
|
||||
"DEFAULT","DEFAULTS","DEFER","DEFINE","DEFINITION","DELETE","DENSERANK",
|
||||
"DENSE_RANK","DESC","DESCRIBE","DESCRIPTOR","DETERMINISTIC","DIAGNOSTICS",
|
||||
"DISABLE","DISALLOW","DISCONNECT","DISTINCT","DO","DOCUMENT","DOUBLE",
|
||||
"DROP","DSSIZE","DYNAMIC","EACH","EDITPROC","ELSE","ELSEIF","ENABLE",
|
||||
"ENCODING","ENCRYPTION","END","ENDING","END","ENFORCED","ERASE","ESCAPE",
|
||||
"EVERY","EXCEPT","EXCEPTION","EXCLUDING","EXCLUSIVE","EXECUTE","EXISTS",
|
||||
"EXIT","EXPLAIN","EXTEND","EXTERNAL","EXTRACT","FENCED","FETCH",
|
||||
"FIELDPROC","FILE","FINAL","FOR","FOREIGN","FREE","FREEPAGE","FROM",
|
||||
"FULL","FUNCTION","GBPCACHE","GENERAL","GENERATED","GET","GLOBAL","GO",
|
||||
"GOTO","GRANT","GRAPHIC","GROUP","HANDLER","HASH","HASHED_VALUE","HAVING",
|
||||
"HINT","HOLD","HOUR","HOURS","ID","IDENTITY","IF","IGNORE","IMMEDIATE",
|
||||
"IMPLICITLY","IN","INCLUDE","INCLUDING","INCLUSIVE","INCREMENT","INDEX",
|
||||
"INDEXBP","INDICATOR","INF","INFINITY","INHERIT","INNER","INOUT",
|
||||
"INSENSITIVE","INSERT","INTEGRITY","INTERSECT","INTO","IS","ISOBID",
|
||||
"ISOLATION","ITERATE","JAR","JAVA","JOIN","KEEP","KEY","LABEL","LANGUAGE",
|
||||
"LATERAL","LC_CTYPE","LEAVE","LEFT","LEVEL2","LIKE","LINKTYPE","LOCAL",
|
||||
"LOCALDATE","LOCALE","LOCALTIME","LOCALTIMESTAMP","LOCATION","LOCATOR",
|
||||
"LOCATORS","LOCK","LOCKSIZE","LOG","LOGGED","LONG","LOOP","MAINTAINED",
|
||||
"MATCHED","MATERIALIZED","MAXVALUE","MERGE","MICROSECOND","MICROSECONDS",
|
||||
"MINPCTUSED","MINUTE","MINUTES","MINVALUE","MIXED","MODE","MODIFIES",
|
||||
"MONTH","MONTHS","NAMESPACE","NAN","NATIONAL","NCHAR","NCLOB","NEW",
|
||||
"NEW_TABLE","NEXTVAL","NO","NOCACHE","NOCYCLE","NODENAME","NODENUMBER",
|
||||
"NOMAXVALUE","NOMINVALUE","NONE","NOORDER","NORMALIZED","NOT","NULL",
|
||||
"NULLS","NUMPARTS","NVARCHAR","OBID","OF","OLD","OLD_TABLE","ON","OPEN",
|
||||
"OPTIMIZATION","OPTIMIZE","OPTION","OR","ORDER","ORDINALITY","ORGANIZE",
|
||||
"OUT","OUTER","OVER","OVERRIDING","PACKAGE","PADDED","PAGE","PAGESIZE",
|
||||
"PARAMETER","PART","PARTITION","PARTITIONED","PARTITIONING","PARTITIONS",
|
||||
"PASSWORD","PATH","PCTFREE","PIECESIZE","PLAN","POSITION","PRECISION",
|
||||
"PREPARE","PREVVAL","PRIMARY","PRIQTY","PRIVILEGES","PROCEDURE","PROGRAM",
|
||||
"PROGRAMID","PSID","PUBLIC","QUERY","QUERYNO","RANGE","RANK","RCDFMT",
|
||||
"READ","READS","RECOVERY","REFERENCES","REFERENCING","REFRESH","RELEASE",
|
||||
"RENAME","REPEAT","RESET","RESIGNAL","RESTART","RESTRICT","RESULT",
|
||||
"RESULT_SET_LOCATOR","RETURN","RETURNS","REVOKE","RID","RIGHT","ROLE",
|
||||
"ROLLBACK","ROLLUP","ROUND_CEILING","ROUND_DOWN","ROUND_FLOOR","ROUND_HALF_DOWN",
|
||||
"ROUND_HALF_EVEN","ROUND_HALF_UP","ROUND_UP","ROUTINE","ROW","ROWNUMBER",
|
||||
"ROWS","ROWSET","ROW_NUMBER","RRN","RUN","SAVEPOINT","SBCS","SCHEMA",
|
||||
"SCRATCHPAD","SCROLL","SEARCH","SECOND","SECONDS","SECQTY","SECURITY",
|
||||
"SELECT","SENSITIVE","SEQUENCE","SESSION","SESSION_USER","SET","SIGNAL",
|
||||
"SIMPLE","SKIP","SNAN","SOME","SOURCE","SPECIFIC","SQL","SQLID","STACKED",
|
||||
"STANDARD","START","STARTING","STATEMENT","STATIC","STATMENT","STAY","STOGROUP",
|
||||
"STORES","STYLE","SUBSTRING","SUMMARY","SYNONYM","SYSFUN","SYSIBM","SYSPROC",
|
||||
"SYSTEM","SYSTEM_USER","TABLE","TABLESPACE","TABLESPACES","THEN","THREADSAFE",
|
||||
"TIME","TIMESTAMP","TO","TRANSACTION","TRIGGER","TRIM","TRIM_ARRAY","TRUNCATE",
|
||||
"TYPE","UNDO","UNION","UNIQUE","UNIT","UNNEST","UNTIL","UPDATE","URI","USAGE",
|
||||
"USE","USER","USERID","USING","VALIDPROC","VALUE","VALUES","VARIABLE","VARIANT",
|
||||
"VCAT","VERSION","VIEW","VOLATILE","VOLUMES","WAIT","WHEN","WHENEVER","WHERE",
|
||||
"WHILE","WITH","WITHOUT","WLM","WRAPPED","WRITE","WRKSTNNAME","XMLAGG",
|
||||
"XMLATTRIBUTES","XMLCAST","XMLCOMMENT","XMLCONCAT","XMLDOCUMENT","XMLELEMENT",
|
||||
"XMLEXISTS","XMLFOREST","XMLGROUP","XMLNAMESPACES","XMLPARSE","XMLPI",
|
||||
"XMLROW","XMLSERIALIZE","XMLTABLE","XMLTEXT","XMLVALIDATE","XSLTRANSFORM",
|
||||
"XSROBJECT","YEAR","YEARS","YES");
|
||||
|
||||
@SuppressWarnings("FieldNameHidesFieldInSuperclass") //Intentional
|
||||
public static final DB2Templates DEFAULT = new DB2Templates();
|
||||
|
||||
private String limitTemplate = "\nfetch first {0s} rows only";
|
||||
|
||||
private String outerQueryStart = "select * from (\n ";
|
||||
|
||||
private String outerQueryEnd = ") a where ";
|
||||
|
||||
private String limitOffsetTemplate = "rn > {0} and rn <= {1}";
|
||||
|
||||
private String offsetTemplate = "rn > {0}";
|
||||
|
||||
private String outerQuerySuffix = " order by rn";
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder() {
|
||||
@Override
|
||||
protected SQLTemplates build(char escape, boolean quote) {
|
||||
return new DB2Templates(escape, quote);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public DB2Templates() {
|
||||
this('\\',false);
|
||||
}
|
||||
|
||||
public DB2Templates(boolean quote) {
|
||||
this('\\',quote);
|
||||
}
|
||||
|
||||
public DB2Templates(char escape, boolean quote) {
|
||||
super(DB2_RESERVED_WORDS, "\"", escape, quote);
|
||||
setDummyTable("sysibm.sysdummy1");
|
||||
setAutoIncrement(" generated always as identity");
|
||||
setFunctionJoinsWrapped(true);
|
||||
setDefaultValues("\nvalues (default)");
|
||||
setNullsFirst(null);
|
||||
setNullsLast(null);
|
||||
|
||||
add(SQLOps.NEXTVAL, "next value for {0s}");
|
||||
|
||||
add(Ops.MathOps.RANDOM, "rand()");
|
||||
add(Ops.MathOps.LN, "log({0})");
|
||||
add(Ops.MathOps.LOG, "(log({0}) / log({1}))");
|
||||
add(Ops.MathOps.COTH, "(exp({0} * 2) + 1) / (exp({0} * 2) - 1)");
|
||||
|
||||
// overrides of the SQL standard functions
|
||||
add(Ops.DateTimeOps.SECOND, "second({0})");
|
||||
add(Ops.DateTimeOps.MINUTE, "minute({0})");
|
||||
add(Ops.DateTimeOps.HOUR, "hour({0})");
|
||||
add(Ops.DateTimeOps.WEEK, "week({0})");
|
||||
add(Ops.DateTimeOps.MONTH, "month({0})");
|
||||
add(Ops.DateTimeOps.YEAR, "year({0})");
|
||||
add(Ops.DateTimeOps.YEAR_MONTH, "(year({0}) * 100 + month({0}))");
|
||||
add(Ops.DateTimeOps.YEAR_WEEK, "(year({0}) * 100 + week({0}))");
|
||||
add(Ops.DateTimeOps.DAY_OF_WEEK, "dayofweek({0})");
|
||||
add(Ops.DateTimeOps.DAY_OF_MONTH, "day({0})");
|
||||
add(Ops.DateTimeOps.DAY_OF_YEAR, "dayofyear({0})");
|
||||
|
||||
add(Ops.DateTimeOps.ADD_YEARS, "{0} + {1} years");
|
||||
add(Ops.DateTimeOps.ADD_MONTHS, "{0} + {1} months");
|
||||
add(Ops.DateTimeOps.ADD_WEEKS, "{0} + {1} weeks");
|
||||
add(Ops.DateTimeOps.ADD_DAYS, "{0} + {1} days");
|
||||
add(Ops.DateTimeOps.ADD_HOURS, "{0} + {1} hours");
|
||||
add(Ops.DateTimeOps.ADD_MINUTES, "{0} + {1} minutes");
|
||||
add(Ops.DateTimeOps.ADD_SECONDS, "{0} + {1} seconds");
|
||||
|
||||
// FIXME
|
||||
add(Ops.DateTimeOps.DIFF_YEARS, "timestampdiff(256, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_MONTHS, "timestampdiff(64, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_WEEKS, "timestampdiff(32, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_DAYS, "timestampdiff(16, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_HOURS, "timestampdiff(8, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_MINUTES, "timestampdiff(4, char({0} - {1}))");
|
||||
add(Ops.DateTimeOps.DIFF_SECONDS, "timestampdiff(2, char({0} - {1}))");
|
||||
|
||||
add(Ops.DateTimeOps.TRUNC_YEAR, "trunc_timestamp({0}, 'year')");
|
||||
add(Ops.DateTimeOps.TRUNC_MONTH, "trunc_timestamp({0}, 'month')");
|
||||
add(Ops.DateTimeOps.TRUNC_WEEK, "trunc_timestamp({0}, 'week')");
|
||||
add(Ops.DateTimeOps.TRUNC_DAY, "trunc_timestamp({0}, 'day')");
|
||||
add(Ops.DateTimeOps.TRUNC_HOUR, "trunc_timestamp({0}, 'hour')");
|
||||
add(Ops.DateTimeOps.TRUNC_MINUTE, "trunc_timestamp({0}, 'minute')");
|
||||
add(Ops.DateTimeOps.TRUNC_SECOND, "trunc_timestamp({0}, 'second')");
|
||||
|
||||
addTypeNameToCode("smallint", Types.BOOLEAN, true);
|
||||
addTypeNameToCode("smallint", Types.TINYINT, true);
|
||||
addTypeNameToCode("long varchar for bit data", Types.LONGVARBINARY);
|
||||
addTypeNameToCode("varchar () for bit data", Types.VARBINARY);
|
||||
addTypeNameToCode("char () for bit data", Types.BINARY);
|
||||
addTypeNameToCode("long varchar", Types.LONGVARCHAR, true);
|
||||
addTypeNameToCode("object", Types.JAVA_OBJECT, true);
|
||||
addTypeNameToCode("xml", Types.SQLXML,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCastTypeNameForCode(int code) {
|
||||
switch (code) {
|
||||
case Types.VARCHAR: return "varchar(4000)";
|
||||
default: return super.getCastTypeNameForCode(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String serialize(String literal, int jdbcType) {
|
||||
if (jdbcType == Types.TIMESTAMP) {
|
||||
return "{ts '" + literal + "'}";
|
||||
} else if (jdbcType == Types.DATE) {
|
||||
return "{d '" + literal + "'}";
|
||||
} else if (jdbcType == Types.TIME) {
|
||||
return "{t '" + literal + "'}";
|
||||
} else {
|
||||
return super.serialize(literal, jdbcType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
|
||||
if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
|
||||
QueryModifiers mod = metadata.getModifiers();
|
||||
if (mod.getOffset() == null) {
|
||||
context.serializeForQuery(metadata, forCountRow);
|
||||
context.handle(limitTemplate, mod.getLimit());
|
||||
} else {
|
||||
context.append(outerQueryStart);
|
||||
metadata = metadata.clone();
|
||||
WindowFunction<Long> rn = SQLExpressions.rowNumber().over();
|
||||
for (OrderSpecifier<?> os : metadata.getOrderBy()) {
|
||||
rn.orderBy(os);
|
||||
}
|
||||
metadata.addProjection(rn.as("rn"));
|
||||
metadata.clearOrderBy();
|
||||
context.serializeForQuery(metadata, forCountRow);
|
||||
context.append(outerQueryEnd);
|
||||
if (mod.getLimit() == null) {
|
||||
context.handle(offsetTemplate, mod.getOffset());
|
||||
} else {
|
||||
context.handle(limitOffsetTemplate, mod.getOffset(), mod.getLimit() + mod.getOffset());
|
||||
}
|
||||
context.append(outerQuerySuffix);
|
||||
}
|
||||
|
||||
} else {
|
||||
context.serializeForQuery(metadata, forCountRow);
|
||||
}
|
||||
|
||||
if (!metadata.getFlags().isEmpty()) {
|
||||
context.serialize(QueryFlag.Position.END, metadata.getFlags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serializeModifiers(QueryMetadata metadata, SQLSerializer context) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -61,7 +61,6 @@ public class DerbyTemplates extends SQLTemplates {
|
||||
setDefaultValues("\nvalues (default)");
|
||||
|
||||
add(Ops.CONCAT, "varchar({0} || {1})");
|
||||
add(Ops.DateTimeOps.DAY_OF_MONTH, "day({0})");
|
||||
|
||||
add(SQLOps.NEXTVAL, "next value for {0s}");
|
||||
|
||||
@ -120,7 +119,9 @@ public class DerbyTemplates extends SQLTemplates {
|
||||
|
||||
@Override
|
||||
public String serialize(String literal, int jdbcType) {
|
||||
if (jdbcType == Types.TIMESTAMP) {
|
||||
if (jdbcType == Types.BOOLEAN) {
|
||||
return "1".equals(literal) ? "true" : "false";
|
||||
} else if (jdbcType == Types.TIMESTAMP) {
|
||||
return "{ts '" + literal + "'}";
|
||||
} else if (jdbcType == Types.DATE) {
|
||||
return "{d '" + literal + "'}";
|
||||
|
||||
@ -155,4 +155,13 @@ public class PostgresTemplates extends SQLTemplates {
|
||||
addTypeNameToCode("timestamptz", Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(String literal, int jdbcType) {
|
||||
if (jdbcType == Types.BOOLEAN) {
|
||||
return "1".equals(literal) ? "true" : "false";
|
||||
} else {
|
||||
return super.serialize(literal, jdbcType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@ package com.mysema.query.sql;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import com.mysema.query.sql.types.BigDecimalAsDoubleType;
|
||||
import com.mysema.query.types.Ops;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import com.mysema.query.sql.types.BigDecimalAsDoubleType;
|
||||
import com.mysema.query.sql.types.BigIntegerAsLongType;
|
||||
import com.mysema.query.types.Ops;
|
||||
|
||||
/**
|
||||
* SQLiteTemplates is a SQL dialect for SQLite
|
||||
*
|
||||
@ -58,6 +60,7 @@ public class SQLiteTemplates extends SQLTemplates {
|
||||
super("\"", escape, quote);
|
||||
setDummyTable(null);
|
||||
addCustomType(BigDecimalAsDoubleType.DEFAULT);
|
||||
addCustomType(BigIntegerAsLongType.DEFAULT);
|
||||
setUnionsWrapped(false);
|
||||
setLimitRequired(true);
|
||||
setNullsFirst(null);
|
||||
|
||||
@ -39,7 +39,8 @@ public class BigDecimalAsDoubleType extends AbstractType<BigDecimal> {
|
||||
|
||||
@Override
|
||||
public BigDecimal getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
return BigDecimal.valueOf(rs.getDouble(startIndex));
|
||||
Number num = (Number)rs.getObject(startIndex);
|
||||
return num != null ? BigDecimal.valueOf(num.doubleValue()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2015, Timo Westkämper
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.sql.types;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* BigIntegerType maps BigInteger to Long on the JDBC level
|
||||
*
|
||||
* @author tiwe
|
||||
*
|
||||
*/
|
||||
public class BigIntegerAsLongType extends AbstractType<BigInteger> {
|
||||
|
||||
public static final BigIntegerAsLongType DEFAULT = new BigIntegerAsLongType();
|
||||
|
||||
public BigIntegerAsLongType() {
|
||||
super(Types.NUMERIC);
|
||||
}
|
||||
|
||||
public BigIntegerAsLongType(int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Number num = (Number) rs.getObject(startIndex);
|
||||
return num != null ? BigInteger.valueOf(num.longValue()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BigInteger> getReturnedClass() {
|
||||
return BigInteger.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, BigInteger value)
|
||||
throws SQLException {
|
||||
st.setLong(startIndex, value.longValue());
|
||||
}
|
||||
|
||||
}
|
||||
@ -28,6 +28,8 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class NumericBooleanType extends AbstractType<Boolean> {
|
||||
|
||||
public static NumericBooleanType DEFAULT = new NumericBooleanType();
|
||||
|
||||
public NumericBooleanType() {
|
||||
super(Types.INTEGER);
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Target.CUBRID;
|
||||
import static com.mysema.query.Target.DB2;
|
||||
import static com.mysema.query.Target.DERBY;
|
||||
import static com.mysema.query.Target.ORACLE;
|
||||
import static com.mysema.query.Target.POSTGRES;
|
||||
@ -31,7 +32,7 @@ import com.mysema.query.sql.domain.Employee;
|
||||
import com.mysema.query.sql.domain.QEmployee;
|
||||
import com.mysema.testutil.ExcludeIn;
|
||||
|
||||
@ExcludeIn({CUBRID, DERBY, ORACLE, SQLSERVER, POSTGRES, SQLITE, TERADATA})
|
||||
@ExcludeIn({CUBRID, DB2, DERBY, ORACLE, SQLSERVER, POSTGRES, SQLITE, TERADATA})
|
||||
public class BeanPopulationBase extends AbstractBaseTest {
|
||||
|
||||
private final QEmployee e = new QEmployee("e");
|
||||
|
||||
@ -60,7 +60,7 @@ public final class Connections {
|
||||
|
||||
private static ThreadLocal<Statement> stmtHolder = new ThreadLocal<Statement>();
|
||||
|
||||
private static boolean derbyInited, sqlServerInited, h2Inited, hsqlInited, mysqlInited, cubridInited, oracleInited, postgresInited, sqliteInited, teradataInited, firebirdInited;
|
||||
private static boolean db2Inited, derbyInited, sqlServerInited, h2Inited, hsqlInited, mysqlInited, cubridInited, oracleInited, postgresInited, sqliteInited, teradataInited, firebirdInited;
|
||||
|
||||
public static void close() throws SQLException{
|
||||
if (stmtHolder.get() != null) {
|
||||
@ -87,6 +87,12 @@ public final class Connections {
|
||||
configurationHolder.set(new Configuration(templates));
|
||||
}
|
||||
|
||||
private static Connection getDB2() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.ibm.db2.jcc.DB2Driver");
|
||||
String url = "jdbc:db2://192.168.0.14:50001/SAMPLE";
|
||||
return DriverManager.getConnection(url, "db2inst1", "a3sd!fDj");
|
||||
}
|
||||
|
||||
private static Connection getDerby() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
||||
String url = "jdbc:derby:target/demoDB;create=true";
|
||||
@ -299,6 +305,67 @@ public final class Connections {
|
||||
cubridInited = true;
|
||||
}
|
||||
|
||||
public static void initDB2() throws SQLException, ClassNotFoundException {
|
||||
targetHolder.set(Target.DB2);
|
||||
SQLTemplates templates = new DB2Templates();
|
||||
Connection c = getDB2();
|
||||
connHolder.set(c);
|
||||
Statement stmt = c.createStatement();
|
||||
stmtHolder.set(stmt);
|
||||
|
||||
if (db2Inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
// survey
|
||||
dropTable(templates, "SURVEY");
|
||||
stmt.execute("create table SURVEY(" +
|
||||
"ID int generated by default as identity(start with 1, increment by 1), " +
|
||||
"NAME varchar(30)," +
|
||||
"NAME2 varchar(30))");
|
||||
stmt.execute("insert into SURVEY values (1,'Hello World','Hello')");
|
||||
|
||||
// test
|
||||
dropTable(templates, "TEST");
|
||||
stmt.execute(CREATE_TABLE_TEST);
|
||||
stmt.execute("create index test_name on test(name)");
|
||||
PreparedStatement pstmt = c.prepareStatement(INSERT_INTO_TEST_VALUES);
|
||||
try{
|
||||
for (int i = 0; i < TEST_ROW_COUNT; i++) {
|
||||
pstmt.setString(1, "name" + i);
|
||||
pstmt.addBatch();
|
||||
}
|
||||
pstmt.executeBatch();
|
||||
}finally{
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
// employee
|
||||
dropTable(templates, "EMPLOYEE");
|
||||
|
||||
createEmployeeTable(templates);
|
||||
|
||||
addEmployees(INSERT_INTO_EMPLOYEE);
|
||||
|
||||
// date_test and time_test
|
||||
dropTable(templates, "TIME_TEST");
|
||||
stmt.execute(CREATE_TABLE_TIMETEST);
|
||||
|
||||
dropTable(templates, "DATE_TEST");
|
||||
stmt.execute(CREATE_TABLE_DATETEST);
|
||||
|
||||
// numbers
|
||||
dropTable(templates, "NUMBER_TEST");
|
||||
stmt.execute("create table NUMBER_TEST(col1 smallint)");
|
||||
|
||||
// xml
|
||||
dropTable(templates, "XML_TEST");
|
||||
stmt.execute("create table XML_TEST(COL varchar(128))");
|
||||
|
||||
db2Inited = true;
|
||||
}
|
||||
|
||||
|
||||
public static void initDerby() throws SQLException, ClassNotFoundException {
|
||||
targetHolder.set(Target.DERBY);
|
||||
SQLTemplates templates = new DerbyTemplates();
|
||||
|
||||
@ -173,14 +173,14 @@ public class InsertBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(DERBY)
|
||||
@ExcludeIn({DB2, DERBY})
|
||||
public void Insert_Null_Without_Columns() {
|
||||
assertEquals(1, insert(survey)
|
||||
.values(4, null, null).execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({FIREBIRD, HSQLDB, DERBY, ORACLE})
|
||||
@ExcludeIn({FIREBIRD, HSQLDB, DB2, DERBY, ORACLE})
|
||||
public void Insert_Without_Values() {
|
||||
assertEquals(1, insert(survey).execute());
|
||||
}
|
||||
|
||||
@ -13,9 +13,18 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Constants.survey2;
|
||||
import static com.mysema.query.Target.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.sql.dml.SQLMergeClause;
|
||||
import com.mysema.query.sql.domain.QSurvey;
|
||||
import com.mysema.query.support.Expressions;
|
||||
@ -23,13 +32,6 @@ import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathImpl;
|
||||
import com.mysema.testutil.ExcludeIn;
|
||||
import com.mysema.testutil.IncludeIn;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Constants.survey2;
|
||||
import static com.mysema.query.Target.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MergeBase extends AbstractBaseTest{
|
||||
|
||||
@ -96,7 +98,7 @@ public class MergeBase extends AbstractBaseTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({CUBRID, DERBY, POSTGRES, SQLSERVER})
|
||||
@ExcludeIn({CUBRID, DB2, DERBY, POSTGRES, SQLSERVER})
|
||||
public void Merge_With_Keys_Null_Id() throws SQLException{
|
||||
ResultSet rs = merge(survey).keys(survey.id)
|
||||
.setNull(survey.id)
|
||||
|
||||
@ -176,13 +176,13 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({ORACLE, CUBRID, FIREBIRD, DERBY, SQLSERVER, SQLITE, TERADATA})
|
||||
@ExcludeIn({ORACLE, CUBRID, FIREBIRD, DB2, DERBY, SQLSERVER, SQLITE, TERADATA})
|
||||
public void Boolean_All() {
|
||||
assertTrue(query().from(employee).uniqueResult(SQLExpressions.all(employee.firstname.isNotNull())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({ORACLE, CUBRID, FIREBIRD, DERBY, SQLSERVER, SQLITE, TERADATA})
|
||||
@ExcludeIn({ORACLE, CUBRID, FIREBIRD, DB2, DERBY, SQLSERVER, SQLITE, TERADATA})
|
||||
public void Boolean_Any() {
|
||||
assertTrue(query().from(employee).uniqueResult(SQLExpressions.any(employee.firstname.isNotNull())));
|
||||
}
|
||||
@ -435,7 +435,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({CUBRID, SQLITE, TERADATA})
|
||||
@ExcludeIn({CUBRID, DB2, SQLITE, TERADATA})
|
||||
public void Date_Diff() {
|
||||
QEmployee employee2 = new QEmployee("employee2");
|
||||
TestQuery query = query().from(employee, employee2);
|
||||
@ -458,7 +458,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({CUBRID, DERBY, HSQLDB, SQLITE, TERADATA})
|
||||
@ExcludeIn({CUBRID, DB2, DERBY, HSQLDB, SQLITE, TERADATA})
|
||||
public void Date_Diff2() {
|
||||
TestQuery query = query().from(employee).orderBy(employee.id.asc());
|
||||
|
||||
@ -482,7 +482,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, SQLITE, SQLSERVER, TERADATA}) // FIXME
|
||||
@ExcludeIn({CUBRID, DB2, DERBY, FIREBIRD, H2, HSQLDB, MYSQL, SQLITE, SQLSERVER, TERADATA}) // FIXME
|
||||
public void Date_Trunc() {
|
||||
DateTimeExpression<java.util.Date> expr = DateTimeExpression.currentTimestamp();
|
||||
|
||||
@ -603,7 +603,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({H2, DERBY, ORACLE, SQLSERVER})
|
||||
@ExcludeIn({H2, DB2, DERBY, ORACLE, SQLSERVER})
|
||||
public void GroupBy_Validate() {
|
||||
NumberPath<BigDecimal> alias = new NumberPath<BigDecimal>(BigDecimal.class, "alias");
|
||||
query().from(employee)
|
||||
@ -754,7 +754,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(DERBY)
|
||||
@ExcludeIn({DB2, DERBY})
|
||||
public void Like_Number() {
|
||||
assertEquals(5, query().from(employee)
|
||||
.where(employee.id.like("1%")).count());
|
||||
@ -821,7 +821,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({ORACLE, DERBY, FIREBIRD, SQLSERVER, CUBRID, TERADATA})
|
||||
@ExcludeIn({ORACLE, DB2, DERBY, FIREBIRD, SQLSERVER, CUBRID, TERADATA})
|
||||
@SkipForQuoted
|
||||
public void Limit_and_Offset2() throws SQLException {
|
||||
// limit
|
||||
@ -868,7 +868,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({DERBY, HSQLDB})
|
||||
@ExcludeIn({DB2, DERBY, HSQLDB})
|
||||
public void Literals() {
|
||||
assertEquals(1, singleResult(ConstantImpl.create(1)).intValue());
|
||||
assertEquals(2l, singleResult(ConstantImpl.create(2l)).longValue());
|
||||
@ -1073,7 +1073,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({DERBY, FIREBIRD, HSQLDB, ORACLE, SQLSERVER})
|
||||
@ExcludeIn({DB2, DERBY, FIREBIRD, HSQLDB, ORACLE, SQLSERVER})
|
||||
@SkipForQuoted
|
||||
public void Path_Alias() {
|
||||
expectedQuery = "select e.LASTNAME, sum(e.SALARY) as salarySum " +
|
||||
@ -1445,7 +1445,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({DERBY, FIREBIRD})
|
||||
@ExcludeIn({DB2, DERBY, FIREBIRD})
|
||||
public void Substring() {
|
||||
//SELECT * FROM account where SUBSTRING(name, -x, 1) = SUBSTRING(name, -y, 1)
|
||||
query().from(employee)
|
||||
@ -1504,7 +1504,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(DERBY)
|
||||
@ExcludeIn({DB2, DERBY})
|
||||
public void Tuple2() {
|
||||
query().from(employee)
|
||||
.list(Expressions.as(ConstantImpl.create("1"),"code"),
|
||||
@ -1705,7 +1705,7 @@ public class SelectBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({DERBY, H2})
|
||||
@ExcludeIn({DB2, DERBY, H2})
|
||||
public void YearWeek() {
|
||||
TestQuery query = query().from(employee).orderBy(employee.id.asc());
|
||||
assertEquals(Integer.valueOf(200006), query.singleResult(employee.datefield.yearWeek()));
|
||||
|
||||
@ -3,6 +3,7 @@ package com.mysema.query;
|
||||
import static com.mysema.query.Constants.employee;
|
||||
import static com.mysema.query.Constants.employee2;
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Target.DB2;
|
||||
import static com.mysema.query.Target.ORACLE;
|
||||
import static com.mysema.query.Target.SQLSERVER;
|
||||
import static com.mysema.query.Target.TERADATA;
|
||||
@ -36,9 +37,9 @@ public class SelectWindowFunctionsBase extends AbstractBaseTest {
|
||||
add(exprs, SQLExpressions.avg(path));
|
||||
add(exprs, SQLExpressions.count(path));
|
||||
add(exprs, SQLExpressions.corr(path, path2));
|
||||
add(exprs, SQLExpressions.covarPop(path, path2));
|
||||
add(exprs, SQLExpressions.covarSamp(path, path2));
|
||||
add(exprs, SQLExpressions.cumeDist(), TERADATA);
|
||||
add(exprs, SQLExpressions.covarPop(path, path2), DB2);
|
||||
add(exprs, SQLExpressions.covarSamp(path, path2), DB2);
|
||||
add(exprs, SQLExpressions.cumeDist(), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.denseRank(), TERADATA);
|
||||
add(exprs, SQLExpressions.firstValue(path), TERADATA);
|
||||
add(exprs, SQLExpressions.lag(path), TERADATA);
|
||||
@ -46,18 +47,18 @@ public class SelectWindowFunctionsBase extends AbstractBaseTest {
|
||||
add(exprs, SQLExpressions.lead(path), TERADATA);
|
||||
add(exprs, SQLExpressions.max(path));
|
||||
add(exprs, SQLExpressions.min(path));
|
||||
add(exprs, SQLExpressions.nthValue(path, 2), TERADATA);
|
||||
add(exprs, SQLExpressions.ntile(3), TERADATA);
|
||||
add(exprs, SQLExpressions.percentRank());
|
||||
add(exprs, SQLExpressions.nthValue(path, 2), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.ntile(3), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.percentRank(), DB2);
|
||||
add(exprs, SQLExpressions.rank());
|
||||
add(exprs, SQLExpressions.rowNumber());
|
||||
add(exprs, SQLExpressions.stddev(path), TERADATA);
|
||||
add(exprs, SQLExpressions.stddevPop(path), TERADATA);
|
||||
add(exprs, SQLExpressions.stddevSamp(path), TERADATA);
|
||||
add(exprs, SQLExpressions.stddevPop(path), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.stddevSamp(path), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.sum(path));
|
||||
add(exprs, SQLExpressions.variance(path), TERADATA);
|
||||
add(exprs, SQLExpressions.varPop(path), TERADATA);
|
||||
add(exprs, SQLExpressions.varSamp(path), TERADATA);
|
||||
add(exprs, SQLExpressions.varPop(path), DB2, TERADATA);
|
||||
add(exprs, SQLExpressions.varSamp(path), DB2, TERADATA);
|
||||
|
||||
for (WindowOver<?> wo : exprs) {
|
||||
query().from(survey).list(wo.over().partitionBy(survey.name).orderBy(survey.id));
|
||||
@ -121,7 +122,7 @@ public class SelectWindowFunctionsBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(SQLSERVER)
|
||||
@ExcludeIn({DB2, SQLSERVER})
|
||||
public void WindowFunctions_Regr() {
|
||||
List<WindowOver<?>> exprs = new ArrayList<WindowOver<?>>();
|
||||
NumberPath<Integer> path = survey.id;
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Constants.*;
|
||||
import static com.mysema.query.Target.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mysema.query.sql.Configuration;
|
||||
import com.mysema.query.sql.ForeignKey;
|
||||
@ -18,11 +25,6 @@ import com.mysema.query.types.path.NumberPath;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.mysema.query.types.query.ListSubQuery;
|
||||
import com.mysema.testutil.ExcludeIn;
|
||||
import org.junit.Test;
|
||||
import static com.mysema.query.Constants.*;
|
||||
import static com.mysema.query.Target.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class SubqueriesBase extends AbstractBaseTest {
|
||||
|
||||
@ -54,6 +56,7 @@ public class SubqueriesBase extends AbstractBaseTest {
|
||||
|
||||
@Test
|
||||
@SkipForQuoted
|
||||
@ExcludeIn(DB2) // ID is reserved IN DB2
|
||||
public void SubQueries() throws SQLException {
|
||||
// subquery in where block
|
||||
expectedQuery = "select e.ID from EMPLOYEE e "
|
||||
|
||||
@ -1,20 +1,60 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Target.CUBRID;
|
||||
import static com.mysema.query.Target.POSTGRES;
|
||||
import static com.mysema.query.Target.TERADATA;
|
||||
import static com.mysema.query.Target.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mysema.query.ddl.CreateTableClause;
|
||||
import com.mysema.query.ddl.DropTableClause;
|
||||
import com.mysema.query.sql.RelationalPath;
|
||||
import com.mysema.query.sql.RelationalPathBase;
|
||||
import com.mysema.query.support.Expressions;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.testutil.ExcludeIn;
|
||||
|
||||
public class TypesBase extends AbstractBaseTest {
|
||||
|
||||
@Test
|
||||
public void CreateTables() {
|
||||
Map<Class<?>, Object> instances = Maps.newLinkedHashMap();
|
||||
instances.put(BigInteger.class, BigInteger.valueOf(1));
|
||||
instances.put(Long.class, Long.valueOf(1));
|
||||
instances.put(Integer.class, Integer.valueOf(1));
|
||||
instances.put(Short.class, Short.valueOf((short)1));
|
||||
instances.put(Byte.class, Byte.valueOf((byte)1));
|
||||
instances.put(BigDecimal.class, BigDecimal.valueOf(1.0));
|
||||
instances.put(Double.class, Double.valueOf(1.0));
|
||||
instances.put(Float.class, Float.valueOf((float)1.0));
|
||||
instances.put(Boolean.class, Boolean.TRUE);
|
||||
instances.put(Character.class, Character.valueOf('a'));
|
||||
instances.put(String.class, "ABC");
|
||||
|
||||
for (Map.Entry<Class<?>, Object> entry : instances.entrySet()) {
|
||||
String tableName = "test_" + entry.getKey().getSimpleName();
|
||||
new DropTableClause(connection, configuration, tableName).execute();
|
||||
CreateTableClause c = new CreateTableClause(connection, configuration, tableName)
|
||||
.column("col", entry.getKey());
|
||||
if (entry.getKey().equals(String.class)) {
|
||||
c.size(256);
|
||||
}
|
||||
c.execute();
|
||||
RelationalPath<Object> entityPath = new RelationalPathBase<Object>(Object.class, tableName, "PUBLIC", tableName);
|
||||
Path<?> columnPath = Expressions.path(entry.getKey(), entityPath, "col");
|
||||
insert(entityPath).set((Path)columnPath, entry.getValue()).execute();
|
||||
new DropTableClause(connection, configuration, tableName).execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({CUBRID, POSTGRES, TERADATA})
|
||||
public void DumpTypes() throws SQLException {
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
*/
|
||||
package com.mysema.query.sql.types;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
@ -23,15 +26,14 @@ import java.net.URL;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
import org.easymock.EasyMock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.joda.time.LocalTime;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
|
||||
public class TypeTest implements InvocationHandler{
|
||||
|
||||
@ -61,6 +63,8 @@ public class TypeTest implements InvocationHandler{
|
||||
List<Pair<?,?>> valueAndType = new ArrayList<Pair<?,?>>();
|
||||
valueAndType.add(Pair.of(new BigDecimal("1"), new BigDecimalType()));
|
||||
valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerType()));
|
||||
valueAndType.add(Pair.of(new BigDecimal("1.0"), new BigDecimalAsDoubleType()));
|
||||
valueAndType.add(Pair.of(new BigInteger("2"), new BigIntegerAsLongType()));
|
||||
//valueAndType.add(Pair.of(Boolean.TRUE, new BooleanType()));
|
||||
valueAndType.add(Pair.of(Byte.valueOf((byte)1), new ByteType()));
|
||||
valueAndType.add(Pair.of(new byte[0], new BytesType()));
|
||||
|
||||
@ -13,6 +13,7 @@ public class CUBRIDLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class CUBRIDSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.mysema.query.suites;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import com.mysema.query.*;
|
||||
import com.mysema.query.sql.DB2Templates;
|
||||
import com.mysema.testutil.ExternalDB;
|
||||
|
||||
@Category(ExternalDB.class)
|
||||
public class DB2LiteralsSuiteTest extends AbstractSuite {
|
||||
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
public static class SelectWindowFunctions extends SelectWindowFunctionsBase {}
|
||||
public static class Subqueries extends SubqueriesBase {}
|
||||
public static class Types extends TypesBase {}
|
||||
public static class Union extends UnionBase {}
|
||||
public static class Update extends UpdateBase {}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
Connections.initDB2();
|
||||
Connections.initConfiguration(DB2Templates.builder().newLineToSingleSpace().build());
|
||||
Connections.getConfiguration().setUseLiterals(true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.mysema.query.suites;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import com.mysema.query.*;
|
||||
import com.mysema.query.sql.DB2Templates;
|
||||
import com.mysema.testutil.ExternalDB;
|
||||
|
||||
@Category(ExternalDB.class)
|
||||
public class DB2SuiteTest extends AbstractSuite {
|
||||
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
public static class SelectWindowFunctions extends SelectWindowFunctionsBase {}
|
||||
public static class Subqueries extends SubqueriesBase {}
|
||||
public static class Types extends TypesBase {}
|
||||
public static class Union extends UnionBase {}
|
||||
public static class Update extends UpdateBase {}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
Connections.initDB2();
|
||||
Connections.initConfiguration(DB2Templates.builder().newLineToSingleSpace().build());
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,6 +10,7 @@ public class DerbyLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class DerbySuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class FirebirdLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class FirebirdSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class H2LiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class H2SuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class H2WithQuotingTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class H2WithSchemaTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class HsqldbLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class HsqldbSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class MSSQLLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class MSSQLSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class MySQLWithQuotingTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class OracleLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class OracleSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class OracleWithQuotingTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class SQLiteLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -10,6 +10,7 @@ public class SQLiteSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class TeradataLiteralsSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
@ -13,6 +13,7 @@ public class TeradataSuiteTest extends AbstractSuite {
|
||||
public static class BeanPopulation extends BeanPopulationBase {}
|
||||
public static class Delete extends DeleteBase {}
|
||||
public static class Insert extends InsertBase {}
|
||||
public static class KeywordQuoting extends KeywordQuotingBase {}
|
||||
public static class LikeEscape extends LikeEscapeBase {}
|
||||
public static class Merge extends MergeBase {}
|
||||
public static class Select extends SelectBase {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user