use of org.hibernate.dialect.PostgreSQL81Dialect in project hibernate-orm by hibernate.
the class IlikeExpression method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
final Dialect dialect = criteriaQuery.getFactory().getDialect();
final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
if (columns.length != 1) {
throw new HibernateException("ilike may only be used with single-column properties");
}
if (dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) {
return columns[0] + " ilike ?";
} else {
return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
}
}
use of org.hibernate.dialect.PostgreSQL81Dialect in project hibernate-orm by hibernate.
the class StandardDialectResolver method resolveDialect.
@Override
public Dialect resolveDialect(DialectResolutionInfo info) {
final String databaseName = info.getDatabaseName();
if ("CUBRID".equalsIgnoreCase(databaseName)) {
return new CUBRIDDialect();
}
if ("HSQL Database Engine".equals(databaseName)) {
return new HSQLDialect();
}
if ("H2".equals(databaseName)) {
return new H2Dialect();
}
if ("MySQL".equals(databaseName)) {
final int majorVersion = info.getDatabaseMajorVersion();
if (majorVersion >= 5) {
return new MySQL5Dialect();
}
return new MySQLDialect();
}
if ("PostgreSQL".equals(databaseName)) {
final int majorVersion = info.getDatabaseMajorVersion();
final int minorVersion = info.getDatabaseMinorVersion();
if (majorVersion == 9) {
if (minorVersion >= 4) {
return new PostgreSQL94Dialect();
} else if (minorVersion >= 2) {
return new PostgreSQL92Dialect();
}
return new PostgreSQL9Dialect();
}
if (majorVersion == 8 && minorVersion >= 2) {
return new PostgreSQL82Dialect();
}
return new PostgreSQL81Dialect();
}
if ("EnterpriseDB".equals(databaseName)) {
return new PostgresPlusDialect();
}
if ("Apache Derby".equals(databaseName)) {
final int majorVersion = info.getDatabaseMajorVersion();
final int minorVersion = info.getDatabaseMinorVersion();
if (majorVersion > 10 || (majorVersion == 10 && minorVersion >= 7)) {
return new DerbyTenSevenDialect();
} else if (majorVersion == 10 && minorVersion == 6) {
return new DerbyTenSixDialect();
} else if (majorVersion == 10 && minorVersion == 5) {
return new DerbyTenFiveDialect();
} else {
return new DerbyDialect();
}
}
if ("ingres".equalsIgnoreCase(databaseName)) {
final int majorVersion = info.getDatabaseMajorVersion();
final int minorVersion = info.getDatabaseMinorVersion();
switch(majorVersion) {
case 9:
if (minorVersion > 2) {
return new Ingres9Dialect();
}
return new IngresDialect();
case 10:
return new Ingres10Dialect();
default:
LOG.unknownIngresVersion(majorVersion);
}
return new IngresDialect();
}
if (databaseName.startsWith("Microsoft SQL Server")) {
final int majorVersion = info.getDatabaseMajorVersion();
switch(majorVersion) {
case 8:
{
return new SQLServerDialect();
}
case 9:
{
return new SQLServer2005Dialect();
}
case 10:
{
return new SQLServer2008Dialect();
}
case 11:
case 12:
case 13:
{
return new SQLServer2012Dialect();
}
default:
{
if (majorVersion < 8) {
LOG.unknownSqlServerVersion(majorVersion, SQLServerDialect.class);
return new SQLServerDialect();
} else {
// assume `majorVersion > 13`
LOG.unknownSqlServerVersion(majorVersion, SQLServer2012Dialect.class);
return new SQLServer2012Dialect();
}
}
}
}
if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server Enterprise".equals(databaseName)) {
return new SybaseASE15Dialect();
}
if (databaseName.startsWith("Adaptive Server Anywhere")) {
return new SybaseAnywhereDialect();
}
if ("Informix Dynamic Server".equals(databaseName)) {
return new InformixDialect();
}
if ("DB2 UDB for AS/400".equals(databaseName)) {
return new DB2400Dialect();
}
if (databaseName.startsWith("DB2/")) {
return new DB2Dialect();
}
if ("Oracle".equals(databaseName)) {
final int majorVersion = info.getDatabaseMajorVersion();
switch(majorVersion) {
case 12:
return new Oracle12cDialect();
case 11:
// fall through
case 10:
return new Oracle10gDialect();
case 9:
return new Oracle9iDialect();
case 8:
return new Oracle8iDialect();
default:
LOG.unknownOracleVersion(majorVersion);
}
return new Oracle8iDialect();
}
if ("HDB".equals(databaseName)) {
// SAP recommends defaulting to column store.
return new HANAColumnStoreDialect();
}
if (databaseName.startsWith("Firebird")) {
return new FirebirdDialect();
}
return null;
}
use of org.hibernate.dialect.PostgreSQL81Dialect in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testExpressionWithParamInFunction.
@Test
public void testExpressionWithParamInFunction() {
Session s = openSession();
s.beginTransaction();
s.createQuery("from Animal a where abs(a.bodyWeight-:param) < 2.0").setLong("param", 1).list();
s.createQuery("from Animal a where abs(:param - a.bodyWeight) < 2.0").setLong("param", 1).list();
if ((getDialect() instanceof HSQLDialect) || (getDialect() instanceof DB2Dialect)) {
// HSQLDB and DB2 don't like the abs(? - ?) syntax. bit work if at least one parameter is typed...
s.createQuery("from Animal where abs(cast(:x as long) - :y) < 2.0").setLong("x", 1).setLong("y", 1).list();
s.createQuery("from Animal where abs(:x - cast(:y as long)) < 2.0").setLong("x", 1).setLong("y", 1).list();
s.createQuery("from Animal where abs(cast(:x as long) - cast(:y as long)) < 2.0").setLong("x", 1).setLong("y", 1).list();
} else {
s.createQuery("from Animal where abs(:x - :y) < 2.0").setLong("x", 1).setLong("y", 1).list();
}
if (getDialect() instanceof DB2Dialect) {
s.createQuery("from Animal where lower(upper(cast(:foo as string))) like 'f%'").setString("foo", "foo").list();
} else {
s.createQuery("from Animal where lower(upper(:foo)) like 'f%'").setString("foo", "foo").list();
}
s.createQuery("from Animal a where abs(abs(a.bodyWeight - 1.0 + :param) * abs(length('ffobar')-3)) = 3.0").setLong("param", 1).list();
if (getDialect() instanceof DB2Dialect) {
s.createQuery("from Animal where lower(upper('foo') || upper(cast(:bar as string))) like 'f%'").setString("bar", "xyz").list();
} else {
s.createQuery("from Animal where lower(upper('foo') || upper(:bar)) like 'f%'").setString("bar", "xyz").list();
}
if (getDialect() instanceof AbstractHANADialect) {
s.createQuery("from Animal where abs(cast(1 as double) - cast(:param as double)) = 1.0").setLong("param", 1).list();
} else if (!(getDialect() instanceof PostgreSQLDialect || getDialect() instanceof PostgreSQL81Dialect || getDialect() instanceof MySQLDialect)) {
s.createQuery("from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0").setLong("param", 1).list();
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.dialect.PostgreSQL81Dialect in project hibernate-orm by hibernate.
the class SimpleNationalizedTest method simpleNationalizedTest.
@Test
public void simpleNationalizedTest() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(NationalizedEntity.class);
final Metadata metadata = ms.buildMetadata();
PersistentClass pc = metadata.getEntityBinding(NationalizedEntity.class.getName());
assertNotNull(pc);
Property prop = pc.getProperty("nvarcharAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(StringType.INSTANCE, prop.getType());
} else {
assertSame(StringNVarcharType.INSTANCE, prop.getType());
}
prop = pc.getProperty("materializedNclobAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(MaterializedClobType.INSTANCE, prop.getType());
} else {
assertSame(MaterializedNClobType.INSTANCE, prop.getType());
}
prop = pc.getProperty("nclobAtt");
assertSame(NClobType.INSTANCE, prop.getType());
prop = pc.getProperty("nlongvarcharcharAtt");
assertSame(NTextType.INSTANCE, prop.getType());
prop = pc.getProperty("ncharArrAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(CharacterArrayType.INSTANCE, prop.getType());
} else {
assertSame(StringNVarcharType.INSTANCE, prop.getType());
}
prop = pc.getProperty("ncharacterAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(CharacterType.INSTANCE, prop.getType());
} else {
assertSame(CharacterNCharType.INSTANCE, prop.getType());
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.dialect.PostgreSQL81Dialect in project hibernate-orm by hibernate.
the class AndNationalizedTests method basicTest.
@Test
@TestForIssue(jiraKey = "HHH-9599")
public void basicTest() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
((MetadataImpl) metadata).validate();
final PersistentClass entityBinding = metadata.getEntityBinding(TestEntity.class.getName());
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertEquals(Types.VARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
} else {
assertEquals(Types.NVARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations