use of org.hibernate.dialect.SybaseASE15Dialect 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.SybaseASE15Dialect in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testStr.
@Test
public void testStr() {
Session session = openSession();
Transaction txn = session.beginTransaction();
Animal an = new Animal();
an.setBodyWeight(123.45f);
session.persist(an);
String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '%1%'").uniqueResult();
if ((getDialect() instanceof DB2Dialect || getDialect() instanceof TeradataDialect) && !(getDialect() instanceof DerbyDialect)) {
assertTrue(str.startsWith("1.234"));
} else //noinspection deprecation
if (getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof SQLServerDialect) {
// str(val) on sybase assumes a default of 10 characters with no decimal point or decimal values
// str(val) on sybase result is right-justified
assertEquals(str.length(), 10);
assertTrue(str.endsWith("123"));
str = (String) session.createQuery("select str(an.bodyWeight, 8, 3) from Animal an where str(an.bodyWeight, 8, 3) like '%1%'").uniqueResult();
assertEquals(str.length(), 8);
assertTrue(str.endsWith("123.450"));
} else {
assertTrue(str.startsWith("123.4"));
}
//noinspection deprecation
if (!(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof Sybase11Dialect) && !(getDialect() instanceof SybaseASE15Dialect) && !(getDialect() instanceof SybaseAnywhereDialect) && !(getDialect() instanceof SQLServerDialect || getDialect() instanceof TeradataDialect)) {
// In TransactSQL (the variant spoken by Sybase and SQLServer), the str() function
// is explicitly intended for numeric values only...
String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
System.out.println(dateStr1 + '=' + dateStr2);
if (!(getDialect() instanceof Oracle8iDialect)) {
//Oracle renders the name of the month :(
String[] dp1 = StringHelper.split("-", dateStr1);
String[] dp2 = StringHelper.split("-", dateStr2);
for (int i = 0; i < 3; i++) {
if (dp1[i].startsWith("0")) {
dp1[i] = dp1[i].substring(1);
}
assertEquals(dp1[i], dp2[i]);
}
}
}
session.delete(an);
txn.commit();
session.close();
}
use of org.hibernate.dialect.SybaseASE15Dialect in project hibernate-orm by hibernate.
the class SQLFunctionsTest method testBlobClob.
@Test
public void testBlobClob() throws Exception {
// Sybase does not support ResultSet.getBlob(String)
if (getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof TeradataDialect) {
return;
}
Session s = openSession();
s.beginTransaction();
Blobber b = new Blobber();
b.setBlob(s.getLobHelper().createBlob("foo/bar/baz".getBytes()));
b.setClob(s.getLobHelper().createClob("foo/bar/baz"));
s.save(b);
//s.refresh(b);
//assertTrue( b.getClob() instanceof ClobImpl );
s.flush();
s.refresh(b);
//b.getBlob().setBytes( 2, "abc".getBytes() );
b.getClob().getSubString(2, 3);
//b.getClob().setString(2, "abc");
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
Blobber b2 = new Blobber();
s.save(b2);
b2.setBlob(b.getBlob());
b.setBlob(null);
//assertTrue( b.getClob().getSubString(1, 3).equals("fab") );
b.getClob().getSubString(1, 6);
//b.getClob().setString(1, "qwerty");
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
b.setClob(s.getLobHelper().createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb"));
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
b = (Blobber) s.load(Blobber.class, new Integer(b.getId()));
assertTrue(b.getClob().getSubString(1, 7).equals("xcvfxvc"));
//b.getClob().setString(5, "1234567890");
s.flush();
s.getTransaction().commit();
s.close();
}
use of org.hibernate.dialect.SybaseASE15Dialect in project hibernate-orm by hibernate.
the class ComponentTest method testComponentQueries.
@Test
public void testComponentQueries() {
Session s = openSession();
Transaction t = s.beginTransaction();
Employee emp = new Employee();
emp.setHireDate(new Date());
emp.setPerson(new Person());
emp.getPerson().setName("steve");
emp.getPerson().setDob(new Date());
s.save(emp);
s.createQuery("from Employee e where e.person = :p and 1 = 1 and 2=2").setParameter("p", emp.getPerson()).list();
s.createQuery("from Employee e where :p = e.person").setParameter("p", emp.getPerson()).list();
// is fixed, the check for SybaseASE15Dialect should be removed.
if (!(getDialect() instanceof SybaseASE15Dialect)) {
s.createQuery("from Employee e where e.person = ('steve', current_timestamp)").list();
}
s.delete(emp);
t.commit();
s.close();
}
use of org.hibernate.dialect.SybaseASE15Dialect in project hibernate-orm by hibernate.
the class FooBarTest method testCollectionsInSelect.
@Test
public void testCollectionsInSelect() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Foo[] foos = new Foo[] { null, new Foo() };
s.save(foos[1]);
Baz baz = new Baz();
baz.setDefaults();
baz.setFooArray(foos);
s.save(baz);
Baz baz2 = new Baz();
baz2.setDefaults();
s.save(baz2);
Bar bar = new Bar();
bar.setBaz(baz);
s.save(bar);
List list = s.createQuery("select new Result(foo.string, foo.long, foo.integer) from Foo foo").list();
assertTrue(list.size() == 2 && (list.get(0) instanceof Result) && (list.get(1) instanceof Result));
/*list = s.find("select new Result( baz.name, foo.long, count(elements(baz.fooArray)) ) from Baz baz join baz.fooArray foo group by baz.name, foo.long");
assertTrue( list.size()==1 && ( list.get(0) instanceof Result ) );
Result r = ((Result) list.get(0) );
assertEquals( r.getName(), baz.getName() );
assertEquals( r.getCount(), 1 );
assertEquals( r.getAmount(), foos[1].getLong().longValue() );*/
list = s.createQuery("select new Result( baz.name, max(foo.long), count(foo) ) from Baz baz join baz.fooArray foo group by baz.name").list();
assertTrue(list.size() == 1 && (list.get(0) instanceof Result));
Result r = ((Result) list.get(0));
assertEquals(r.getName(), baz.getName());
assertEquals(r.getCount(), 1);
assertTrue(r.getAmount() > 696969696969696000l);
//The following test is disabled for databases with no subselects...also for Interbase (not sure why).
if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && /*&& !(dialect instanceof MckoiDialect)*/
!(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect)) {
s.createQuery("select count(*) from Baz as baz where 1 in indices(baz.fooArray)").list();
s.createQuery("select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)").list();
s.createQuery("select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)").list();
if (!(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle8iDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof Sybase11Dialect) && !(getDialect() instanceof SybaseASE15Dialect) && !(getDialect() instanceof PostgreSQLDialect) && !(getDialect() instanceof PostgreSQL81Dialect) && !(getDialect() instanceof AbstractHANADialect)) {
// SybaseAnywhereDialect supports implicit conversions from strings to ints
s.createQuery("select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)").list();
s.createQuery("select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)").list();
}
s.createQuery("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')").list();
s.createQuery("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')").list();
s.createQuery("select count(*) from Bar as bar left outer join bar.component.glarch.proxyArray as pg where '1' in (from bar.component.glarch.proxyArray)").list();
}
list = s.createQuery("from Baz baz left join baz.fooToGlarch join fetch baz.fooArray foo left join fetch foo.foo").list();
assertTrue(list.size() == 1 && ((Object[]) list.get(0)).length == 2);
s.createQuery("select baz.name from Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("SELECT baz.name FROM Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string").list();
if (!(getDialect() instanceof HSQLDialect))
s.createQuery("select baz.name from Bar bar join bar.baz baz left outer join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("select baz.name from Bar bar join bar.baz baz join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("SELECT baz.name FROM Bar AS bar JOIN bar.baz AS baz JOIN baz.fooSet AS foo WHERE baz.name = bar.string").list();
if (!(getDialect() instanceof HSQLDialect)) {
s.createQuery("select baz.name from Bar bar left join bar.baz baz left join baz.fooSet foo where baz.name = bar.string").list();
s.createQuery("select foo.string from Bar bar left join bar.baz.fooSet foo where bar.string = foo.string").list();
}
s.createQuery("select baz.name from Bar bar left join bar.baz baz left join baz.fooArray foo where baz.name = bar.string").list();
s.createQuery("select foo.string from Bar bar left join bar.baz.fooArray foo where bar.string = foo.string").list();
s.createQuery("select bar.string, foo.string from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo where baz.name = 'name'").list();
s.createQuery("select foo from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo").list();
s.createQuery("select foo from Bar bar inner join bar.baz.fooSet as foo").list();
s.createQuery("select bar.string, foo.string from Bar bar join bar.baz as baz join baz.fooSet as foo where baz.name = 'name'").list();
s.createQuery("select foo from Bar bar join bar.baz as baz join baz.fooSet as foo").list();
s.createQuery("select foo from Bar bar join bar.baz.fooSet as foo").list();
assertTrue(s.createQuery("from Bar bar join bar.baz.fooArray foo").list().size() == 1);
assertTrue(s.createQuery("from Bar bar join bar.baz.fooSet foo").list().size() == 0);
assertTrue(s.createQuery("from Bar bar join bar.baz.fooArray foo").list().size() == 1);
s.delete(bar);
if (getDialect() instanceof DB2Dialect || getDialect() instanceof PostgreSQLDialect || getDialect() instanceof PostgreSQL81Dialect) {
s.createQuery("select one from One one join one.manies many group by one order by count(many)").iterate();
s.createQuery("select one from One one join one.manies many group by one having count(many) < 5").iterate();
}
s.createQuery("from One one join one.manies many where one.id = 1 and many.id = 1").list();
s.createQuery("select one.id, elements(one.manies) from One one").iterate();
s.createQuery("select max( elements(one.manies) ) from One one").iterate();
s.createQuery("select one, elements(one.manies) from One one").list();
Iterator iter = s.createQuery("select elements(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertTrue(iter.next() == foos[1] && !iter.hasNext());
list = s.createQuery("select elements(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).list();
assertEquals(1, list.size());
iter = s.createQuery("select indices(baz.fooArray) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertTrue(iter.next().equals(new Integer(1)) && !iter.hasNext());
iter = s.createQuery("select size(baz.stringSet) from Baz baz where baz.id=?").setParameter(0, baz.getCode(), StandardBasicTypes.STRING).iterate();
assertEquals(new Integer(3), iter.next());
s.createQuery("from Foo foo where foo.component.glarch.id is not null").list();
iter = s.createQuery("select baz, size(baz.stringSet), count( distinct elements(baz.stringSet) ), max( elements(baz.stringSet) ) from Baz baz group by baz").iterate();
while (iter.hasNext()) {
Object[] arr = (Object[]) iter.next();
log.info(arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3]);
}
s.delete(baz);
s.delete(baz2);
s.delete(foos[1]);
t.commit();
s.close();
}
Aggregations