当前位置: 首页>>代码示例>>Java>>正文


Java MySQLDialect类代码示例

本文整理汇总了Java中org.hibernate.dialect.MySQLDialect的典型用法代码示例。如果您正苦于以下问题:Java MySQLDialect类的具体用法?Java MySQLDialect怎么用?Java MySQLDialect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MySQLDialect类属于org.hibernate.dialect包,在下文中一共展示了MySQLDialect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: determineDatabaseDialectClass

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
/**
 * 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
 */
@SuppressWarnings("deprecation")
protected Class<?> determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyDialect.class;  // DerbyDialect deprecated in 4.x
		case H2: return H2Dialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQLDialect.class;
		case ORACLE: return Oracle9iDialect.class;
		case POSTGRESQL: return PostgreSQLDialect.class;  // PostgreSQLDialect deprecated in 4.x
		case SQL_SERVER: return SQLServerDialect.class;
		case SYBASE: return org.hibernate.dialect.SybaseDialect.class;  // SybaseDialect deprecated in 3.6 but not 4.x
		default: return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HibernateJpaVendorAdapter.java

示例2: testFindSimpleBySQL

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testFindSimpleBySQL() throws Exception {
	if ( getDialect() instanceof MySQLDialect ) return;
	Session session = openSession();
	Category s = new Category();
	s.setName(String.valueOf(nextLong++));
	session.save(s);
	session.flush();

	Query query = session.createSQLQuery("select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s", "category", Category.class);
	List list = query.list();

	assertNotNull(list);
	assertTrue(list.size() > 0);
	assertTrue(list.get(0) instanceof Category);
	session.connection().commit();
	session.close();
	// How do we handle objects with composite id's ? (such as Single)
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:SQLLoaderTest.java

示例3: testFindBySQLSimpleByDiffSessions

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testFindBySQLSimpleByDiffSessions() throws Exception {
	Session session = openSession();
	Category s = new Category();
	s.setName(String.valueOf(nextLong++));
	session.save(s);
	session.flush();
	session.connection().commit();
	session.close();

	if ( getDialect() instanceof MySQLDialect ) return;

	session = openSession();

	Query query = session.createSQLQuery("select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s", "category", Category.class);
	List list = query.list();

	assertNotNull(list);
	assertTrue(list.size() > 0);
	assertTrue(list.get(0) instanceof Category);

	// How do we handle objects that does not have id property (such as Simple ?)
	// How do we handle objects with composite id's ? (such as Single)
	session.connection().commit();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:SQLLoaderTest.java

示例4: testUpdateOnMammal

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testUpdateOnMammal() {
	TestData data = new TestData();
	data.prepare();

	Session s = openSession();
	Transaction t = s.beginTransaction();

	int count = s.createQuery( "update Mammal set description = description" ).executeUpdate();
	assertEquals( "incorrect update count against 'middle' of joined-subclass hierarchy", 2, count );

	count = s.createQuery( "update Mammal set bodyWeight = 25" ).executeUpdate();
	assertEquals( "incorrect update count against 'middle' of joined-subclass hierarchy", 2, count );

	if ( ! ( getDialect() instanceof MySQLDialect ) ) {
		// MySQL does not support (even un-correlated) subqueries against the update-mutating table
		count = s.createQuery( "update Mammal set bodyWeight = ( select max(bodyWeight) from Animal )" ).executeUpdate();
		assertEquals( "incorrect update count against 'middle' of joined-subclass hierarchy", 2, count );
	}

	t.commit();
	s.close();

	data.cleanup();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:25,代码来源:BulkManipulationTest.java

示例5: testExpressionWithParamInFunction

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
/**
 * Copied from {@link HQLTest#testExpressionWithParamInFunction}
 */
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 ) ) {
		// HSQLDB does not like the abs(? - ?) syntax...
		s.createQuery( "from Animal where abs(:x - :y) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
	}
	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();
	s.createQuery( "from Animal where lower(upper('foo') || upper(:bar)) like 'f%'" ).setString( "bar", "xyz" ).list();
	if ( ! ( getDialect() instanceof PostgreSQLDialect || 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();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:ASTParserLoadingTest.java

示例6: testExpressionWithParamInFunction

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
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");
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:18,代码来源:HQLTest.java

示例7: determineDatabaseDialectClass

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
/**
 * 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
 */
protected Class determineDatabaseDialectClass(Database database) {
	switch (database) {
		case DB2: return DB2Dialect.class;
		case DERBY: return DerbyDialect.class;
		case H2: return H2Dialect.class;
		case HSQL: return HSQLDialect.class;
		case INFORMIX: return InformixDialect.class;
		case MYSQL: return MySQLDialect.class;
		case ORACLE: return Oracle9iDialect.class;
		case POSTGRESQL: return PostgreSQLDialect.class;
		case SQL_SERVER: return SQLServerDialect.class;
		case SYBASE: return SybaseDialect.class;
		default: return null;
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:HibernateJpaVendorAdapter.java

示例8: exportDb

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
@Test
public void exportDb() throws Exception
{
    Class dialectClass = dialect.getClass();
    
    if (logger.isDebugEnabled())
    {
        logger.debug("Using dialect class " + dialectClass.getName());
    }
    if (PostgreSQLDialect.class.isAssignableFrom(dialectClass))
    {
        exportTester = new PostgreSQLDialectExportTester(exporter, tx, jdbcTemplate);
    }
    else if (AlfrescoMariaDBDialect.class.isAssignableFrom(dialectClass))
    {
        exportTester = new AlfrescoMariaDBDialectExportTester(exporter, tx, jdbcTemplate);
    }
    else if (MySQLDialect.class.isAssignableFrom(dialectClass))
    {
        exportTester = new MySQLDialectExportTester(exporter, tx, jdbcTemplate);
    }
    
    if (exportTester != null)
    {
        // Run the DBMS specific tests.
        exportTester.runExportTest();
    }
    else
    {
        if (logger.isInfoEnabled())
        {
            logger.info("Unsupported dialect for this test " + dialectClass.getName());
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:ExportDbTest.java

示例9: getEngineDecorator

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public static EngineDecorator getEngineDecorator(String dialect) throws ClassNotFoundException {
	Class<?> dialectClass = Class.forName(dialect);
	if (MySQLDialect.class.isAssignableFrom(dialectClass)) {
		return new MySQLDecorator();
	} else if (PostgreSQL81Dialect.class.isAssignableFrom(dialectClass)) {
		return new PostgreSQLDecorator();
	} else if (Oracle8iDialect.class.isAssignableFrom(dialectClass)) {
		return new OracleDecorator();
	} else if (SQLServerDialect.class.isAssignableFrom(dialectClass)) {
		return new SQLServerDecorator();
	}
	return new NoOpDecorator();

}
 
开发者ID:Devskiller,项目名称:jpa2ddl,代码行数:15,代码来源:EngineDecorator.java

示例10: getProperties

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
@Override
public Properties getProperties() {
    // additional property mainly for hibernate
    Properties prop = new Properties();
    prop.setProperty("hibernate.dialect", MySQLDialect.class.getName());
    prop.setProperty("hibernate.format_sql", "true");
    prop.setProperty("hibernate.hbm2ddl.auto", autoddl);
    return prop;
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:10,代码来源:DefaultPersistenceUnitInfo.java

示例11: toSqlString

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
	if ( criteriaQuery.getFactory().getDialect() instanceof MySQLDialect ) {
		return "not (" + criterion.toSqlString(criteria, criteriaQuery) + ')';
	}
	else {
		return "not " + criterion.toSqlString(criteria, criteriaQuery);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:10,代码来源:NotExpression.java

示例12: testAutoFlush

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testAutoFlush() throws Exception {
	Session s = openSession();
	Transaction txn = s.beginTransaction();
	FooProxy foo = new Foo();
	s.save(foo);
	assertTrue( "autoflush create", s.find("from Foo foo").size()==1 );
	foo.setChar( new Character('X') );
	assertTrue( "autoflush update", s.find("from Foo foo where foo.char='X'").size()==1 );
	txn.commit();
	s.close();

	s = openSession();
	txn = s.beginTransaction();
	foo = (FooProxy) s.load( Foo.class, foo.getKey() );
	//s.update( new Foo(), foo.getKey() );
	//assertTrue( s.find("from Foo foo where not foo.char='X'").size()==1, "autoflush update" );
	if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof PointbaseDialect) )  {
		foo.setBytes( "osama".getBytes() );
		assertTrue( "autoflush collection update", s.find("from Foo foo where 111 in elements(foo.bytes)").size()==1 );
		foo.getBytes()[0] = 69;
		assertTrue( "autoflush collection update", s.find("from Foo foo where 69 in elements(foo.bytes)").size()==1 );
	}
	s.delete(foo);
	assertTrue( "autoflush delete", s.find("from Foo foo").size()==0 );
	txn.commit();
	s.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:28,代码来源:FooBarTest.java

示例13: testCollectionQuery

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testCollectionQuery() throws Exception {
	Session s = openSession();
	Transaction t = s.beginTransaction();
	if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) ) {
		s.iterate("FROM Master m WHERE NOT EXISTS ( FROM m.details d WHERE NOT d.i=5 )");
		s.iterate("FROM Master m WHERE NOT 5 IN ( SELECT d.i FROM m.details AS d )");
	}
	s.iterate("SELECT m FROM Master m JOIN m.details d WHERE d.i=5");
	s.find("SELECT m FROM Master m JOIN m.details d WHERE d.i=5");
	s.find("SELECT m.id FROM Master AS m JOIN m.details AS d WHERE d.i=5");
	t.commit();
	s.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:MasterDetailTest.java

示例14: testPropertyResultSQL

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testPropertyResultSQL() throws HibernateException, SQLException {
	
	if ( getDialect() instanceof MySQLDialect ) return;
		
	Session s = openSession();
	s.delete("from Assignable");
	s.delete("from Category");

	Category c = new Category();
	c.setName("NAME");
	Assignable assn = new Assignable();
	assn.setId("i.d.");
	List l = new ArrayList();
	l.add(c);
	assn.setCategories(l);
	c.setAssignable(assn);
	s.save(assn);
	s.flush();
	s.connection().commit();
	s.close();

	s = openSession();

	Query query = s.getNamedQuery("nonaliasedsql");
	assertNotNull(query);
	List list = query.list();
       assertNotNull(list);
	
	assertTrue(list.get(0) instanceof Category);
	
	s.connection().commit();
	s.close();

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:35,代码来源:SQLLoaderTest.java

示例15: testCompositeKeyPathExpressions

import org.hibernate.dialect.MySQLDialect; //导入依赖的package包/类
public void testCompositeKeyPathExpressions() throws Exception {
	Session s = openSession();
	s.find("select fum1.fo from Fum fum1 where fum1.fo.fum is not null");
	s.find("from Fum fum1 where fum1.fo.fum is not null order by fum1.fo.fum");
	if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof PointbaseDialect) ) {
		s.find("from Fum fum1 where exists elements(fum1.friends)");
		if(!(getDialect() instanceof TimesTenDialect)) { // can't execute because TimesTen can't do subqueries combined with aggreations
			s.find("from Fum fum1 where size(fum1.friends) = 0");
		}
	}
	s.find("select elements(fum1.friends) from Fum fum1");
	s.find("from Fum fum1, fr in elements( fum1.friends )");
	s.connection().commit();
	s.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:16,代码来源:FumTest.java


注:本文中的org.hibernate.dialect.MySQLDialect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。