本文整理汇总了Java中org.hibernate.tool.schema.TargetType类的典型用法代码示例。如果您正苦于以下问题:Java TargetType类的具体用法?Java TargetType怎么用?Java TargetType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TargetType类属于org.hibernate.tool.schema包,在下文中一共展示了TargetType类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyConstraints
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
protected void applyConstraints(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (isApplyingConstraints(sql)) {
sqls.add(sql);
}
}
execute(sqls, true);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例2: createTables
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
protected void createTables(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (shouldInclude(sql) && !isApplyingConstraints(sql))
sqls.add(sql);
}
execute(sqls, true);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
FileUtils.deleteFile(tempFile);
}
}
示例3: dropConstraints
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
protected void dropConstraints(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).drop(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (isDroppingConstraints(sql))
sqls.add(sql);
}
execute(sqls, false);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例4: cleanDatabase
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
protected void cleanDatabase(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).drop(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
sqls.add(sql);
}
execute(sqls, false);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例5: outputDdl
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
private void outputDdl(String packageName, String dialect, String fileName) {
LocalSessionFactoryBean sfBean = sfBean(packageName, dialect);
StandardServiceRegistry serviceRegistry = sfBean.getConfiguration().getStandardServiceRegistryBuilder().build();
try {
String outputFile = OutputRoot + fileName;
Files.deleteIfExists(Paths.get(outputFile));
MetadataImplementor metadata = metadata(sfBean, serviceRegistry);
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setFormat(FormatSql);
export.setOutputFile(outputFile);
export.create(EnumSet.of(TargetType.SCRIPT), metadata);
} catch (Exception e) {
throw new InvocationException(e);
} finally {
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
}
示例6: generate
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
/**
* Method that actually creates the file.
*
* @param dbDialect to use
*/
private void generate(Dialect dialect) {
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
StandardServiceRegistry standardServiceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
for (Class clzz : jpaClasses) {
metadataSources.addAnnotatedClass(clzz);
}
Metadata metadata = metadataSources.buildMetadata();
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
//export.execute(true, false, false, true);
export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
示例7: main
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
public static void main(String[] args){
String file = "camping-db-creation.sql";
new File(file).delete();
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder().configure().build());
SchemaExport export = new SchemaExport();
export.setOutputFile(file);
export.setDelimiter(";");
export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}
示例8: createSQLSchema
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
private void createSQLSchema(String fileName, String dialect) {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.implicit_naming_strategy", new MidPointImplicitNamingStrategy())
.applySetting("hibernate.physical_naming_strategy", new MidPointPhysicalNamingStrategy())
.applySetting("hibernate.dialect", dialect)
.build());
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", metadata);
metadata.addPackage("com.evolveum.midpoint.repo.sql.type");
SchemaExport export = new SchemaExport();
export.setOutputFile(fileName);
export.setDelimiter(";");
// export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}
示例9: dropAndCreate
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
public void dropAndCreate() {
// SchemaExport export = new SchemaExport(HibernateUtil.getConfiguration());
// export.drop(true, true);
// export.create(true, true);
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("javax.persistence.schema-generation-connection", this.getConnection())
.build());
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
}
示例10: writeSqlDiffScript
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
public static void writeSqlDiffScript(ConfigurableApplicationContext context, String fileName, String action) {
EntityManagerFactory entityManagerFactory = context.getBean(EntityManagerFactory.class);
EntityManager entityManager = entityManagerFactory.createEntityManager();
ExecutionOptions executionOptions = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return false;
}
@Override
public Map<?, ?> getConfigurationValues() {
return Maps.newHashMap();
}
@Override
public ExceptionHandler getExceptionHandler() {
// TODO récupérer et vérifier aucune exception pendant la mise à jour
return new ExceptionHandlerCollectingImpl();
}
};
ServiceRegistry serviceRegistry = ((SessionImpl) entityManager.getDelegate()).getSessionFactory().getServiceRegistry();
Metadata metadata = MetadataRegistryIntegrator.METADATA;
EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.SCRIPT);
TargetDescriptor targetDescriptor = SchemaExport.buildTargetDescriptor(targetTypes, fileName, serviceRegistry);
if (action.equals("create")) {
final SourceDescriptor sourceDescriptor = new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
};
serviceRegistry.getService(SchemaManagementTool.class).getSchemaCreator(Maps.newHashMap())
.doCreation(metadata, executionOptions, sourceDescriptor, targetDescriptor);
} else if (action.equals("update")) {
serviceRegistry.getService(SchemaManagementTool.class).getSchemaMigrator(Maps.newHashMap())
.doMigration(metadata, executionOptions, targetDescriptor);
}
}
示例11: createDatabase
import org.hibernate.tool.schema.TargetType; //导入依赖的package包/类
public void createDatabase() throws HibernateException {
// executes a drop and a create!
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
}