mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Merge pull request #1622 from querydsl/dialect-support
Extend Hibernate dialects
This commit is contained in:
commit
4b0152fa71
@ -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));
|
||||
|
||||
@ -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<Class<?>, Type> NUMERIC_TYPES;
|
||||
private static final Map<Class<?>, Type> TYPES;
|
||||
|
||||
static {
|
||||
ImmutableMap.Builder<Class<?>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String, SQLFunction> createFunctions(SQLTemplates templates) {
|
||||
Map<String, SQLFunction> 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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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'))"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -12,7 +12,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.ExtendedDerbyDialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QDerbyDialect" />
|
||||
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:derby:target/derbydb-hibernate;create=true" />
|
||||
<!-- <property name="hibernate.show_sql" value="true"/> -->
|
||||
@ -49,7 +49,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.ExtendedHSQLDialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QHSQLDialect" />
|
||||
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:target/testdb-hibernate;shutdown=true" />
|
||||
<property name="hibernate.connection.user" value="sa" />
|
||||
@ -78,7 +78,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QH2Dialect" />
|
||||
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:h2:./target/h2-hibernate" />
|
||||
<property name="hibernate.connection.user" value="sa" />
|
||||
@ -92,7 +92,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QH2Dialect" />
|
||||
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:h2:./target/h2-hibernate-perf" />
|
||||
<property name="hibernate.connection.user" value="sa" />
|
||||
@ -203,7 +203,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QMySQL5InnoDBDialect" />
|
||||
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/querydsl" />
|
||||
<property name="hibernate.connection.username" value="querydsl" />
|
||||
@ -234,7 +234,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QSQLServer2008Dialect" />
|
||||
<property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://localhost:1433/querydsl" />
|
||||
<property name="hibernate.connection.username" value="querydsl" />
|
||||
@ -251,7 +251,7 @@
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<properties>
|
||||
<property name="hibernate.archive.autodetection" value="class" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
|
||||
<property name="hibernate.dialect" value="com.querydsl.jpa.support.QPostgreSQL9Dialect" />
|
||||
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
|
||||
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/querydsl" />
|
||||
<property name="hibernate.connection.username" value="querydsl" />
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user