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


Java SchemaExport.create方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: exportDatabaseSchema

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
 * Controller method to download a ddl.
 */
@Deprecated
@SuppressWarnings({"unchecked", "rawtypes"})
@RequestMapping(value = "ddl", method = RequestMethod.GET)
public void exportDatabaseSchema(HttpServletRequest request, HttpServletResponse response, Model uiModel) {
	PersistenceUnitInfo persistenceUnitInfo = getEntityManagerFactory().getPersistenceUnitInfo();

	Map jpaPropertyMap = getEntityManagerFactory().getJpaPropertyMap();
	jpaPropertyMap.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
	Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap).getHibernateConfiguration();

	SchemaExport schema = new SchemaExport(configuration);
	schema.setFormat(true);
	schema.setDelimiter(";");
	schema.setOutputFile("/tmp/schema.sql");
	schema.create(false, false);
}
 
開發者ID:tamerman,項目名稱:mobile-starting-framework,代碼行數:20,代碼來源:HomeController.java

示例5: main

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public static void main(String[] args) {
        Configuration hello =new Configuration();

        Properties properties = new Properties();
        properties.setProperty(Environment.DIALECT, MySQL5Dialect.class.getName());
        hello.setProperties(properties);
        hello.addAnnotatedClass(Hello.class);
        hello.addAnnotatedClass(Hello1.class);
        SchemaExport schemaExport = new SchemaExport(hello);
        schemaExport.setDelimiter(";");
//        schemaExport.setOutputFile(String.format("%s_%s.%s ", new Object[] {"ddl", dialect.name().toLowerCase(), "sql" }));
         boolean consolePrint = true;
         boolean exportInDatabase = false;
//         schemaExport.create(consolePrint, exportInDatabase);
        schemaExport.create(Target.SCRIPT);

    }
 
開發者ID:PkayJava,項目名稱:pluggable,代碼行數:18,代碼來源:Hello.java

示例6: main

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Configuration config = new AnnotationConfiguration().configure();

		AnnotationConfiguration config = new AnnotationConfiguration().configure();
		config.addAnnotatedClass(TUser.class)
				.addAnnotatedClass(TGameDetailRecord.class)
				.addAnnotatedClass(TMatch.class)
				.addAnnotatedClass(TMatchType.class)
				.addAnnotatedClass(TResult.class);
		
/*
		config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
		new SchemaExport(cfg, connection);*/
		
		SchemaExport se = new SchemaExport(config);
		se.create(true, true);
	}
 
開發者ID:linzi-zero,項目名稱:billiards,代碼行數:21,代碼來源:MakeTable.java

示例7: testDbSchema

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
@Test
public void testDbSchema() {
    MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder()
                    .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").build());

    metadata.addAnnotatedClass(ConsoleEntity.class);
    metadata.addAnnotatedClass(GameEntity.class);
    metadata.addAnnotatedClass(UserEntity.class);
    metadata.addAnnotatedClass(RoleEntity.class);
    metadata.addAnnotatedClass(LibraryEntity.class);
    metadata.addAnnotatedClass(BorrowEntity.class);

    SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata());
    export.create(Target.SCRIPT);
}
 
開發者ID:MannanM,項目名稱:corporate-game-share,代碼行數:16,代碼來源:SchemaTranslator.java

示例8: generateSchema

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
 * Generate schema.
 */
