Skip to content

Commit

Permalink
HHH-9930 - Enable mariadb (mysql) database profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Jul 25, 2015
1 parent c00d460 commit c154d7e
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 52 deletions.
Expand Up @@ -277,6 +277,36 @@ public char openQuote() {
return '`';
}

@Override
public boolean canCreateCatalog() {
return true;
}

@Override
public String[] getCreateCatalogCommand(String catalogName) {
return new String[] { "create database " + catalogName };
}

@Override
public String[] getDropCatalogCommand(String catalogName) {
return new String[] { "drop database " + catalogName };
}

@Override
public boolean canCreateSchema() {
return false;
}

@Override
public String[] getCreateSchemaCommand(String schemaName) {
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
}

@Override
public String[] getDropSchemaCommand(String schemaName) {
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
}

@Override
public boolean supportsIfExistsBeforeTableName() {
return true;
Expand Down
Expand Up @@ -177,19 +177,22 @@ public void testClearMap() {

s.beginTransaction();

user = (User) s.get( User.class, 1 );
user = s.get( User.class, 1 );
user.userDatas.clear();
s.update( user );
Query q = s.createQuery( "DELETE FROM " + UserData.class.getName() + " d WHERE d.user = :user" );
q.setParameter( "user", user );
q.executeUpdate();

s.getTransaction().commit();
s.clear();

assertEquals( ( (User) s.get( User.class, user.id ) ).userDatas.size(), 0 );

s.getTransaction().begin();

assertEquals( s.get( User.class, user.id ).userDatas.size(), 0 );
assertEquals( s.createQuery( "FROM " + UserData.class.getName() ).list().size(), 0 );

s.createQuery( "delete " + User.class.getName() ).executeUpdate();

s.getTransaction().commit();
s.close();
}

Expand Down
Expand Up @@ -348,6 +348,12 @@ public void testExpressionWithParamInFunction() {
// ...al0_7_.mammal where [abs(cast(1 as float(19))-cast(? as float(19)))=1.0]
return;
}
if ( getDialect() instanceof MySQLDialect ) {
// MySQL dialects are smarter now wrt cast targets. For example, float (as a db type) is not
// valid as a cast target for MySQL. The new parser uses the dialect handling for casts, the old
// parser does not; so the outputs do not match here...
return;
}
assertTranslation("from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0");
}

Expand Down
Expand Up @@ -35,7 +35,7 @@
import javax.persistence.Table;

