本文整理匯總了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 );
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
}