use of org.hibernate.tool.hbm2ddl.SchemaExport in project jOOQ by jOOQ.
the class JPADatabase method create0.
@SuppressWarnings("serial")
@Override
protected DSLContext create0() {
if (connection == null) {
String packages = getProperties().getProperty("packages");
if (isBlank(packages)) {
packages = "";
log.warn("No packages defined", "It is highly recommended that you provide explicit packages to scan");
}
try {
connection = DriverManager.getConnection("jdbc:h2:mem:jooq-meta-extensions", "sa", "");
MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").applySetting("javax.persistence.schema-generation-connection", connection).applySetting(AvailableSettings.CONNECTION_PROVIDER, new ConnectionProvider() {
@SuppressWarnings("rawtypes")
@Override
public boolean isUnwrappableAs(Class unwrapType) {
return false;
}
@Override
public <T> T unwrap(Class<T> unwrapType) {
return null;
}
@Override
public Connection getConnection() {
return connection;
}
@Override
public void closeConnection(Connection conn) throws SQLException {
}
@Override
public boolean supportsAggressiveRelease() {
return true;
}
}).build());
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
// [#5845] Use the correct ClassLoader to load the jpa entity classes defined in the user project
ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (String pkg : packages.split(",")) for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim())) metadata.addAnnotatedClass(Class.forName(def.getBeanClassName(), true, cl));
// This seems to be the way to do this in idiomatic Hibernate 5.0 API
// See also: http://stackoverflow.com/q/32178041/521799
// SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
// export.create(true, true);
// Hibernate 5.2 broke 5.0 API again. Here's how to do this now:
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
} catch (Exception e) {
throw new DataAccessException("Error while exporting schema", e);
}
}
return DSL.using(connection);
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project ACS by ACS-Community.
the class TestCase method runSchemaGeneration.
protected void runSchemaGeneration() {
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project SimpleContentPortlet by Jasig.
the class SchemaCreator method create.
private int create() {
/*
* We will need to provide a Configuration and a Connection; both should be properly
* managed by the Spring ApplicationContext.
*/
final DataSource dataSource = applicationContext.getBean(DATA_SOURCE_BEAN_NAME, DataSource.class);
try (final Connection conn = dataSource.getConnection()) {
final Configuration config = new Configuration();
config.setProperty("hibernate.dialect", hibernateDialect);
config.addAnnotatedClass(Attachment.class);
logger.info("Creating database schema based on the following Configuration:\n{}", config);
final SchemaExport schemaExport = new SchemaExport(config, conn);
schemaExport.execute(true, true, false, false);
final List<Exception> exceptions = schemaExport.getExceptions();
if (exceptions.size() != 0) {
logger.error("Schema Create Failed; see below for details");
for (Exception e : exceptions) {
logger.error("Exception from Hibernate Tools SchemaExport", e);
}
return 1;
}
} catch (SQLException sqle) {
logger.error("Failed to initialize & invoke the SchemaExport tool", sqle);
return 1;
}
return 0;
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newSchemaExport.
@Override
public ISchemaExport newSchemaExport(IConfiguration hcfg) {
ISchemaExport result = null;
if (hcfg instanceof IFacade) {
SchemaExport schemaExport = new SchemaExport((Configuration) ((IFacade) hcfg).getTarget());
result = facadeFactory.createSchemaExport(schemaExport);
}
return result;
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newSchemaExport.
@Override
public ISchemaExport newSchemaExport(IConfiguration hcfg) {
ISchemaExport result = null;
if (hcfg instanceof IFacade) {
Configuration configuration = (Configuration) ((IFacade) hcfg).getTarget();
MetadataImplementor metadata = (MetadataImplementor) MetadataHelper.getMetadata(configuration);
SchemaExport schemaExport = new SchemaExport(metadata);
result = facadeFactory.createSchemaExport(schemaExport);
}
return result;
}
Aggregations