org.hibernate.dialect.SybaseDialect Java Examples

The following examples show how to use org.hibernate.dialect.SybaseDialect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateJpaVendorAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
@Nullable
protected Class<?> determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyTenSevenDialect.class;
		case H2: return H2Dialect.class;
		case HANA: return HANAColumnStoreDialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQL5Dialect.class;
		case ORACLE: return Oracle12cDialect.class;
		case POSTGRESQL: return PostgreSQL95Dialect.class;
		case SQL_SERVER: return SQLServer2012Dialect.class;
		case SYBASE: return SybaseDialect.class;
		default: return null;
	}
}
 
Example #2
Source File: HibernateJpaVendorAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
@Nullable
protected Class<?> determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyTenSevenDialect.class;
		case H2: return H2Dialect.class;
		case HANA: return HANAColumnStoreDialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQL5Dialect.class;
		case ORACLE: return Oracle12cDialect.class;
		case POSTGRESQL: return PostgreSQL95Dialect.class;
		case SQL_SERVER: return SQLServer2012Dialect.class;
		case SYBASE: return SybaseDialect.class;
		default: return null;
	}
}
 
Example #3
Source File: HQLTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testExpressionWithParamInFunction() {
	assertTranslation("from Animal a where abs(a.bodyWeight-:param) < 2.0");
	assertTranslation("from Animal a where abs(:param - a.bodyWeight) < 2.0");
	assertTranslation("from Animal where abs(:x - :y) < 2.0");
	assertTranslation("from Animal where lower(upper(:foo)) like 'f%'");
	if ( ! ( getDialect() instanceof SybaseDialect ) ) {
		// SybaseDialect maps the length function -> len; classic translator does not consider that *when nested*
		assertTranslation("from Animal a where abs(abs(a.bodyWeight - 1.0 + :param) * abs(length('ffobar')-3)) = 3.0");
	}
	if ( !( getDialect() instanceof MySQLDialect || getDialect() instanceof SybaseDialect ) ) {
		assertTranslation("from Animal where lower(upper('foo') || upper(:bar)) like 'f%'");
	}
	if ( getDialect() instanceof PostgreSQLDialect ) {
		return;
	}
	assertTranslation("from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0");
}
 
Example #4
Source File: ASTParserLoadingTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 '123%' or str(an.bodyWeight) like '1.23%'").uniqueResult();
	if ( getDialect() instanceof DB2Dialect ) {
		assertTrue( str.startsWith("1.234") );
	}
	else if ( getDialect() instanceof SQLServerDialect ) {
		// no assertion as SQLServer always returns nulls here; even trying directly against the
		// database, it seems to have problems with str() in the where clause...
	}
	else {
		assertTrue( str.startsWith("123.4") );
	}
	if ( ! ( getDialect() instanceof SybaseDialect ) ) {
		// 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 Oracle9Dialect || 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();
}
 
Example #5
Source File: HQLTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testConcatenation() {
	if ( getDialect() instanceof MySQLDialect || getDialect() instanceof SybaseDialect ) {
		// MySQL uses concat(x, y, z)
		// SQL Server replaces '||' with '+'
		//
		// this is syntax checked in {@link ASTParserLoadingTest#testConcatenation} 
		return;
	}
	assertTranslation("from Human h where h.nickName = '1' || 'ov' || 'tha' || 'few'");
}
 
Example #6
Source File: FooBarTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testScrollableIterator() throws Exception {
	if ( getDialect() instanceof DB2Dialect || getDialect() instanceof OracleDialect || getDialect() instanceof SybaseDialect || getDialect() instanceof HSQLDialect ) {
		Session s = openSession();
		Transaction txn = s.beginTransaction();
		s.save( new Foo() );
		s.save( new Foo() );
		s.save( new Foo() );
		s.save( new Bar() );
		Query query = s.createQuery("select f, f.integer from Foo f");
		assertTrue( query.getReturnTypes().length==2 );
		ScrollableResults iter = query.scroll();
		assertTrue( iter.next() );
		assertTrue( iter.scroll(1) );
		FooProxy f2 = (FooProxy) iter.get()[0];
		assertTrue( f2!=null );
		assertTrue( iter.scroll(-1) );
		Object f1 = iter.get(0);
		iter.next();
		assertTrue( f1!=null && iter.get(0)==f2 );
		iter.getInteger(1);

		assertTrue( !iter.scroll(100) );
		assertTrue( iter.first() );
		assertTrue( iter.scroll(3) );
		Object f4 = iter.get(0);
		assertTrue( f4!=null );
		assertTrue( !iter.next() );
		assertTrue( iter.first() );
		assertTrue( iter.get(0)==f1 );
		assertTrue( iter.last() );
		assertTrue( iter.get(0)==f4 );
		assertTrue( iter.previous() );
		txn.commit();
		s.close();

		s = openSession();
		txn = s.beginTransaction();
		query = s.createQuery("select f, f.integer from Foo f");
		assertTrue( query.getReturnTypes().length==2 );
		iter = query.scroll();
		assertTrue( iter.next() );
		assertTrue( iter.scroll(1) );
		f2 = (FooProxy) iter.get()[0];
		assertTrue( f2!=null );
		assertTrue( f2.getString()!=null  && f2.getComponent().getImportantDates().length > 0 );
		assertTrue( iter.scroll(-1) );
		f1 = iter.get(0);
		iter.next();
		assertTrue( f1!=null && iter.get(0)==f2 );
		iter.getInteger(1);

		assertTrue( !iter.scroll(100) );
		assertTrue( iter.first() );
		assertTrue( iter.scroll(3) );
		f4 = iter.get(0);
		assertTrue( f4!=null );
		assertTrue( !iter.next() );
		assertTrue( iter.first() );
		assertTrue( iter.get(0)==f1 );
		assertTrue( iter.last() );
		assertTrue( iter.get(0)==f4 );
		assertTrue( iter.previous() );
		assertTrue( s.delete("from Foo")==4 );
		s.flush();
		assertTrue( s.find("from java.lang.Object").size()==0 );
		txn.commit();
		s.close();
	}
}
 
Example #7
Source File: TimestampGeneratedValuesWithCachingTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean appliesTo(Dialect dialect) {
	// this test is specific to Sybase/SQLServer as it is testing support
	// for their TIMESTAMP datatype...
	return ( dialect instanceof SybaseDialect );
}
 
Example #8
Source File: SybaseTimestampVersioningTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean appliesTo(Dialect dialect) {
	return dialect instanceof SybaseDialect;
}
 
Example #9
Source File: SybaseCustomSQLTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean appliesTo(Dialect dialect) {
	return ( dialect instanceof SybaseDialect );
}