use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project cas by apereo.
the class GenerateDdlCommand method generate.
/**
* Generate.
*
* @param file the file
* @param dialect the dialect
* @param delimiter the delimiter
* @param pretty the pretty
* @param dropSchema the drop schema
* @param createSchema the create schema
* @param haltOnError the halt on error
*/
@CliCommand(value = "generate-ddl", help = "Generate database DDL scripts")
public void generate(@CliOption(key = { "file" }, help = "DDL file to contain to generated script", specifiedDefaultValue = "/etc/cas/config/cas-db-schema.sql", unspecifiedDefaultValue = "/etc/cas/config/cas-db-schema.sql", optionContext = "DDL file to contain to generated script") final String file, @CliOption(key = { "dialect" }, help = "Database dialect class", specifiedDefaultValue = "HSQL", unspecifiedDefaultValue = "HSQL", optionContext = "Database dialect class") final String dialect, @CliOption(key = { "delimiter" }, help = "Delimiter to use for separation of statements when generating SQL", specifiedDefaultValue = ";", unspecifiedDefaultValue = ";", optionContext = "Delimiter to use for separation of statements when generating SQL") final String delimiter, @CliOption(key = { "pretty" }, help = "Format DDL scripts and pretty-print the output", specifiedDefaultValue = "true", unspecifiedDefaultValue = "true", optionContext = "Format DDL scripts and pretty-print the output") final boolean pretty, @CliOption(key = { "dropSchema" }, help = "Generate DROP SQL statements in the DDL", specifiedDefaultValue = "true", unspecifiedDefaultValue = "true", optionContext = "Generate DROP statements in the DDL") final boolean dropSchema, @CliOption(key = { "createSchema" }, help = "Generate DROP SQL statements in the DDL", specifiedDefaultValue = "true", unspecifiedDefaultValue = "true", optionContext = "Generate CREATE SQL statements in the DDL") final boolean createSchema, @CliOption(key = { "haltOnError" }, help = "Halt if an error occurs during the generation process", specifiedDefaultValue = "true", unspecifiedDefaultValue = "true", optionContext = "Halt if an error occurs during the generation process") final boolean haltOnError) {
final String dialectName = DIALECTS_MAP.getOrDefault(dialect.trim().toUpperCase(), dialect);
LOGGER.info("Using database dialect class [{}]", dialectName);
if (!dialectName.contains(".")) {
LOGGER.warn("Dialect name must be a fully qualified class name. Supported dialects by default are [{}] " + "or you may specify the dialect class directly", DIALECTS_MAP.keySet());
return;
}
final StandardServiceRegistryBuilder svcRegistry = new StandardServiceRegistryBuilder();
if (StringUtils.isNotBlank(dialectName)) {
svcRegistry.applySetting(AvailableSettings.DIALECT, dialect);
}
final MetadataSources metadata = new MetadataSources(svcRegistry.build());
REFLECTIONS.getTypesAnnotatedWith(MappedSuperclass.class).forEach(metadata::addAnnotatedClass);
REFLECTIONS.getTypesAnnotatedWith(Entity.class).forEach(metadata::addAnnotatedClass);
final SchemaExport export = new SchemaExport();
export.setDelimiter(delimiter);
export.setOutputFile(file);
export.setFormat(pretty);
export.setHaltOnError(haltOnError);
export.setManageNamespaces(true);
final SchemaExport.Action action;
if (createSchema && dropSchema) {
action = SchemaExport.Action.BOTH;
} else if (createSchema) {
action = SchemaExport.Action.CREATE;
} else if (dropSchema) {
action = SchemaExport.Action.DROP;
} else {
action = SchemaExport.Action.NONE;
}
LOGGER.info("Exporting Database DDL to [{}] using dialect [{}] with export type set to [{}]", file, dialect, action);
export.execute(EnumSet.of(TargetType.SCRIPT, TargetType.STDOUT), SchemaExport.Action.BOTH, metadata.buildMetadata());
LOGGER.info("Database DDL is exported to [{}]", file);
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project ignite by apache.
the class HibernateL2CacheSelfTest method startHibernate.
/**
* Starts Hibernate.
*
* @param accessType Cache access type.
* @param igniteInstanceName Ignite instance name.
* @return Session factory.
*/
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = registryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue());
// Use the same cache for Entity and Entity2.
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
StandardServiceRegistry srvcRegistry = builder.build();
MetadataSources metadataSources = new MetadataSources(srvcRegistry);
for (Class entityClass : getAnnotatedClasses()) metadataSources.addAnnotatedClass(entityClass);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings()) collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName());
return metadata.buildSessionFactory();
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project ignite by apache.
the class HibernateL2CacheTransactionalSelfTest method registryBuilder.
/**
* {@inheritDoc}
*/
@Nullable
@Override
protected StandardServiceRegistryBuilder registryBuilder() {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
// JTA-aware data source.
BasicManagedDataSource dataSrc = new BasicManagedDataSource();
dataSrc.setTransactionManager(jotm.getTransactionManager());
dataSrc.setDefaultAutoCommit(false);
JdbcDataSource h2DataSrc = new JdbcDataSource();
h2DataSrc.setURL(CONNECTION_URL);
dataSrc.setXaDataSourceInstance(h2DataSrc);
connProvider.setDataSource(dataSrc);
connProvider.configure(Collections.emptyMap());
builder.addService(ConnectionProvider.class, connProvider);
builder.addService(JtaPlatform.class, new TestJtaPlatform());
builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
return builder;
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project ignite by apache.
the class HibernateL2CacheConfigurationSelfTest method startHibernate.
/**
* @param igniteInstanceName Name of the grid providing caches.
* @return Session factory.
*/
private SessionFactory startHibernate(String igniteInstanceName) {
Configuration cfg = hibernateConfiguration(igniteInstanceName);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
builder.applySetting("hibernate.show_sql", false);
builder.applySettings(cfg.getProperties());
return cfg.buildSessionFactory(builder.build());
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class TimestampsRegionImplTest method testClearTimestampsRegionInIsolated.
public void testClearTimestampsRegionInIsolated() throws Exception {
StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder();
final StandardServiceRegistry registry = ssrb.build();
final StandardServiceRegistry registry2 = ssrb.build();
try {
final Properties properties = CacheTestUtil.toProperties(ssrb.getSettings());
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(registry, getCacheTestSupport());
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(registry2, getCacheTestSupport());
TimestampsRegionImpl region = (TimestampsRegionImpl) regionFactory.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
TimestampsRegionImpl region2 = (TimestampsRegionImpl) regionFactory2.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
Account acct = new Account();
acct.setAccountHolder(new AccountHolder());
region.getCache().withFlags(Flag.FORCE_SYNCHRONOUS).put(acct, "boo");
} finally {
StandardServiceRegistryBuilder.destroy(registry);
StandardServiceRegistryBuilder.destroy(registry2);
}
}
Aggregations