public void generateSchema() {
	Configuration config;
	try {
		config = this.getHibernateConfig();
		final Session session = this.getHibernateSession();
		final Transaction tx = session.beginTransaction();
		final SchemaExport sch = new SchemaExport(config);
		sch.create(true, true);
		tx.commit();
	}
	catch (final Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:leonarduk,項目名稱:unison,代碼行數:18,代碼來源:HibernateHelper.java

示例9: testSchemaExport

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
@Test
public void testSchemaExport() {
	ServiceRegistry serviceRegistry =
		new StandardServiceRegistryBuilder().configure().build();

	MetadataImplementor metadataImplementor =
		(MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();

	SchemaExport schemaExport = new SchemaExport(serviceRegistry, metadataImplementor);
	schemaExport.create(true, true);
}
 
開發者ID:bejondshao,項目名稱:personal,代碼行數:12,代碼來源:ORMappingTest.java

示例10: testSchemaTools

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public void testSchemaTools() throws Exception{
	// database schema have been created thanks to the setUp method
	// we have 2 schemas SA et SB, SB must be set as the default schema
	// used by hibernate hibernate.default_schema SB
	SchemaExport se = new SchemaExport(getCfg());
	se.create(true,true);
	
	// here we modify the generated table in order to test SchemaUpdate
	Session session = openSession();
	Connection conn = session.connection();
	Statement stat = conn.createStatement();
	stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
	
	// update schema
	SchemaUpdate su = new SchemaUpdate(getCfg());
	su.execute(true,true);
	
	// we can run schema validation. Note that in the setUp method a *wrong* table
	// has been created with different column names
	// if schema validator chooses the bad db schema, then the testcase will fail (exception)
	SchemaValidator sv = new SchemaValidator(getCfg());
	sv.validate();
	
	// it's time to clean our database
	se.drop(true,true);
	
	// then the schemas and false table.

	stat.execute("DROP TABLE \"SA\".\"Team\" ");
	stat.execute(" DROP SCHEMA sa ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:35,代碼來源:TestSchemaTools.java

示例11: testSchemaToolsNonQuote

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public void testSchemaToolsNonQuote() throws Exception{
	// database schema have been created thanks to the setUp method
	// we have 2 schemas SA et SB, SB must be set as the default schema
	// used by hibernate hibernate.default_schema SB
	SchemaExport se = new SchemaExport(getCfg());
	se.create(true,true);
	
	// here we modify the generated table in order to test SchemaUpdate
	Session session = openSession();
	Connection conn = session.connection();
	Statement stat = conn.createStatement();
	stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
	
	// update schema
	SchemaUpdate su = new SchemaUpdate(getCfg());
	su.execute(true,true);
	
	// we can run schema validation. Note that in the setUp method a *wrong* table
	// has been created with different column names
	// if schema validator chooses the bad db schema, then the testcase will fail (exception)
	SchemaValidator sv = new SchemaValidator(getCfg());
	sv.validate();
	
	// it's time to clean our database
	se.drop(true,true);
	
	// then the schemas and false table.

	stat.execute("DROP TABLE \"SA\".\"Team\" ");
	stat.execute(" DROP SCHEMA sa ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:35,代碼來源:TestSchemaTools.java

示例12: testFailingQuoteValidation

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public void testFailingQuoteValidation() throws Exception{
	// database schema have been created thanks to the setUp method
	// we have 2 schemas SA et SB, SB must be set as the default schema
	// used by hibernate hibernate.default_schema SB
	SchemaExport se = new SchemaExport(getCfg());
	se.create(true,true);
	
	// here we modify the generated table in order to test SchemaUpdate
	Session session = openSession();
	Connection conn = session.connection();
	Statement stat = conn.createStatement();
	stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
	
	// update schema
	//SchemaUpdate su = new SchemaUpdate(getCfg());
	//su.execute(true,true);
	
	try {
		SchemaValidator sv = new SchemaValidator(getCfg());
		sv.validate();
		fail("should fail since we mutated the current schema.");
	} catch(HibernateException he) {
		
	}
	
	// it's time to clean our database
	se.drop(true,true);
	
	// then the schemas and false table.

	stat.execute("DROP TABLE \"SA\".\"Team\" ");
	stat.execute(" DROP SCHEMA sa ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:37,代碼來源:TestSchemaTools.java

示例13: testFailingNonQuoteValidation

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public void testFailingNonQuoteValidation() throws Exception{
	// database schema have been created thanks to the setUp method
	// we have 2 schemas SA et SB, SB must be set as the default schema
	// used by hibernate hibernate.default_schema SB
	SchemaExport se = new SchemaExport(getCfg());
	se.create(true,true);
	
	// here we modify the generated table in order to test SchemaUpdate
	Session session = openSession();
	Connection conn = session.connection();
	Statement stat = conn.createStatement();
	stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
	
	// update schema
	//SchemaUpdate su = new SchemaUpdate(getCfg());
	//su.execute(true,true);
	
	try {
		SchemaValidator sv = new SchemaValidator(getCfg());
		sv.validate();
		fail("should fail since we mutated the current schema.");
	} catch(HibernateException he) {
		
	}
	
	// it's time to clean our database
	se.drop(true,true);
	
	// then the schemas and false table.

	stat.execute("DROP TABLE \"SA\".\"Team\" ");
	stat.execute(" DROP SCHEMA sa ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:37,代碼來源:TestSchemaTools.java

示例14: configureAndGenerate

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
 * Method to configure necessary hibernate properties and generate DDL for a supplied configuration
 * @param dialectName Which hibernate dialect should be used
 * @param destinationDirectory The output directory
 * @param outputFileName The output filename
 * @param configuration The hibernate configuration setup with the appropriate schema objects
 */
private void configureAndGenerate(final String dialectName, final String destinationDirectory, final String outputFileName,
		final Configuration configuration)
{
	final Properties dialect = new Properties();
	dialect.setProperty("hibernate.dialect", dialectName);
	configuration.addProperties(dialect);

	final SchemaExport se = new SchemaExport(configuration);
	se.setOutputFile(destinationDirectory + outputFileName);
	se.setDelimiter(";\n");
	se.create(true, false);
}
 
開發者ID:danielhams,項目名稱:mad-java,代碼行數:20,代碼來源:GeneratorHelper.java

示例15: exportDDLtoFile

import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
 * Write database configuration to file. Includes differences to existing database. Filename: "database/setupDatabase.sql"
 */
private static void exportDDLtoFile() {
    String outputFile = "database/setupDatabase.sql";

    boolean script = true; // write DDL
    boolean export = false; // don't update databse
    try {
        SchemaExport se = new SchemaExport(cf);
        se.setOutputFile(outputFile);
        se.setDelimiter(";");
        se.create(script, export);
    } catch (Exception e) {
        log.error("DDL export to file failed: Reason: ", e);
    }
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:18,代碼來源:DatabaseSetup.java


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