Skip to content

Commit c154d7e

Browse files
committed
HHH-9930 - Enable mariadb (mysql) database profile
1 parent c00d460 commit c154d7e

File tree

12 files changed

+112
-52
lines changed

12 files changed

+112
-52
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

+30
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,36 @@ public char openQuote() {
277277
return '`';
278278
}
279279

280+
@Override
281+
public boolean canCreateCatalog() {
282+
return true;
283+
}
284+
285+
@Override
286+
public String[] getCreateCatalogCommand(String catalogName) {
287+
return new String[] { "create database " + catalogName };
288+
}
289+
290+
@Override
291+
public String[] getDropCatalogCommand(String catalogName) {
292+
return new String[] { "drop database " + catalogName };
293+
}
294+
295+
@Override
296+
public boolean canCreateSchema() {
297+
return false;
298+
}
299+
300+
@Override
301+
public String[] getCreateSchemaCommand(String schemaName) {
302+
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
303+
}
304+
305+
@Override
306+
public String[] getDropSchemaCommand(String schemaName) {
307+
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
308+
}
309+
280310
@Override
281311
public boolean supportsIfExistsBeforeTableName() {
282312
return true;

hibernate-core/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,22 @@ public void testClearMap() {
177177

178178
s.beginTransaction();
179179

180-
user = (User) s.get( User.class, 1 );
180+
user = s.get( User.class, 1 );
181181
user.userDatas.clear();
182182
s.update( user );
183183
Query q = s.createQuery( "DELETE FROM " + UserData.class.getName() + " d WHERE d.user = :user" );
184184
q.setParameter( "user", user );
185185
q.executeUpdate();
186186

187187
s.getTransaction().commit();
188-
s.clear();
189-
190-
assertEquals( ( (User) s.get( User.class, user.id ) ).userDatas.size(), 0 );
188+
189+
s.getTransaction().begin();
190+
191+
assertEquals( s.get( User.class, user.id ).userDatas.size(), 0 );
191192
assertEquals( s.createQuery( "FROM " + UserData.class.getName() ).list().size(), 0 );
192-
193+
s.createQuery( "delete " + User.class.getName() ).executeUpdate();
194+
195+
s.getTransaction().commit();
193196
s.close();
194197
}
195198

hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ public void testExpressionWithParamInFunction() {
348348
// ...al0_7_.mammal where [abs(cast(1 as float(19))-cast(? as float(19)))=1.0]
349349
return;
350350
}
351+
if ( getDialect() instanceof MySQLDialect ) {
352+
// MySQL dialects are smarter now wrt cast targets. For example, float (as a db type) is not
353+
// valid as a cast target for MySQL. The new parser uses the dialect handling for casts, the old
354+
// parser does not; so the outputs do not match here...
355+
return;
356+
}
351357
assertTranslation("from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0");
352358
}
353359

hibernate-core/src/test/java/org/hibernate/test/hql/fetchAndJoin/Child.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import javax.persistence.Table;
3636

