當前位置: 首頁>>代碼示例>>Java>>正文


Java SchemaExport類代碼示例

本文整理匯總了Java中org.hibernate.tool.hbm2ddl.SchemaExport的典型用法代碼示例。如果您正苦於以下問題:Java SchemaExport類的具體用法?Java SchemaExport怎麽用?Java SchemaExport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SchemaExport類屬於org.hibernate.tool.hbm2ddl包,在下文中一共展示了SchemaExport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateDDL

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
private void generateDDL() throws Exception {
    final MetadataImplementor md = createMetaData();
    final SchemaExport export = new SchemaExport(md);

    // drop
    {
        export.setDelimiter(";");
        export.setOutputFile(getRefPath() + "/db-drop.sql");
        export.setFormat(true);
        export.execute(true, false, true, false);
    }
    // create
    {
        export.setDelimiter(";");
        export.setOutputFile(getRefPath() + "/db-create.sql");
        export.setFormat(true);
        export.execute(true, false, false, true);
    }
}
 
開發者ID:shared-vd,項目名稱:tipi-engine,代碼行數:20,代碼來源:TipiDDLGeneratorTest.java

示例2: applyConstraints

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的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();
   	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:21,代碼來源:DefaultPersistManager.java

示例3: createTables

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的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);
   	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:20,代碼來源:DefaultPersistManager.java

示例4: dropConstraints

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的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();
   	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:20,代碼來源:DefaultPersistManager.java

示例5: cleanDatabase

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的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();
   	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:19,代碼來源:DefaultPersistManager.java

示例6: outputDdl

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的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 );
    }
}
 
開發者ID:jkazama,項目名稱:sample-boot-micro,代碼行數:20,代碼來源:DdlExporter.java

示例7: generateDatabase

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
/**
 * Generate database schema and initial data for a defined dialect
 */
