Skip to content

Commit 37cc060

Browse files
committed
HHH-9930 - Enable mariadb (mysql) database profile
1 parent 11c7612 commit 37cc060

File tree

8 files changed

+111
-37
lines changed

8 files changed

+111
-37
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ subprojects { subProject ->
189189
systemProperties['hibernate.test.validatefailureexpected'] = true
190190
systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
191191

192-
beforeTest { descriptor ->
193-
println "Starting test: " + descriptor
194-
}
192+
// beforeTest { descriptor ->
193+
// println "Starting test: " + descriptor
194+
// }
195195

196196
// afterTest { descriptor ->
197197
// println "Completed test: " + descriptor

hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/IdentifierHelperBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class IdentifierHelperBuilder {
3535
private Set<String> reservedWords = new TreeSet<String>( String.CASE_INSENSITIVE_ORDER );
3636
private boolean globallyQuoteIdentifiers = false;
3737
private boolean autoQuoteKeywords = true;
38-
private IdentifierCaseStrategy unquotedCaseStrategy = IdentifierCaseStrategy.UPPER;
38+
private IdentifierCaseStrategy unquotedCaseStrategy = IdentifierCaseStrategy.MIXED;
3939
private IdentifierCaseStrategy quotedCaseStrategy = IdentifierCaseStrategy.MIXED;
4040

4141
public static IdentifierHelperBuilder from(JdbcEnvironment jdbcEnvironment) {

hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ public boolean catalogExists(Identifier catalog) {
110110
@Override
111111
public boolean schemaExists(Identifier catalog, Identifier schema) {
112112
try {
113+
final String catalogFilter = determineCatalogFilter( catalog );
114+
final String schemaFilter = determineSchemaFilter( schema );
115+
113116
final ResultSet resultSet = extractionContext.getJdbcDatabaseMetaData().getSchemas(
114-
determineCatalogFilter( catalog ),
115-
determineSchemaFilter( schema )
117+
catalogFilter,
118+
schemaFilter
116119
);
117120

118121
try {
@@ -267,6 +270,9 @@ private TableInformation locateTableInNamespace(
267270
Identifier catalog,
268271
Identifier schema,
269272
Identifier tableName) {
273+
Identifier catalogToUse = null;
274+
Identifier schemaToUse = null;
275+
270276
final String catalogFilter;
271277
final String schemaFilter;
272278

@@ -275,6 +281,7 @@ private TableInformation locateTableInNamespace(
275281
catalogFilter = "";
276282
}
277283
else {
284+
catalogToUse = catalog;
278285
catalogFilter = toMetaDataObjectName( catalog );
279286
}
280287
}
@@ -287,6 +294,7 @@ private TableInformation locateTableInNamespace(
287294
schemaFilter = "";
288295
}
289296
else {
297+
schemaToUse = schema;
290298
schemaFilter = toMetaDataObjectName( schema );
291299
}
292300
}
@@ -305,8 +313,8 @@ private TableInformation locateTableInNamespace(
305313
);
306314

307315
return processGetTableResults(
308-
catalog,
309-
schema,
316+
catalogToUse,
317+
schemaToUse,
310318
tableName,
311319
resultSet
312320
);
@@ -364,14 +372,44 @@ protected boolean isPhysicalTableType(String tableType) {
364372

365373
@Override
366374
public ColumnInformation getColumn(TableInformation tableInformation, Identifier columnIdentifier) {
375+
final Identifier catalog = tableInformation.getName().getCatalogName();
376+
final Identifier schema = tableInformation.getName().getSchemaName();
377+
378+
final String catalogFilter;
379+
final String schemaFilter;
380+
381+
if ( extractionContext.getJdbcEnvironment().getNameQualifierSupport().supportsCatalogs() ) {
382+
if ( catalog == null ) {
383+
catalogFilter = "";
384+
}
385+
else {
386+
catalogFilter = toMetaDataObjectName( catalog );
387+
}
388+
}
389+
else {
390+
catalogFilter = null;
391+
}
392+
393+
if ( extractionContext.getJdbcEnvironment().getNameQualifierSupport().supportsSchemas() ) {
394+
if ( schema == null ) {
395+
schemaFilter = "";
396+
}
397+
else {
398+
schemaFilter = toMetaDataObjectName( schema );
399+
}
400+
}
401+
else {
402+
schemaFilter = null;
403+
}
404+
405+
final String tableFilter = toMetaDataObjectName( tableInformation.getName().getTableName() );
406+
final String columnFilter = toMetaDataObjectName( columnIdentifier );
367407
try {
368408
ResultSet resultSet = extractionContext.getJdbcDatabaseMetaData().getColumns(
369-
identifierHelper().toMetaDataCatalogName( tableInformation.getName().getCatalogName() ),
370-
identifierHelper().toMetaDataSchemaName( tableInformation.getName().getSchemaName() ),
371-
identifierHelper().toMetaDataObjectName( tableInformation.getName().getTableName() ),
372-
extractionContext.getJdbcEnvironment()
373-
.getIdentifierHelper()
374-
.toMetaDataObjectName( columnIdentifier )
409+
catalogFilter,
410+
schemaFilter,
411+
tableFilter,
412+
columnFilter
375413
);
376414

377415
try {

hibernate-core/src/test/java/org/hibernate/test/foreignkeys/disabled/ManyToManyOwner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void setName(String name) {
7474
)
7575
},
7676
inverseForeignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT),
77-
name = "many_to_many"
77+
name = "Many_To_Many"
7878
)
7979
public Set<ManyToManyTarget> getManyToMany() {
8080
return manyToMany;

hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public void testIndexCreationViaSchemaUpdate() {
128128
.addAnnotatedClass( EntityWithIndex.class )
129129
.buildMetadata();
130130

131-
// export the schema
132-
new SchemaExport( metadata ).execute( Target.EXPORT, SchemaExport.Type.CREATE );
131+
// drop and then create the schema
132+
new SchemaExport( metadata ).execute( Target.EXPORT, SchemaExport.Type.BOTH );
133133

134134
try {
135135
// update the schema
@@ -157,8 +157,8 @@ public void testSameTableNameDifferentExplicitSchemas() {
157157
.addAnnotatedClass( PersonInfo.class )
158158
.buildMetadata();
159159

160-
// export the schema
161-
new SchemaExport( metadata, true ).execute( Target.EXPORT, SchemaExport.Type.CREATE );
160+
// drop and then create the schema
161+
new SchemaExport( metadata, true ).execute( Target.EXPORT, SchemaExport.Type.BOTH );
162162

163163
try {
164164
// update the schema

hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.dialect.Dialect;
1313
import org.hibernate.service.ServiceRegistry;
1414
import org.hibernate.tool.hbm2ddl.SchemaExport;
15+
import org.hibernate.tool.hbm2ddl.Target;
1516

1617
import org.hibernate.testing.ServiceRegistryBuilder;
1718
import org.hibernate.testing.junit4.BaseUnitTestCase;
@@ -43,6 +44,7 @@ public void setUp() {
4344
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
4445
.addResource( "org/hibernate/test/schemaupdate/mapping.hbm.xml" )
4546
.buildMetadata();
47+
metadata.validate();
4648

4749
SchemaExport schemaExport = createSchemaExport( metadata, serviceRegistry );
4850
schemaExport.drop( true, true );
@@ -59,20 +61,15 @@ public void testCreateAndDropOnlyType() {
5961
final SchemaExport schemaExport = createSchemaExport( metadata, serviceRegistry );
6062

6163
// create w/o dropping first; (OK because tables don't exist yet
62-
schemaExport.execute( false, true, false, true );
63-
// if ( doesDialectSupportDropTableIfExist() ) {
64-
assertEquals( 0, schemaExport.getExceptions().size() );
65-
// }
66-
// else {
67-
// assertEquals( 2, schemaExport.getExceptions().size() );
68-
// }
69-
// create w/o dropping again; should be an exception for each table
70-
// (2 total) because the tables exist already
71-
// assertEquals( 0, schemaExport.getExceptions().size() );
72-
schemaExport.execute( false, true, false, true );
73-
assertEquals( 2, schemaExport.getExceptions().size() );
64+
schemaExport.execute( Target.EXPORT, SchemaExport.Type.CREATE );
65+
assertEquals( 0, schemaExport.getExceptions().size() );
66+
67+
// create w/o dropping again; should cause an exception because the tables exist already
68+
schemaExport.execute( Target.EXPORT, SchemaExport.Type.CREATE );
69+
assertEquals( 1, schemaExport.getExceptions().size() );
70+
7471
// drop tables only
75-
schemaExport.execute( false, true, true, false );
72+
schemaExport.execute( Target.EXPORT, SchemaExport.Type.DROP );
7673
assertEquals( 0, schemaExport.getExceptions().size() );
7774
}
7875

@@ -86,11 +83,13 @@ public void testBothType() {
8683
assertEquals( 0, schemaExport.getExceptions().size() );
8784
}
8885
else {
89-
assertEquals( 2, schemaExport.getExceptions().size() );
86+
assertEquals( 1, schemaExport.getExceptions().size() );
9087
}
88+
9189
// drop before crete again (this time drops the tables before re-creating)
9290
schemaExport.execute( false, true, false, false );
9391
assertEquals( 0, schemaExport.getExceptions().size() );
92+
9493
// drop tables
9594
schemaExport.execute( false, true, true, false );
9695
assertEquals( 0, schemaExport.getExceptions().size() );
@@ -101,14 +100,15 @@ public void testGenerateDdlToFile() {
101100
final SchemaExport schemaExport = createSchemaExport( metadata, serviceRegistry );
102101

103102
java.io.File outFile = new java.io.File("schema.ddl");
104-
schemaExport.setOutputFile(outFile.getPath());
103+
schemaExport.setOutputFile( outFile.getPath() );
104+
105105
// do not script to console or export to database
106106
schemaExport.execute( false, false, false, true );
107-
if ( doesDialectSupportDropTableIfExist()
108-
&& schemaExport.getExceptions().size() > 0 ) {
107+
if ( doesDialectSupportDropTableIfExist() && schemaExport.getExceptions().size() > 0 ) {
109108
assertEquals( 2, schemaExport.getExceptions().size() );
110109
}
111110
assertTrue( outFile.exists() );
111+
112112
//check file is not empty
113113
assertTrue( outFile.length() > 0 );
114114
outFile.delete();

hibernate-core/src/test/java/org/hibernate/test/schemaupdate/mapping.hbm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<class name="Version">
1515
<id name="id">
16-
<generator class="sequence"/>
16+
<generator class="increment"/>
1717
</id>
1818
<property name="description"/>
1919
</class>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.testing.jdbc;
8+
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import java.util.ArrayList;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
/**
17+
* @author Steve Ebersole
18+
*/
19+
public class ResultSetUtil {
20+
public static List<Map<String,?>> extractResults(ResultSet resultSet) throws SQLException {
21+
List<Map<String,?>> results = new ArrayList<Map<String, ?>>();
22+
23+
while ( resultSet.next() ) {
24+
Map<String,Object> row = new HashMap<String, Object>();
25+
for ( int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++ ) {
26+
row.put(
27+
resultSet.getMetaData().getColumnLabel( i ),
28+
resultSet.getObject( i )
29+
);
30+
results.add( row );
31+
}
32+
}
33+
34+
return results;
35+
}
36+
}

0 commit comments

Comments
 (0)