3737
@Entity
38-
@Table(name = "entity1")
38+
@Table(name = "child")
3939
public class Child {
4040
@Id
4141
@GeneratedValue

hibernate-core/src/test/java/org/hibernate/test/hql/fetchAndJoin/GrandChild.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@
2424
package org.hibernate.test.hql.fetchAndJoin;
2525

2626
import javax.persistence.Entity;
27-
import javax.persistence.FetchType;
2827
import javax.persistence.GeneratedValue;
2928
import javax.persistence.Id;
30-
import javax.persistence.JoinColumn;
31-
import javax.persistence.OneToMany;
3229
import javax.persistence.Table;
3330

3431
@Entity
35-
@Table(name = "entity1")
32+
@Table(name = "grandchild")
3633
public class GrandChild {
3734
@Id
3835
@GeneratedValue

hibernate-core/src/test/java/org/hibernate/test/hql/fetchAndJoin/Parent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import javax.persistence.Table;
3636

3737
@Entity
38-
@Table(name = "entity1")
38+
@Table(name = "parent")
3939
public class Parent {
4040
@Id
4141
@GeneratedValue

hibernate-core/src/test/java/org/hibernate/test/hql/fetchAndJoin/ToManyFetchAndJoinTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import org.hibernate.Hibernate;
3333
import org.hibernate.Session;
34+
import org.hibernate.dialect.MySQLDialect;
35+
3436
import org.hibernate.testing.TestForIssue;
3537
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
3638

@@ -73,6 +75,8 @@ public void setupData() {
7375
public void cleanupData() {
7476
Session s = openSession();
7577
s.getTransaction().begin();
78+
s.createQuery( "delete GrandChild" ).executeUpdate();
79+
s.createQuery( "delete Child" ).executeUpdate();
7680
s.createQuery( "delete Parent" ).executeUpdate();
7781
s.getTransaction().commit();
7882
s.close();

hibernate-core/src/test/java/org/hibernate/test/id/PooledHiLoSequenceIdentifierTest.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@
2323
*/
2424
package org.hibernate.test.id;
2525

26-
import javax.persistence.Entity;
27-
import javax.persistence.GeneratedValue;
28-
import javax.persistence.GenerationType;
29-
import javax.persistence.Id;
3026
import java.sql.Connection;
27+
import java.sql.PreparedStatement;
3128
import java.sql.SQLException;
32-
import java.sql.Statement;
3329
import java.util.List;
3430
import java.util.Properties;
35-
36-
import org.jboss.logging.Logger;
31+
import javax.persistence.Entity;
32+
import javax.persistence.GeneratedValue;
33+
import javax.persistence.GenerationType;
34+
import javax.persistence.Id;
3735

3836
import org.hibernate.Session;
3937
import org.hibernate.Transaction;
4038
import org.hibernate.annotations.GenericGenerator;
4139
import org.hibernate.cfg.Configuration;
40+
import org.hibernate.engine.spi.SessionFactoryImplementor;
41+
import org.hibernate.engine.spi.SessionImplementor;
4242
import org.hibernate.jdbc.Work;
4343

44-
import org.junit.Test;
45-
4644
import org.hibernate.testing.TestForIssue;
4745
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
46+
import org.junit.Test;
47+
48+
import org.jboss.logging.Logger;
4849

4950
import static org.junit.Assert.assertEquals;
5051

@@ -75,7 +76,7 @@ public void testSequenceIdentifierGenerator() {
7576

7677
assertEquals( 7, countInsertedRows( s ) );
7778

78-
List<Number> ids = s.createSQLQuery( "SELECT id FROM sequenceIdentifier" ).list();
79+
List<Number> ids = s.createQuery( "SELECT id FROM sequenceIdentifier" ).list();
7980
for ( Number id : ids ) {
8081
log.debug( "Found id: " + id );
8182
}
@@ -128,16 +129,18 @@ public static class SequenceIdentifier {
128129
}
129130

130131
private void insertNewRow(Session session) {
132+
final SessionImplementor si = (SessionImplementor) session;
133+
final SessionFactoryImplementor sfi = si.getFactory();
134+
131135
session.doWork(
132136
new Work() {
133137
@Override
134138
public void execute(Connection connection) throws SQLException {
135-
Statement statement = null;
139+
PreparedStatement statement = null;
136140
try {
137-
statement = connection.createStatement();
138-
statement.executeUpdate(
139-
"INSERT INTO sequenceIdentifier VALUES (NEXT VALUE FOR hibernate_sequence)"
140-
);
141+
statement = connection.prepareStatement( "INSERT INTO sequenceIdentifier VALUES (?)" );
142+
statement.setObject( 1, sfi.getIdentifierGenerator( SequenceIdentifier.class.getName() ).generate( si, null ) );
143+
statement.executeUpdate();
141144
}
142145
finally {
143146
if ( statement != null ) {

hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -2947,11 +2947,17 @@ public void testCollectionOfSelf() throws Exception {
29472947
s = openSession();
29482948
s.beginTransaction();
29492949
s.load( bar, bar.getKey() );
2950+
bar2 = s.load( Bar.class, bar2.getKey() );
29502951
assertTrue( "collection contains self", bar.getAbstracts().size() == 2 && bar.getAbstracts().contains( bar ) );
29512952
assertTrue( "association to self", bar.getFoo()==bar );
2952-
for ( Object o : bar.getAbstracts() ) {
2953-
s.delete( o );
2954-
}
2953+
2954+
// for MySQL :(
2955+
bar.getAbstracts().clear();
2956+
bar.setFoo( null );
2957+
s.flush();
2958+
2959+
s.delete( bar );
2960+
s.delete( bar2 );
29552961
s.getTransaction().commit();
29562962
s.close();
29572963
}

hibernate-core/src/test/java/org/hibernate/test/legacy/MapTest.java

+19-15
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ public void testMap() throws Exception {
3939
s.beginTransaction();
4040
Map map = new HashMap();
4141
map.put("$type$", "TestMap");
42-
map.put("name", "foo");
43-
map.put("address", "bar");
42+
map.put( "name", "foo" );
43+
map.put( "address", "bar" );
4444
Map cmp = new HashMap();
45-
cmp.put( "a", new Integer(1) );
46-
cmp.put( "b", new Float(1.0) );
47-
map.put("cmp", cmp);
48-
s.save(map);
45+
cmp.put( "a", new Integer( 1 ) );
46+
cmp.put( "b", new Float( 1.0 ) );
47+
map.put( "cmp", cmp );
48+
s.save( map );
4949
s.getTransaction().commit();
5050
s.close();
5151

5252
s = openSession();
5353
s.beginTransaction();
5454
map = (Map) s.get( "TestMap", (Serializable) map.get("id") );
55-
assertTrue( map!=null && "foo".equals( map.get("name") ) );
56-
assertTrue( map.get("$type$").equals("TestMap") );
55+
assertTrue( map != null && "foo".equals( map.get( "name" ) ) );
56+
assertTrue( map.get( "$type$" ).equals( "TestMap" ) );
5757

5858
int size = s.createCriteria("TestMap").add( Example.create(map) ).list().size();
59-
assertTrue(size==1);
59+
assertTrue( size == 1 );
6060
s.getTransaction().commit();
6161
s.close();
6262

@@ -67,12 +67,12 @@ public void testMap() throws Exception {
6767
assertTrue( "foo".equals( map.get("name") ) );
6868
assertTrue( "bar".equals( map.get("address") ) );
6969
cmp = (Map) map.get("cmp");
70-
assertTrue( new Integer(1).equals( cmp.get("a") ) && new Float(1.0).equals( cmp.get("b") ) );
71-
assertTrue( null==map.get("parent") );
72-
map.put("name", "foobar");
73-
map.put("parent", map);
70+
assertTrue( new Integer( 1 ).equals( cmp.get( "a" ) ) && new Float( 1.0 ).equals( cmp.get( "b" ) ) );
71+
assertTrue( null == map.get( "parent" ) );
72+
map.put( "name", "foobar" );
73+
map.put( "parent", map );
7474
List bag = (List) map.get("children");
75-
bag.add(map);
75+
bag.add( map );
7676
s.getTransaction().commit();
7777
s.close();
7878

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

97+
// for MySQL :(
98+
map.put( "parent", null );
99+
map.put( "children", null );
100+
s.flush();
97101
s.delete(map);
98102
s.getTransaction().commit();
99103
s.close();

hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,16 @@ public void testSelfManyToOne() throws Exception {
196196
s.save(m);
197197
t.commit();
198198
s.close();
199+
199200
s = openSession();
200201
t = s.beginTransaction();
201202
Iterator i = s.createQuery( "from Master" ).iterate();
202203
m = (Master) i.next();
203204
assertTrue( m.getOtherMaster()==m );
204-
if (getDialect() instanceof HSQLDialect) { m.setOtherMaster(null); s.flush(); }
205+
if ( getDialect() instanceof HSQLDialect || getDialect() instanceof MySQLDialect ) {
206+
m.setOtherMaster(null);
207+
s.flush();
208+
}
205209
s.delete(m);
206210
t.commit();
207211
s.close();
@@ -243,8 +247,11 @@ public void testExample() throws Exception {
243247
m2 = (Master) s.createCriteria(Master.class)
244248
.add( Example.create(m).excludeNone().excludeProperty("bigDecimal") )
245249
.uniqueResult();
246-
assertTrue( null==m2 );
247-
if (getDialect() instanceof HSQLDialect) { m1.setOtherMaster(null); s.flush(); }
250+
assertTrue( null == m2 );
251+
if (getDialect() instanceof HSQLDialect || getDialect() instanceof MySQLDialect) {
252+
m1.setOtherMaster(null);
253+
s.flush();
254+
}
248255
s.delete(m1);
249256
t.commit();
250257
s.close();

hibernate-core/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public void testBoundedLongByteArrayAccess() {
3939

4040
s = openSession();
4141
s.beginTransaction();
42-
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
42+
entity = s.get( LongByteArrayHolder.class, entity.getId() );
4343
assertNull( entity.getLongByteArray() );
4444
entity.setLongByteArray( original );
4545
s.getTransaction().commit();
4646
s.close();
4747

4848
s = openSession();
4949
s.beginTransaction();
50-
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
50+
entity = s.get( LongByteArrayHolder.class, entity.getId() );
5151
Assert.assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
5252
assertEquals( original, entity.getLongByteArray() );
5353
entity.setLongByteArray( changed );
@@ -56,7 +56,7 @@ public void testBoundedLongByteArrayAccess() {
5656

5757
s = openSession();
5858
s.beginTransaction();
59-
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
59+
entity = s.get( LongByteArrayHolder.class, entity.getId() );
6060
Assert.assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
6161
assertEquals( changed, entity.getLongByteArray() );
6262
entity.setLongByteArray( null );
@@ -65,15 +65,15 @@ public void testBoundedLongByteArrayAccess() {
6565

6666
s = openSession();
6767
s.beginTransaction();
68-
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
68+
entity = s.get( LongByteArrayHolder.class, entity.getId() );
6969
assertNull( entity.getLongByteArray() );
7070
entity.setLongByteArray( empty );
7171
s.getTransaction().commit();
7272
s.close();
7373

7474
s = openSession();
7575
s.beginTransaction();
76-
entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
76+
entity = s.get( LongByteArrayHolder.class, entity.getId() );
7777
if ( entity.getLongByteArray() != null ) {
7878
Assert.assertEquals( empty.length, entity.getLongByteArray().length );
7979
assertEquals( empty, entity.getLongByteArray() );

0 commit comments

Comments
 (0)