public static void generateDatabase(String dialect) throws IOException {
	// Configure Hibernate
	log.info("Exporting Database Schema...");
	String dbSchema = EnvironmentDetector.getUserHome() + "/schema.sql";
	Configuration cfg = getConfiguration().configure();
	cfg.setProperty("hibernate.dialect", dialect);
	SchemaExport se = new SchemaExport(cfg);
	se.setOutputFile(dbSchema);
	se.setDelimiter(";");
	se.setFormat(false);
	se.create(false, false);
	log.info("Database Schema exported to {}", dbSchema);

	String initialData = new File("").getAbsolutePath() + "/src/main/resources/default.sql";
	log.info("Exporting Initial Data from '{}'...", initialData);
	String initData = EnvironmentDetector.getUserHome() + "/data.sql";
	FileInputStream fis = new FileInputStream(initialData);
	String ret = DatabaseDialectAdapter.dialectAdapter(fis, dialect);
	FileWriter fw = new FileWriter(initData);
	IOUtils.write(ret, fw);
	fw.flush();
	fw.close();
	log.info("Initial Data exported to {}", initData);
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:28,代碼來源:HibernateUtil.java

示例8: main

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
/**
 * Only for testing purposes
 */
public static void main(String[] args) throws Exception {
	log.info("Generate database schema & initial data");
	HibernateUtil.generateDatabase("org.hibernate.dialect.Oracle10gDialect");
	Configuration cfg = new Configuration();

	// Add annotated beans
	cfg.addAnnotatedClass(NodeFolder.class);

	// Configure Hibernate
	cfg.setProperty("hibernate.dialect", Config.HIBERNATE_DIALECT);
	cfg.setProperty("hibernate.hbm2ddl.auto", "create");

	SchemaExport se = new SchemaExport(cfg);
	se.setOutputFile("/home/pavila/export.sql");
	se.setDelimiter(";");
	se.setFormat(false);
	se.create(false, false);
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:22,代碼來源:Test.java

示例9: createSQLSchema

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
private void createSQLSchema(String fileName, String dialect) throws Exception {
        org.hibernate.cfg.Configuration configuration = new Configuration();
        configuration.setNamingStrategy(new MidPointNamingStrategy());
        configuration.setProperties(sessionFactory.getHibernateProperties());
        sessionFactory.getHibernateProperties().setProperty("hibernate.dialect", dialect);

        System.out.println("Dialect: " + sessionFactory.getHibernateProperties().getProperty("hibernate.dialect"));

        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", configuration);
        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", configuration);
//        addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.poc", configuration);

        configuration.addPackage("com.evolveum.midpoint.repo.sql.type");

        SchemaExport export = new SchemaExport(configuration);
        export.setOutputFile(fileName);
        export.setDelimiter(";");
        export.execute(true, false, false, true);
    }
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:27,代碼來源:SpringApplicationContextTest.java

示例10: prepareTest

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
protected void prepareTest() throws Exception {
	super.prepareTest();
	Connection conn = cp.getConnection();
	try {
		new SchemaExport( getCfg(), conn ).create( false, true );
	}
	finally {
		if ( conn != null ) {
			try {
				cp.closeConnection( conn );
			}
			catch( Throwable ignore ) {
			}
		}
	}
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:17,代碼來源:SuppliedConnectionTest.java

示例11: testSimpleColumnAddition

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
public void testSimpleColumnAddition() {
	String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
	String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";

	Configuration v1cfg = new Configuration();
	v1cfg.addResource( resource1 );
	new SchemaExport( v1cfg ).execute( false, true, true, false );

	SchemaUpdate v1schemaUpdate = new SchemaUpdate( v1cfg );
	v1schemaUpdate.execute( true, true );

	assertEquals( 0, v1schemaUpdate.getExceptions().size() );

	Configuration v2cfg = new Configuration();
	v2cfg.addResource( resource2 );

	SchemaUpdate v2schemaUpdate = new SchemaUpdate( v2cfg );
	v2schemaUpdate.execute( true, true );
	assertEquals( 0, v2schemaUpdate.getExceptions().size() );

}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:MigrationTest.java

示例12: schemaExport

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
private static void schemaExport(Log log,Configuration configuration, DatasourceConnection dc, SessionFactoryData data) throws PageException, SQLException, IOException {
	ORMConfiguration ormConf = data.getORMConfiguration();
	
	if(ORMConfiguration.DBCREATE_NONE==ormConf.getDbCreate()) {
		return;
	}
	else if(ORMConfiguration.DBCREATE_DROP_CREATE==ormConf.getDbCreate()) {
		SchemaExport export = new SchemaExport(configuration);
		export.setHaltOnError(true);
            
		export.execute(false,true,false,false);
           printError(log,data,export.getExceptions(),false);
           executeSQLScript(ormConf,dc);
	}
	else if(ORMConfiguration.DBCREATE_UPDATE==ormConf.getDbCreate()) {
		SchemaUpdate update = new SchemaUpdate(configuration);
           update.setHaltOnError(true);
           update.execute(false, true);
           printError(log,data,update.getExceptions(),false);
       }
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:22,代碼來源:HibernateSessionFactory.java

示例13: dropSchema

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
protected void dropSchema() throws ExecutionException, InterruptedException, IOException {
    log.info("Dropping schema!");
    Configuration config = new Configuration();
    Properties properties = new Properties();
    properties.putAll(entityManagerFactory.getProperties());

    config.setProperties(properties);
    entityManagerFactory.getMetamodel().getEntities()
        .stream()
        .map(EntityType::getJavaType)
        .forEach(config::addAnnotatedClass);

    EntityManagerImpl em = (EntityManagerImpl) entityManager;
    Session session = em.getSession();
    session.doWork(connection -> new SchemaExport(config, connection).create(false, true));
    entityManager.clear();
    log.info("Dropped schema successfully!");
}
 
開發者ID:MoodCat,項目名稱:MoodCat.me-Core,代碼行數:19,代碼來源:BootstrapRule.java

示例14: export

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
protected void export(Class<? extends Dialect> dialect, String app_key, Configuration configuration, boolean create, boolean drop) {
    Assert.notNull(dialect, "dialect is invalid [null]");
    Assert.notNull(app_key, "app_key is invalid [null]");
    Assert.notNull(configuration, "configuration is invalid [null]");
    
    SchemaExport schemaExport = new SchemaExport(configuration);
    schemaExport.setDelimiter(";");
    schemaExport.setFormat(true);

    if (create) {
        // Generate create script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_create.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, false, true);
    }

    if (drop) {
        // Generate drop script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_drop.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, true, false);
    }
}
 
開發者ID:bartgerard,項目名稱:ubrew_v0.1,代碼行數:22,代碼來源:SchemaExporterOld.java

示例15: export

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入依賴的package包/類
protected void export(Class<? extends Dialect> dialect, String app_key, MetadataSources metadata, boolean create, boolean drop) {
    Assert.notNull(dialect, "dialect is invalid [null]");
    Assert.notNull(app_key, "app_key is invalid [null]");
    Assert.notNull(metadata, "metadata is invalid [null]");

    SchemaExport schemaExport = new SchemaExport((MetadataImplementor) metadata.buildMetadata());
    schemaExport.setDelimiter(";");
    schemaExport.setFormat(true);

    if (create) {
        // Generate create script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_create.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, false, true);
    }

    if (drop) {
        // Generate drop script
        schemaExport.setOutputFile(String.format("target/%s_ddl_%s_drop.sql", app_key, dialect.getSimpleName()));
        schemaExport.execute(true, false, true, false);
    }
}
 
開發者ID:bartgerard,項目名稱:ubrew_v0.1,代碼行數:22,代碼來源:SchemaExporter.java


注:本文中的org.hibernate.tool.hbm2ddl.SchemaExport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。