Java 类org.hibernate.dialect.MySQLDialect 实例源码
项目:lams
文件:HibernateJpaVendorAdapter.java
/**
* 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;
}
}
项目:spring4-understanding
文件:HibernateJpaVendorAdapter.java
/**
* 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;
}
}
项目:cacheonix-core
文件:SQLLoaderTest.java
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)
}
项目:cacheonix-core
文件:SQLLoaderTest.java
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();
}
项目:cacheonix-core
文件:BulkManipulationTest.java
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();
}
项目:cacheonix-core
文件:ASTParserLoadingTest.java
/**
* 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();
}
项目:cacheonix-core
文件:HQLTest.java
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");
}
项目:class-guard
文件:HibernateJpaVendorAdapter.java
/**
* 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;
}
}
项目:alfresco-repository
文件:ExportDbTest.java
@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());
}
}
}
项目:jpa2ddl
文件:EngineDecorator.java
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();
}
项目:carbon
文件:DefaultPersistenceUnitInfo.java
@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;
}
项目:cacheonix-core
文件:NotExpression.java
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);
}
}
项目:cacheonix-core
文件:FooBarTest.java
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();
}
项目:cacheonix-core
文件:MasterDetailTest.java
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();
}
项目:cacheonix-core
文件:SQLLoaderTest.java
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();
}
项目:cacheonix-core
文件:FumTest.java
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();
}
项目:cacheonix-core
文件:BulkManipulationTest.java
public void testUpdateOnManyToOne() {
Session s = openSession();
Transaction t = s.beginTransaction();
s.createQuery( "update Animal a set a.mother = null where a.id = 2" ).executeUpdate();
if ( ! ( getDialect() instanceof MySQLDialect ) ) {
// MySQL does not support (even un-correlated) subqueries against the update-mutating table
s.createQuery( "update Animal a set a.mother = (from Animal where id = 1) where a.id = 2" ).executeUpdate();
}
t.commit();
s.close();
}
项目:cacheonix-core
文件:BulkManipulationTest.java
public void testUpdateOnAnimal() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction t = s.beginTransaction();
int count = s.createQuery( "update Animal set description = description where description = :desc" )
.setString( "desc", data.frog.getDescription() )
.executeUpdate();
assertEquals( "Incorrect entity-updated count", 1, count );
count = s.createQuery( "update Animal set description = :newDesc where description = :desc" )
.setString( "desc", data.polliwog.getDescription() )
.setString( "newDesc", "Tadpole" )
.executeUpdate();
assertEquals( "Incorrect entity-updated count", 1, count );
Animal tadpole = ( Animal ) s.load( Animal.class, data.polliwog.getId() );
assertEquals( "Update did not take effect", "Tadpole", tadpole.getDescription() );
count = s.createQuery( "update Animal set bodyWeight = bodyWeight + :w1 + :w2" )
.setDouble( "w1", 1 )
.setDouble( "w2", 2 )
.executeUpdate();
assertEquals( "incorrect count on 'complex' update assignment", count, 6 );
if ( ! ( getDialect() instanceof MySQLDialect ) ) {
// MySQL does not support (even un-correlated) subqueries against the update-mutating table
s.createQuery( "update Animal set bodyWeight = ( select max(bodyWeight) from Animal )" )
.executeUpdate();
}
t.commit();
s.close();
data.cleanup();
}
项目:cacheonix-core
文件:ASTParserLoadingTest.java
public void testCast() {
if ( ( getDialect() instanceof MySQLDialect ) || ( getDialect() instanceof DB2Dialect ) ) {
return;
}
Session session = openSession();
Transaction txn = session.beginTransaction();
session.createQuery("from Human h where h.nickName like 'G%'").list();
session.createQuery("from Animal a where cast(a.bodyWeight as string) like '1.%'").list();
session.createQuery("from Animal a where cast(a.bodyWeight as integer) = 1").list();
txn.commit();
session.close();
}
项目:cacheonix-core
文件:HQLTest.java
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'");
}
项目:Portofino
文件:GoogleCloudSQLDatabasePlatform.java
public GoogleCloudSQLDatabasePlatform() {
super(new MySQLDialect(), "jdbc:google:rdbms://<instance-name>/<database>");
try {
DriverManager.registerDriver((Driver) Class.forName("com.google.cloud.sql.Driver").newInstance());
} catch (Exception e) {
logger.debug("The driver to connect to Google Cloud SQL from a non-GAE application was not found", e);
}
}
项目:community-edition-old
文件:ExportDbTest.java
@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 (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());
}
}
}
项目:aerogear-unifiedpush-server
文件:MysqlDialectResolver.java
@Override
public Dialect resolveDialect(DialectResolutionInfo dialectResolutionInfo) {
if ("MySQL".equals(dialectResolutionInfo.getDatabaseName())) {
return dialectResolutionInfo.getDatabaseMajorVersion() >= 5 ? new Mysql5BitBooleanDialect() : new MySQLDialect();
}
return null;
}
项目:unitimes
文件:HibernateUtil.java
public static boolean isMySQL() {
return MySQLDialect.class.isAssignableFrom(getDialect());
}
项目:ERDesignerNG
文件:RepositoryIOTest.java
public void testLoadSaveRepository() throws Exception {
Connection theConnection = createConnection();
Class theHibernateDialect = MySQLDialect.class;
String theModelResource = "/de/erdesignerng/test/io/repository/examplemodel.mxm";
String theNewFile = RepositioryHelper.performRepositorySaveAndLoad(theModelResource, theHibernateDialect,
theConnection);
String theOriginalFile = IOUtils.toString(getClass().getResourceAsStream(theModelResource));
System.out.println(theOriginalFile);
System.out.println(theNewFile);
assertTrue(compareStrings(theOriginalFile, theNewFile));
}
项目:metaworks_framework
文件:DialectHelper.java
public boolean isMySql() {
return getHibernateDialect() instanceof MySQLDialect;
}
项目:cacheonix-core
文件:FooBarTest.java
public void testQueryCollectionOfValues() throws Exception {
Session s = openSession();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
Glarch g = new Glarch();
Serializable gid = s.save(g);
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) /*&& !(dialect instanceof MckoiDialect)*/ && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof TimesTenDialect) ) {
s.filter( baz.getFooArray(), "where size(this.bytes) > 0");
s.filter( baz.getFooArray(), "where 0 in elements(this.bytes)");
}
s.flush();
s.connection().commit();
s.close();
s = openSession();
//s.find("from Baz baz where baz.fooSet.string = 'foo'");
//s.find("from Baz baz where baz.fooArray.string = 'foo'");
//s.find("from Baz baz where baz.fooSet.foo.string = 'foo'");
//s.find("from Baz baz join baz.fooSet.foo foo where foo.string = 'foo'");
s.find("from Baz baz join baz.fooSet foo join foo.foo.foo foo2 where foo2.string = 'foo'");
s.find("from Baz baz join baz.fooArray foo join foo.foo.foo foo2 where foo2.string = 'foo'");
s.find("from Baz baz join baz.stringDateMap date where index(date) = 'foo'");
s.find("from Baz baz join baz.topGlarchez g where index(g) = 'A'");
s.find("select index(g) from Baz baz join baz.topGlarchez g");
assertTrue( s.find("from Baz baz left join baz.stringSet").size()==3 );
baz = (Baz) s.find("from Baz baz join baz.stringSet str where str='foo'").get(0);
assertTrue( !Hibernate.isInitialized( baz.getStringSet() ) );
baz = (Baz) s.find("from Baz baz left join fetch baz.stringSet").get(0);
assertTrue( Hibernate.isInitialized( baz.getStringSet() ) );
assertTrue( s.find("from Baz baz join baz.stringSet string where string='foo'").size()==1 );
assertTrue( s.find("from Baz baz inner join baz.components comp where comp.name='foo'").size()==1 );
//List bss = s.find("select baz, ss from Baz baz inner join baz.stringSet ss");
s.find("from Glarch g inner join g.fooComponents comp where comp.fee is not null");
s.find("from Glarch g inner join g.fooComponents comp join comp.fee fee where fee.count > 0");
s.find("from Glarch g inner join g.fooComponents comp where comp.fee.count is not null");
s.delete(baz);
//s.delete("from Glarch g");
s.delete( s.get(Glarch.class, gid) );
s.flush();
s.connection().commit();
s.close();
}
项目:cacheonix-core
文件:FooBarTest.java
public void testAutoFlushCollections() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
baz.getStringArray()[0] = "bark";
Iterator i = s.iterate("select elements(baz.stringArray) from Baz baz");
boolean found = false;
while ( i.hasNext() ) {
if ( "bark".equals( i.next() ) ) found = true;
}
assertTrue(found);
baz.setStringArray(null);
i = s.iterate("select distinct elements(baz.stringArray) from Baz baz");
assertTrue( !i.hasNext() );
baz.setStringArray( new String[] { "foo", "bar" } );
i = s.iterate("select elements(baz.stringArray) from Baz baz");
assertTrue( i.hasNext() );
Foo foo = new Foo();
s.save(foo);
s.flush();
baz.setFooArray( new Foo[] {foo} );
i = s.iterate("select foo from Baz baz join baz.fooArray foo");
found = false;
while ( i.hasNext() ) {
if ( foo==i.next() ) found = true;
}
assertTrue(found);
baz.getFooArray()[0] = null;
i = s.iterate("select foo from Baz baz join baz.fooArray foo");
assertTrue( !i.hasNext() );
baz.getFooArray()[0] = foo;
i = s.iterate("select elements(baz.fooArray) from Baz baz");
assertTrue( i.hasNext() );
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof SAPDBDialect) ) {
baz.getFooArray()[0] = null;
i = s.iterate(
"from Baz baz where ? in elements(baz.fooArray)",
foo, Hibernate.entity(Foo.class)
);
assertTrue( !i.hasNext() );
baz.getFooArray()[0] = foo;
i = s.iterate(
"select foo from Foo foo where foo in "
+ "(select elt from Baz baz join baz.fooArray elt)"
);
assertTrue( i.hasNext() );
}
s.delete(foo);
s.delete(baz);
tx.commit();
s.close();
}
项目:cacheonix-core
文件:MasterDetailTest.java
public void testCachedCollectionRefresh() throws Exception {
Session s = openSession();
Category c = new Category();
List list = new ArrayList();
c.setSubcategories(list);
list.add( new Category() );
c.setName("root");
Serializable id = s.save(c);
s.flush();
s.connection().commit();
s.close();
s = openSession();
c = (Category) s.load(Category.class, id);
c.getSubcategories().size(); //force load and cache
s.connection().commit();
s.close();
s = openSession();
if ( (getDialect() instanceof MySQLDialect) ) s.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
c = (Category) s.load(Category.class, id);
c.getSubcategories().size(); //force load
Session ss = openSession();
Category c2 = (Category) ss.load(Category.class, id);
ss.delete( c2.getSubcategories().get(0) );
c2.getSubcategories().clear();
ss.flush();
ss.connection().commit();
ss.close();
s.refresh(c);
assertTrue( c.getSubcategories().size()==0 );
ss = openSession();
c2 = (Category) ss.load(Category.class, id);
c2.getSubcategories().add( new Category() );
c2.getSubcategories().add( new Category() );
ss.flush();
ss.connection().commit();
ss.close();
s.refresh(c);
assertEquals( 2, c.getSubcategories().size() );
s.flush();
s.connection().commit();
s.close();
s = openSession();
c = (Category) s.load(Category.class, id);
assertEquals( 2, c.getSubcategories().size() );
s.delete(c);
s.flush();
s.connection().commit();
s.close();
}
项目:cacheonix-core
文件:CustomSQLTest.java
public void testCRUD() throws HibernateException, SQLException {
if ( getDialect() instanceof HSQLDialect ) return;
if ( getDialect() instanceof MySQLDialect ) return;
Person p = new Person();
p.setName("Max");
p.setLastName("Andersen");
p.setNationalID("110974XYZ�");
p.setAddress("P. P. Street 8");
Session s = openSession();
s.save(p);
s.flush();
s.connection().commit();
s.close();
getSessions().evict(Person.class);
s = openSession();
Person p2 = (Person) s.get(Person.class, p.getId());
assertNotSame(p, p2);
assertEquals(p2.getId(),p.getId());
assertEquals(p2.getLastName(),p.getLastName());
s.flush();
List list = s.find("select p from Party as p");
assertTrue(list.size() == 1);
s.connection().commit();
s.close();
s = openSession();
list = s.find("select p from Person as p where p.address = 'L�rkev�nget 1'");
assertTrue(list.size() == 0);
p.setAddress("L�rkev�nget 1");
s.update(p);
list = s.find("select p from Person as p where p.address = 'L�rkev�nget 1'");
assertTrue(list.size() == 1);
list = s.find("select p from Party as p where p.address = 'P. P. Street 8'");
assertTrue(list.size() == 0);
s.delete(p);
list = s.find("select p from Person as p");
assertTrue(list.size() == 0);
s.connection().commit();
s.close();
}
项目:cacheonix-core
文件:SQLLoaderTest.java
public void testFindBySQLAssociatedObjects() throws HibernateException, SQLException {
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();
List list = s.createSQLQuery("select {category.*} from category {category}", "category", Category.class).list();
list.get(0);
s.connection().commit();
s.close();
if ( getDialect() instanceof MySQLDialect ) return;
if ( getDialect() instanceof OracleDialect ) return; // todo : this fails on Oracle8 also
s = openSession();
Query query = s.getNamedQuery("namedsql");
assertNotNull(query);
list = query.list();
assertNotNull(list);
Object[] values = (Object[]) list.get(0);
assertNotNull(values[0]);
assertNotNull(values[1]);
assertTrue("wrong type: " + values[0].getClass(), values[0] instanceof Category);
assertTrue("wrong type: " + values[1].getClass(), values[1] instanceof Assignable);
s.connection().commit();
s.close();
}
项目:cacheonix-core
文件:SQLLoaderTest.java
public void testFindBySQLMultipleObject() throws HibernateException, SQLException {
Session s = openSession();
s.delete("from Assignable");
s.delete("from Category");
s.flush();
s.connection().commit();
s.close();
s = openSession();
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();
c = new Category();
c.setName("NAME2");
assn = new Assignable();
assn.setId("i.d.2");
l = new ArrayList();
l.add(c);
assn.setCategories(l);
c.setAssignable(assn);
s.save(assn);
s.flush();
assn = new Assignable();
assn.setId("i.d.3");
s.save(assn);
s.flush();
s.connection().commit();
s.close();
if ( getDialect() instanceof MySQLDialect ) return;
s = openSession();
List list = s.createSQLQuery("select {category.*}, {assignable.*} from category {category}, \"assign-able\" {assignable}", new String[] { "category", "assignable" }, new Class[] { Category.class, Assignable.class }).list();
assertTrue(list.size() == 6); // crossproduct of 2 categories x 3 assignables
assertTrue(list.get(0) instanceof Object[]);
s.connection().commit();
s.close();
}
项目:cacheonix-core
文件:OnDeleteTest.java
public void testJoinedSubclass() {
if ( ! supportsCircularCascadeDelete() ) {
return;
}
Statistics statistics = getSessions().getStatistics();
statistics.clear();
Session s = openSession();
Transaction t = s.beginTransaction();
Salesperson mark = new Salesperson();
mark.setName("Mark");
mark.setTitle("internal sales");
mark.setSex('M');
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
Person joe = new Person();
joe.setName("Joe");
joe.setAddress("San Francisco");
joe.setZip("XXXXX");
joe.setCountry("USA");
joe.setSex('M');
joe.setSalesperson(mark);
mark.getCustomers().add(joe);
s.save(mark);
t.commit();
assertEquals( statistics.getEntityInsertCount(), 2 );
assertEquals( statistics.getPrepareStatementCount(), 5 );
statistics.clear();
t = s.beginTransaction();
s.delete(mark);
t.commit();
assertEquals( statistics.getEntityDeleteCount(), 2 );
if ( !(getDialect() instanceof MySQLDialect) || (getDialect() instanceof MySQLInnoDBDialect) ) {
assertEquals( statistics.getPrepareStatementCount(), 1 );
}
t = s.beginTransaction();
List names = s.createQuery("select name from Person").list();
assertTrue( names.isEmpty() );
t.commit();
s.close();
}
项目:cacheonix-core
文件:MySQLCustomSQLTest.java
public boolean appliesTo(Dialect dialect) {
return ( dialect instanceof MySQLDialect );
}
项目:SparkCommerce
文件:DialectHelper.java
public boolean isMySql() {
return getHibernateDialect() instanceof MySQLDialect;
}
项目:Portofino
文件:MySql5DatabasePlatform.java
public MySql5DatabasePlatform() {
super(new MySQLDialect(), "jdbc:mysql://<host>[:<port>][/<database>]");
}
项目:blcdemo
文件:DialectHelper.java
public boolean isMySql() {
return getHibernateDialect() instanceof MySQLDialect;
}
项目:unitime
文件:HibernateUtil.java
public static boolean isMySQL() {
return MySQLDialect.class.isAssignableFrom(getDialect());
}
项目:ubrew_v0.1
文件:GameSchemaExportTest.java
@Test
public void export() throws ClassNotFoundException {
export(MySQLDialect.class, "game", localContainerEntityManagerFactoryBean.getPersistenceUnitInfo().getManagedClassNames());
}
项目:ubrew_v0.1
文件:UbrewCoreSchemaExportTest.java
@Test
public void export() throws ClassNotFoundException {
export(MySQLDialect.class, "ubrew", localContainerEntityManagerFactoryBean.getPersistenceUnitInfo().getManagedClassNames());
}