Skip to content

Commit

Permalink
Merge pull request #275 from nmck257/feature/nationalized-characters
Browse files Browse the repository at this point in the history
Feature/nationalized characters
  • Loading branch information
nvoxland authored Jun 21, 2022
2 parents 2c89ef5 + b5dc820 commit 3a2c918
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) throws
configureNewIdentifierGeneratorSupport(getProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS), metadataBuilder);
configureImplicitNamingStrategy(getProperty(AvailableSettings.IMPLICIT_NAMING_STRATEGY), metadataBuilder);
configurePhysicalNamingStrategy(getProperty(AvailableSettings.PHYSICAL_NAMING_STRATEGY), metadataBuilder);
metadataBuilder.enableGlobalNationalizedCharacterDataSupport(
Boolean.parseBoolean(getProperty(AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws D
}

/**
* Calls {@link #createEntityManagerFactory()} to create and save the entity manager factory.
* Calls {@link #createEntityManagerFactoryBuilder()} to create and save the entity manager factory.
*/
@Override
protected Metadata buildMetadataFromPath() throws DatabaseException {
Expand Down Expand Up @@ -81,6 +81,7 @@ protected EntityManagerFactoryBuilderImpl createEntityManagerFactoryBuilder() {

Map<String, Object> properties = new HashMap<>();
properties.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, Boolean.FALSE.toString());
properties.put(AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, getProperty(AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA));

final EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) persistenceProvider.getEntityManagerFactoryBuilderOrNull(getHibernateConnection().getPath(), properties, null);
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ protected EntityManagerFactoryBuilderImpl createEntityManagerFactoryBuilder() {
map.put(AvailableSettings.SCANNER_DISCOVERY, ""); // disable scanning of all classes and hbm.xml files. Only scan speficied packages
map.put(EnversSettings.AUDIT_TABLE_PREFIX,getHibernateConnection().getProperties().getProperty(EnversSettings.AUDIT_TABLE_PREFIX,""));
map.put(EnversSettings.AUDIT_TABLE_SUFFIX,getHibernateConnection().getProperties().getProperty(EnversSettings.AUDIT_TABLE_SUFFIX,"_AUD"));

map.put(AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, getProperty(AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA));

EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(persistenceUnitInfo, map);

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ private void ignoreDatabaseChangeLogTable(DiffResult diffResult) throws Exceptio
Set<Index> unexpectedIndexes = diffResult.getUnexpectedObjects(Index.class);
for (Iterator<Index> iterator = unexpectedIndexes.iterator(); iterator.hasNext(); ) {
Index index = iterator.next();
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getTable().getName()) || "DATABASECHANGELOG".equalsIgnoreCase(index.getTable().getName()))
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getRelation().getName()) || "DATABASECHANGELOG".equalsIgnoreCase(index.getRelation().getName()))
diffResult.getUnexpectedObjects().remove(index);
}
Set<Index> missingIndexes = diffResult.getMissingObjects(Index.class);
for (Iterator<Index> iterator = missingIndexes.iterator(); iterator.hasNext(); ) {
Index index = iterator.next();
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getTable().getName()) || "DATABASECHANGELOG".equalsIgnoreCase(index.getTable().getName()))
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getRelation().getName()) || "DATABASECHANGELOG".equalsIgnoreCase(index.getRelation().getName()))
diffResult.getMissingObjects().remove(index);
}
Set<PrimaryKey> unexpectedPrimaryKeys = diffResult.getUnexpectedObjects(PrimaryKey.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ private void ignoreDatabaseChangeLogTable(DiffResult diffResult)
Set<Index> unexpectedIndexes = diffResult.getUnexpectedObjects(Index.class);
for (Iterator<Index> iterator = unexpectedIndexes.iterator(); iterator.hasNext(); ) {
Index index = iterator.next();
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getTable().getName())
|| "DATABASECHANGELOG".equalsIgnoreCase(index.getTable().getName()))
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getRelation().getName())
|| "DATABASECHANGELOG".equalsIgnoreCase(index.getRelation().getName()))
diffResult.getUnexpectedObjects().remove(index);
}
Set<Index> missingIndexes = diffResult.getMissingObjects(Index.class);
for (Iterator<Index> iterator = missingIndexes.iterator(); iterator.hasNext(); ) {
Index index = iterator.next();
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getTable().getName())
|| "DATABASECHANGELOG".equalsIgnoreCase(index.getTable().getName()))
if ("DATABASECHANGELOGLOCK".equalsIgnoreCase(index.getRelation().getName())
|| "DATABASECHANGELOG".equalsIgnoreCase(index.getRelation().getName()))
diffResult.getMissingObjects().remove(index);
}
Set<PrimaryKey> unexpectedPrimaryKeys = diffResult.getUnexpectedObjects(PrimaryKey.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import liquibase.database.Database;
import liquibase.database.DatabaseConnection;
import liquibase.integration.commandline.CommandLineUtils;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.SnapshotControl;
import liquibase.snapshot.SnapshotGeneratorFactory;
Expand All @@ -13,10 +14,12 @@
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.*;


public class HibernateClassicDatabaseTest {

private static final String CUSTOMCONFIG_CLASS = "com.example.customconfig.CustomClassicConfigurationFactoryImpl";
Expand Down Expand Up @@ -64,13 +67,27 @@ public void tearDown() throws Exception {
@Test
public void simpleHibernateUrl() throws Exception {
String url = "hibernate:classic:com/example/pojo/Hibernate.cfg.xml";
Database database = CommandLineUtils.createDatabaseObject(this.getClass().getClassLoader(), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

assertPojoHibernateMapped(snapshot);
}

@Test
public void nationalizedCharactersHibernateUrl() throws Exception {
String url = "hibernate:classic:com/example/pojo/Hibernate.cfg.xml?hibernate.use_nationalized_character_data=true";
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

assertPojoHibernateMapped(snapshot);
Table watcherTable = (Table) snapshot.get(new Table().setName("watcher").setSchema(new Schema()));
assertEquals("nvarchar", watcherTable.getColumn("name").getType().getTypeName());
}

public static void assertPojoHibernateMapped(DatabaseSnapshot snapshot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import liquibase.CatalogAndSchema;
import liquibase.database.Database;
import liquibase.integration.commandline.CommandLineUtils;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.SnapshotControl;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.structure.core.Schema;
import liquibase.structure.core.Table;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.*;
Expand All @@ -19,7 +21,7 @@ public class HibernateEjb3DatabaseTest {
@Test
public void simpleEjb3Url() throws Exception {
String url = "hibernate:ejb3:auction";
Database database = CommandLineUtils.createDatabaseObject(this.getClass().getClassLoader(), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

Expand All @@ -28,6 +30,20 @@ public void simpleEjb3Url() throws Exception {
assertEjb3HibernateMapped(snapshot);
}

@Test
public void nationalizedCharactersEjb3Url() throws Exception {
String url = "hibernate:ejb3:auction?hibernate.use_nationalized_character_data=true";
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

assertEjb3HibernateMapped(snapshot);
Table userTable = (Table) snapshot.get(new Table().setName("user").setSchema(new Schema()));
assertEquals("nvarchar", userTable.getColumn("userName").getType().getTypeName());
}

public static void assertEjb3HibernateMapped(DatabaseSnapshot snapshot) {
assertThat(snapshot.get(Table.class), containsInAnyOrder(
hasProperty("name", is("Bid")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.SnapshotControl;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.structure.core.Schema;
import liquibase.structure.core.Table;
import org.hibernate.dialect.H2Dialect;
import org.junit.After;
import org.junit.Test;
Expand Down Expand Up @@ -56,7 +58,7 @@ public void testSpringPackageScanningMustHaveItemClassMapping() throws DatabaseE
@Test
public void simpleSpringUrl() throws Exception {
String url = "hibernate:spring:spring.ctx.xml?bean=sessionFactory";
Database database = CommandLineUtils.createDatabaseObject(this.getClass().getClassLoader(), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

Expand All @@ -65,16 +67,44 @@ public void simpleSpringUrl() throws Exception {
HibernateClassicDatabaseTest.assertPojoHibernateMapped(snapshot);
}

@Test
public void nationalizedCharactersSpringBeanUrl() throws Exception {
String url = "hibernate:spring:spring.ctx.xml?hibernate.use_nationalized_character_data=true&bean=sessionFactory";
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

HibernateClassicDatabaseTest.assertPojoHibernateMapped(snapshot);
Table watcherTable = (Table) snapshot.get(new Table().setName("watcher").setSchema(new Schema()));
assertEquals("nvarchar", watcherTable.getColumn("name").getType().getTypeName());
}

@Test
public void simpleSpringScanningUrl() throws Exception {
String url = "hibernate:spring:com.example.ejb3.auction?dialect=" + H2Dialect.class.getName();
Database database = CommandLineUtils.createDatabaseObject(this.getClass().getClassLoader(), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

HibernateEjb3DatabaseTest.assertEjb3HibernateMapped(snapshot);
}

@Test
public void nationalizedCharactersSpringScanningUrl() throws Exception {
String url = "hibernate:spring:com.example.ejb3.auction?hibernate.use_nationalized_character_data=true&dialect=" + H2Dialect.class.getName();
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, database, new SnapshotControl(database));

HibernateEjb3DatabaseTest.assertEjb3HibernateMapped(snapshot);
Table userTable = (Table) snapshot.get(new Table().setName("user").setSchema(new Schema()));
assertEquals("nvarchar", userTable.getColumn("userName").getType().getTypeName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import liquibase.CatalogAndSchema;
import liquibase.database.Database;
import liquibase.integration.commandline.CommandLineUtils;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.SnapshotControl;
import liquibase.snapshot.SnapshotGeneratorFactory;
Expand All @@ -17,7 +18,7 @@ public class JPAPersistenceDatabaseTest {
@Test
public void persistenceXML() throws Exception {
String url = "jpa:persistence:META-INF/persistence.xml";
Database database = CommandLineUtils.createDatabaseObject(this.getClass().getClassLoader(), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);
Database database = CommandLineUtils.createDatabaseObject(new ClassLoaderResourceAccessor(this.getClass().getClassLoader()), url, null, null, null, null, null, false, false, null, null, null, null, null, null, null);

assertNotNull(database);

Expand Down

0 comments on commit 3a2c918

Please sign in to comment.