diff --git a/querydsl-core/src/main/java/com/querydsl/core/types/Template.java b/querydsl-core/src/main/java/com/querydsl/core/types/Template.java index 7b84f46ea..5fb578c35 100644 --- a/querydsl-core/src/main/java/com/querydsl/core/types/Template.java +++ b/querydsl-core/src/main/java/com/querydsl/core/types/Template.java @@ -76,6 +76,10 @@ public final class Template implements Serializable { return arg instanceof Constant ? arg.toString() : arg; } + public int getIndex() { + return index; + } + @Override public boolean isString() { return true; @@ -104,6 +108,10 @@ public final class Template implements Serializable { this.toString = "'" + text + "'"; } + public String getText() { + return text; + } + @Override public boolean isString() { return true; @@ -140,6 +148,10 @@ public final class Template implements Serializable { this.toString = String.valueOf(index); } + public int getIndex() { + return index; + } + @Override public Object convert(final List args) { return transformer.apply(args.get(index)); diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java index 38547b650..dd022b61d 100644 --- a/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/hibernate/HibernateUtil.java @@ -16,6 +16,7 @@ package com.querydsl.jpa.hibernate; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; +import java.util.Date; import java.util.Map; import java.util.Set; @@ -43,7 +44,7 @@ public final class HibernateUtil { java.util.Locale.class, java.util.TimeZone.class, java.util.Currency.class, Class.class, java.io.Serializable.class, java.sql.Blob.class, java.sql.Clob.class); - private static final Map, Type> NUMERIC_TYPES; + private static final Map, Type> TYPES; static { ImmutableMap.Builder, Type> builder = ImmutableMap.builder(); @@ -55,7 +56,11 @@ public final class HibernateUtil { builder.put(Double.class, new DoubleType()); builder.put(Float.class, new FloatType()); builder.put(BigDecimal.class, new BigDecimalType()); - NUMERIC_TYPES = builder.build(); + builder.put(String.class, new StringType()); + builder.put(Character.class, new CharacterType()); + builder.put(Date.class, new DateType()); + builder.put(Boolean.class, new BooleanType()); + TYPES = builder.build(); } private HibernateUtil() { } @@ -80,10 +85,14 @@ public final class HibernateUtil { query.setParameterList(key, (Collection) val); } else if (val instanceof Object[] && !BUILT_IN.contains(val.getClass())) { query.setParameterList(key, (Object[]) val); - } else if (NUMERIC_TYPES.containsKey(val.getClass())) { - query.setParameter(key, val, NUMERIC_TYPES.get(val.getClass())); + } else if (val instanceof Number && TYPES.containsKey(val.getClass())) { + query.setParameter(key, val, getType(val.getClass())); } else { query.setParameter(key, val); } } + + public static Type getType(Class clazz) { + return TYPES.get(clazz); + } } diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/DialectSupport.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/DialectSupport.java new file mode 100644 index 000000000..acfc02808 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/DialectSupport.java @@ -0,0 +1,69 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import java.util.Map; + +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.dialect.function.SQLFunctionTemplate; +import org.hibernate.type.Type; + +import com.google.common.collect.Maps; +import com.querydsl.core.types.Operator; +import com.querydsl.core.types.Ops; +import com.querydsl.core.types.Template; +import com.querydsl.jpa.hibernate.HibernateUtil; +import com.querydsl.sql.SQLTemplates; + +final class DialectSupport { + + private DialectSupport() { } + + public static Map createFunctions(SQLTemplates templates) { + Map functions = Maps.newHashMap(); + functions.put("second", createFunction(templates, Ops.DateTimeOps.SECOND)); + functions.put("minute", createFunction(templates, Ops.DateTimeOps.MINUTE)); + functions.put("hour", createFunction(templates, Ops.DateTimeOps.HOUR)); + functions.put("day", createFunction(templates, Ops.DateTimeOps.DAY_OF_MONTH)); + functions.put("week", createFunction(templates, Ops.DateTimeOps.WEEK)); + functions.put("month", createFunction(templates, Ops.DateTimeOps.MONTH)); + functions.put("year", createFunction(templates, Ops.DateTimeOps.YEAR)); + return functions; + } + + public static SQLFunction createFunction(SQLTemplates templates, Operator operator) { + Template template = templates.getTemplate(operator); + Type type = HibernateUtil.getType(operator.getType()); + return new SQLFunctionTemplate(type, convert(template)); + } + + public static String convert(Template template) { + StringBuilder builder = new StringBuilder(); + for (Template.Element element : template.getElements()) { + if (element instanceof Template.AsString) { + builder.append("?").append(((Template.AsString) element).getIndex() + 1); + } else if (element instanceof Template.ByIndex) { + builder.append("?").append(((Template.ByIndex) element).getIndex() + 1); + } else if (element instanceof Template.Transformed) { + builder.append("?").append(((Template.Transformed) element).getIndex() + 1); + } else if (element instanceof Template.StaticText) { + builder.append(((Template.StaticText) element).getText()); + } else { + throw new IllegalStateException("Unsupported element " + element); + } + } + return builder.toString(); + } + +} diff --git a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedDerbyDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java similarity index 74% rename from querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedDerbyDialect.java rename to querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java index ee1193a11..6593ae2df 100644 --- a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedDerbyDialect.java +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java @@ -18,16 +18,17 @@ import java.util.List; import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.function.CastFunction; -import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; +import com.querydsl.core.types.Ops; +import com.querydsl.sql.DerbyTemplates; +import com.querydsl.sql.SQLTemplates; + /** - * @author tiwe - * + * {@code QDerbyDialect} extends {@code DerbyDialect} with additional functions */ -public class ExtendedDerbyDialect extends DerbyDialect { +public class QDerbyDialect extends DerbyDialect { private static final CastFunction castFunction = new CastFunction() { @Override @@ -40,8 +41,10 @@ public class ExtendedDerbyDialect extends DerbyDialect { } }; - public ExtendedDerbyDialect() { - registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "cast ((","||",") as varchar(128))")); + public QDerbyDialect() { + SQLTemplates templates = DerbyTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + registerFunction("concat", DialectSupport.createFunction(templates, Ops.CONCAT)); registerFunction("cast", castFunction); } diff --git a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedHSQLDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QH2Dialect.java similarity index 63% rename from querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedHSQLDialect.java rename to querydsl-jpa/src/main/java/com/querydsl/jpa/support/QH2Dialect.java index 201232df3..69b2a188a 100644 --- a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedHSQLDialect.java +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QH2Dialect.java @@ -13,17 +13,19 @@ */ package com.querydsl.jpa.support; -import org.hibernate.dialect.HSQLDialect; -import org.hibernate.dialect.function.SQLFunctionTemplate; -import org.hibernate.type.StandardBasicTypes; +import org.hibernate.dialect.H2Dialect; + +import com.querydsl.sql.H2Templates; +import com.querydsl.sql.SQLTemplates; /** - * @author tiwe - * + * {@code QH2Dialect} extends {@code H2Dialect} with additional functions */ -public class ExtendedHSQLDialect extends HSQLDialect { +public class QH2Dialect extends H2Dialect { - public ExtendedHSQLDialect() { - registerFunction("trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(both from ?1)")); + public QH2Dialect() { + SQLTemplates templates = H2Templates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); } + } diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QHSQLDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QHSQLDialect.java new file mode 100644 index 000000000..0602a6ff3 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QHSQLDialect.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.HSQLDialect; + +import com.querydsl.core.types.Ops; +import com.querydsl.sql.HSQLDBTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QHSQLDialect} extends {@code HSQLDialect} with additional functions + */ +public class QHSQLDialect extends HSQLDialect { + + public QHSQLDialect() { + SQLTemplates templates = HSQLDBTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + registerFunction("trim", DialectSupport.createFunction(templates, Ops.TRIM)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL57InnoDBDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL57InnoDBDialect.java new file mode 100644 index 000000000..5ed6bdb55 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL57InnoDBDialect.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.MySQL57InnoDBDialect; + +import com.querydsl.sql.MySQLTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QMySQL57InnoDBDialect} extends {@code MySQL57InnoDBDialect} with additional functions + */ +public class QMySQL57InnoDBDialect extends MySQL57InnoDBDialect { + + public QMySQL57InnoDBDialect() { + SQLTemplates templates = MySQLTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5Dialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5Dialect.java new file mode 100644 index 000000000..e1a0b66a2 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5Dialect.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.MySQL5Dialect; + +import com.querydsl.sql.MySQLTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QMySQL5Dialect} extends {@code MySQL5Dialect} with additional functions + */ +public class QMySQL5Dialect extends MySQL5Dialect { + + public QMySQL5Dialect() { + SQLTemplates templates = MySQLTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5InnoDBDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5InnoDBDialect.java new file mode 100644 index 000000000..920228b21 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QMySQL5InnoDBDialect.java @@ -0,0 +1,31 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.MySQL5InnoDBDialect; + +import com.querydsl.sql.MySQLTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QMySQL5InnoDBDialect} extends {@code MySQL5InnoDBDialect} with additional functions + */ +public class QMySQL5InnoDBDialect extends MySQL5InnoDBDialect { + + public QMySQL5InnoDBDialect() { + SQLTemplates templates = MySQLTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } + +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QOracle10gDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QOracle10gDialect.java new file mode 100644 index 000000000..c6eb0793d --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QOracle10gDialect.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.Oracle10gDialect; + +import com.querydsl.sql.OracleTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QOracle10gDialect} extends {@code Oracle10gDialect} with additional functions + */ +public class QOracle10gDialect extends Oracle10gDialect { + + public QOracle10gDialect() { + SQLTemplates templates = OracleTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQL9Dialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQL9Dialect.java new file mode 100644 index 000000000..dbe007531 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQL9Dialect.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.PostgreSQL9Dialect; + +import com.querydsl.sql.PostgreSQLTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QPostgreSQL9Dialect} extends {@code PostgreSQL9Dialect} with additional functions + */ +public class QPostgreSQL9Dialect extends PostgreSQL9Dialect { + + public QPostgreSQL9Dialect() { + SQLTemplates templates = PostgreSQLTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQLDialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQLDialect.java new file mode 100644 index 000000000..1b5ffb8ba --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QPostgreSQLDialect.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.PostgreSQLDialect; + +import com.querydsl.sql.PostgreSQLTemplates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QPostgreSQLDialect} extends {@code PostgreSQLDialect} with additional functions + */ +public class QPostgreSQLDialect extends PostgreSQLDialect { + + public QPostgreSQLDialect() { + SQLTemplates templates = PostgreSQLTemplates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2005Dialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2005Dialect.java new file mode 100644 index 000000000..54c90eae1 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2005Dialect.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.SQLServer2005Dialect; + +import com.querydsl.core.types.Ops; +import com.querydsl.sql.SQLServer2005Templates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QSQLServer2005Dialect} extends {@code SQLServer2005Dialect} with additional functions + */ +public class QSQLServer2005Dialect extends SQLServer2005Dialect { + + public QSQLServer2005Dialect() { + SQLTemplates templates = SQLServer2005Templates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + registerFunction("current_date", + DialectSupport.createFunction(templates, Ops.DateTimeOps.CURRENT_DATE)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2008Dialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2008Dialect.java new file mode 100644 index 000000000..a7f47cf9e --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2008Dialect.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.SQLServer2008Dialect; + +import com.querydsl.core.types.Ops; +import com.querydsl.sql.SQLServer2008Templates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QSQLServer2008Dialect} extends {@code SQLServer2008Dialect} with additional functions + */ +public class QSQLServer2008Dialect extends SQLServer2008Dialect { + + public QSQLServer2008Dialect() { + SQLTemplates templates = SQLServer2008Templates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + registerFunction("current_date", + DialectSupport.createFunction(templates, Ops.DateTimeOps.CURRENT_DATE)); + } +} diff --git a/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2012Dialect.java b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2012Dialect.java new file mode 100644 index 000000000..94e8396b5 --- /dev/null +++ b/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QSQLServer2012Dialect.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team) + * + * 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.querydsl.jpa.support; + +import org.hibernate.dialect.SQLServer2012Dialect; + +import com.querydsl.core.types.Ops; +import com.querydsl.sql.SQLServer2012Templates; +import com.querydsl.sql.SQLTemplates; + +/** + * {@code QSQLServer2012Dialect} extends {@code SQLServer2012Dialect} with additional functions + */ +public class QSQLServer2012Dialect extends SQLServer2012Dialect { + + public QSQLServer2012Dialect() { + SQLTemplates templates = SQLServer2012Templates.DEFAULT; + getFunctions().putAll(DialectSupport.createFunctions(templates)); + registerFunction("current_date", + DialectSupport.createFunction(templates, Ops.DateTimeOps.CURRENT_DATE)); + } +} diff --git a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/DialectSupportTest.java b/querydsl-jpa/src/test/java/com/querydsl/jpa/support/DialectSupportTest.java new file mode 100644 index 000000000..b49558615 --- /dev/null +++ b/querydsl-jpa/src/test/java/com/querydsl/jpa/support/DialectSupportTest.java @@ -0,0 +1,20 @@ +package com.querydsl.jpa.support; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.querydsl.core.types.Ops; +import com.querydsl.core.types.Template; +import com.querydsl.sql.HSQLDBTemplates; + +public class DialectSupportTest { + + @Test + public void Convert() { + Template trim = HSQLDBTemplates.DEFAULT.getTemplate(Ops.TRIM); + assertEquals("trim(both from ?1)", DialectSupport.convert(trim)); + Template concat = HSQLDBTemplates.DEFAULT.getTemplate(Ops.CONCAT); + assertEquals("?1 || ?2", DialectSupport.convert(concat)); + } +} diff --git a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedOracleDialect.java b/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedOracleDialect.java deleted file mode 100644 index 14d642ffd..000000000 --- a/querydsl-jpa/src/test/java/com/querydsl/jpa/support/ExtendedOracleDialect.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.querydsl.jpa.support; - -import org.hibernate.dialect.Oracle10gDialect; -import org.hibernate.dialect.function.SQLFunctionTemplate; -import org.hibernate.type.StandardBasicTypes; - -/** - * @author tiwe - * - */ -public class ExtendedOracleDialect extends Oracle10gDialect { - - public ExtendedOracleDialect() { - // there fail otherwise with the time datatype - registerFunction("second", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "to_number(to_char(?1,'SS'))")); - registerFunction("minute", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "to_number(to_char(?1,'MI'))")); - registerFunction("hour", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "to_number(to_char(?1,'HH24'))")); - } - -} diff --git a/querydsl-jpa/src/test/resources/META-INF/persistence.xml b/querydsl-jpa/src/test/resources/META-INF/persistence.xml index d7b42ea72..ea7ca76b3 100644 --- a/querydsl-jpa/src/test/resources/META-INF/persistence.xml +++ b/querydsl-jpa/src/test/resources/META-INF/persistence.xml @@ -12,7 +12,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -49,7 +49,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -78,7 +78,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -92,7 +92,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -203,7 +203,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -234,7 +234,7 @@ org.hibernate.ejb.HibernatePersistence - + @@ -251,7 +251,7 @@ org.hibernate.ejb.HibernatePersistence - + diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/derby.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/derby.properties index 434e34d12..aa8240207 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/derby.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/derby.properties @@ -1,6 +1,6 @@ ## Derby #hibernate.dialect=org.hibernate.dialect.DerbyDialect -hibernate.dialect=com.querydsl.jpa.support.ExtendedDerbyDialect +hibernate.dialect=com.querydsl.jpa.support.QDerbyDialect hibernate.connection.driver_class=org.apache.derby.jdbc.EmbeddedDriver hibernate.connection.url=jdbc:derby:target/derbydb;create=true diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/h2.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/h2.properties index dbaee29bb..0d714abb0 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/h2.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/h2.properties @@ -1,4 +1,4 @@ -hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.dialect=com.querydsl.jpa.support.QH2Dialect hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:./target/h2-jpa1 hibernate.connection.username=sa diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/hsqldb.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/hsqldb.properties index f2b58247d..bdc8346e4 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/hsqldb.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/hsqldb.properties @@ -1,6 +1,6 @@ ## HSQL #hibernate.dialect=org.hibernate.dialect.HSQLDialect -hibernate.dialect=com.querydsl.jpa.support.ExtendedHSQLDialect +hibernate.dialect=com.querydsl.jpa.support.QHSQLDialect hibernate.connection.url=jdbc:hsqldb:file:target/testdb;shutdown=true hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.username=sa diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mssql.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mssql.properties index 9ffe1de49..7b148f50a 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mssql.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mssql.properties @@ -1,5 +1,5 @@ ## MSSQL -hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect +hibernate.dialect=com.querydsl.jpa.support.QSQLServer2008Dialect hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver hibernate.connection.url=jdbc:jtds:sqlserver://localhost:1433/querydsl hibernate.connection.username=querydsl diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mysql.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mysql.properties index d261199a5..8f2f5f21b 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mysql.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/mysql.properties @@ -1,5 +1,5 @@ ## MySQL -hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect +hibernate.dialect=com.querydsl.jpa.support.QMySQL5InnoDBDialect hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.connection.url=jdbc:mysql://localhost:3306/querydsl hibernate.connection.username=querydsl diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/oracle.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/oracle.properties index 11964df35..40bfa2511 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/oracle.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/oracle.properties @@ -1,6 +1,6 @@ ## MySQL #hibernate.dialect=org.hibernate.dialect.Oracle10gDialect -hibernate.dialect=com.querydsl.jpa.support.ExtendedOracleDialect +hibernate.dialect=com.querydsl.jpa.support.QOracle10gDialect hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:xe hibernate.connection.username=querydsl diff --git a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/postgresql.properties b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/postgresql.properties index b78843c01..39dcd284c 100644 --- a/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/postgresql.properties +++ b/querydsl-jpa/src/test/resources/com/querydsl/jpa/testutil/postgresql.properties @@ -1,5 +1,5 @@ ## MySQL -hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.dialect=com.querydsl.jpa.support.QPostgreSQL9Dialect hibernate.connection.driver_class=org.postgresql.Driver hibernate.connection.url=jdbc:postgresql://localhost:5432/querydsl hibernate.connection.username=querydsl