@Entity
@Table(name = "entity1")
@Table(name = "child")
public class Child {
@Id
@GeneratedValue
Expand Down
Expand Up @@ -24,15 +24,12 @@
package org.hibernate.test.hql.fetchAndJoin;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "entity1")
@Table(name = "grandchild")
public class GrandChild {
@Id
@GeneratedValue
Expand Down
Expand Up @@ -35,7 +35,7 @@
import javax.persistence.Table;

@Entity
@Table(name = "entity1")
@Table(name = "parent")
public class Parent {
@Id
@GeneratedValue
Expand Down
Expand Up @@ -31,6 +31,8 @@

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.dialect.MySQLDialect;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

Expand Down Expand Up @@ -73,6 +75,8 @@ public void setupData() {
public void cleanupData() {
Session s = openSession();
s.getTransaction().begin();
s.createQuery( "delete GrandChild" ).executeUpdate();
s.createQuery( "delete Child" ).executeUpdate();
s.createQuery( "delete Parent" ).executeUpdate();
s.getTransaction().commit();
s.close();
Expand Down
Expand Up @@ -23,28 +23,29 @@
*/
package org.hibernate.test.id;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;

import org.jboss.logging.Logger;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jdbc.Work;

import org.junit.Test;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;

import org.jboss.logging.Logger;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -75,7 +76,7 @@ public void testSequenceIdentifierGenerator() {

assertEquals( 7, countInsertedRows( s ) );

List<Number> ids = s.createSQLQuery( "SELECT id FROM sequenceIdentifier" ).list();
List<Number> ids = s.createQuery( "SELECT id FROM sequenceIdentifier" ).list();
for ( Number id : ids ) {
log.debug( "Found id: " + id );
}
Expand Down Expand Up @@ -128,16 +129,18 @@ public static class SequenceIdentifier {
}

private void insertNewRow(Session session) {
final SessionImplementor si = (SessionImplementor) session;
final SessionFactoryImplementor sfi = si.getFactory();

session.doWork(
new Work() {
@Override
public void execute(Connection connection) throws SQLException {
Statement statement = null;
PreparedStatement statement = null;
try {
statement = connection.createStatement();
statement.executeUpdate(
"INSERT INTO sequenceIdentifier VALUES (NEXT VALUE FOR hibernate_sequence)"
);
statement = connection.prepareStatement( "INSERT INTO sequenceIdentifier VALUES (?)" );
statement.setObject( 1, sfi.getIdentifierGenerator( SequenceIdentifier.class.getName() ).generate( si, null ) );
statement.executeUpdate();
}
finally {
if ( statement != null ) {
Expand Down
Expand Up @@ -2947,11 +2947,17 @@ public void testCollectionOfSelf() throws Exception {
s = openSession();
s.beginTransaction();
s.load( bar, bar.getKey() );
bar2 = s.load( Bar.class, bar2.getKey() );
assertTrue( "collection contains self", bar.getAbstracts().size() == 2 && bar.getAbstracts().contains( bar ) );
assertTrue( "association to self", bar.getFoo()==bar );
for ( Object o : bar.getAbstracts() ) {
s.delete( o );
}

// for MySQL :(
bar.getAbstracts().clear();
bar.setFoo( null );
s.flush();

s.delete( bar );
s.delete( bar2 );
s.getTransaction().commit();
s.close();
}
Expand Down
34 changes: 19 additions & 15 deletions hibernate-core/src/test/java/org/hibernate/test/legacy/MapTest.java
Expand Up @@ -39,24 +39,24 @@ public void testMap() throws Exception {
s.beginTransaction();
Map map = new HashMap();
map.put("$type$", "TestMap");
map.put("name", "foo");
map.put("address", "bar");
map.put( "name", "foo" );
map.put( "address", "bar" );
Map cmp = new HashMap();
cmp.put( "a", new Integer(1) );
cmp.put( "b", new Float(1.0) );
map.put("cmp", cmp);
s.save(map);
cmp.put( "a", new Integer( 1 ) );
cmp.put( "b", new Float( 1.0 ) );
map.put( "cmp", cmp );
s.save( map );
s.getTransaction().commit();
s.close();

s = openSession();
s.beginTransaction();
map = (Map) s.get( "TestMap", (Serializable) map.get("id") );
assertTrue( map!=null && "foo".equals( map.get("name") ) );
assertTrue( map.get("$type$").equals("TestMap") );
assertTrue( map != null && "foo".equals( map.get( "name" ) ) );
assertTrue( map.get( "$type$" ).equals( "TestMap" ) );

int size = s.createCriteria("TestMap").add( Example.create(map) ).list().size();
assertTrue(size==1);
assertTrue( size == 1 );
s.getTransaction().commit();
s.close();

Expand All @@ -67,12 +67,12 @@ public void testMap() throws Exception {
assertTrue( "foo".equals( map.get("name") ) );
assertTrue( "bar".equals( map.get("address") ) );
cmp = (Map) map.get("cmp");
assertTrue( new Integer(1).equals( cmp.get("a") ) && new Float(1.0).equals( cmp.get("b") ) );
assertTrue( null==map.get("parent") );
map.put("name", "foobar");
map.put("parent", map);
assertTrue( new Integer( 1 ).equals( cmp.get( "a" ) ) && new Float( 1.0 ).equals( cmp.get( "b" ) ) );
assertTrue( null == map.get( "parent" ) );
map.put( "name", "foobar" );
map.put( "parent", map );
List bag = (List) map.get("children");
bag.add(map);
bag.add( map );
s.getTransaction().commit();
s.close();

Expand All @@ -92,8 +92,12 @@ public void testMap() throws Exception {
.add( Restrictions.eq("name", "foobar") )
.list()
.size();
assertTrue(size==1);
assertTrue( size == 1 );

// for MySQL :(
map.put( "parent", null );
map.put( "children", null );
s.flush();
s.delete(map);
s.getTransaction().commit();
s.close();
Expand Down
Expand Up @@ -196,12 +196,16 @@ public void testSelfManyToOne() throws Exception {
s.save(m);
t.commit();
s.close();

s = openSession();
t = s.beginTransaction();
Iterator i = s.createQuery( "from Master" ).iterate();
m = (Master) i.next();
assertTrue( m.getOtherMaster()==m );
if (getDialect() instanceof HSQLDialect) { m.setOtherMaster(null); s.flush(); }
if ( getDialect() instanceof HSQLDialect || getDialect() instanceof MySQLDialect ) {
m.setOtherMaster(null);
s.flush();
}
s.delete(m);
t.commit();
s.close();
Expand Down Expand Up @@ -243,8 +247,11 @@ public void testExample() throws Exception {
m2 = (Master) s.createCriteria(Master.class)
.add( Example.create(m).excludeNone().excludeProperty("bigDecimal") )
.uniqueResult();
assertTrue( null==m2 );
if (getDialect() instanceof HSQLDialect) { m1.setOtherMaster(null); s.flush(); }
assertTrue( null == m2 );
if (getDialect() instanceof HSQLDialect || getDialect() instanceof MySQLDialect) {
m1.setOtherMaster(null);
s.flush();
}
s.delete(m1);
t.commit();
s.close();
Expand Down
Expand Up @@ -39,15 +39,15 @@ public void testBoundedLongByteArrayAccess() {

s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
entity = s.get( LongByteArrayHolder.class, entity.getId() );
assertNull( entity.getLongByteArray() );
entity.setLongByteArray( original );
s.getTransaction().commit();
s.close();

s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
entity = s.get( LongByteArrayHolder.class, entity.getId() );
Assert.assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
assertEquals( original, entity.getLongByteArray() );
entity.setLongByteArray( changed );
Expand All @@ -56,7 +56,7 @@ public void testBoundedLongByteArrayAccess() {

s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
entity = s.get( LongByteArrayHolder.class, entity.getId() );
Assert.assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
assertEquals( changed, entity.getLongByteArray() );
entity.setLongByteArray( null );
Expand All @@ -65,15 +65,15 @@ public void testBoundedLongByteArrayAccess() {

s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
entity = s.get( LongByteArrayHolder.class, entity.getId() );
assertNull( entity.getLongByteArray() );
entity.setLongByteArray( empty );
s.getTransaction().commit();
s.close();

s = openSession();
s.beginTransaction();
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
entity = s.get( LongByteArrayHolder.class, entity.getId() );
if ( entity.getLongByteArray() != null ) {
Assert.assertEquals( empty.length, entity.getLongByteArray().length );
assertEquals( empty, entity.getLongByteArray() );
Expand Down

0 comments on commit c154d7e

Please sign in to comment.