本文整理汇总了Java中org.hibernate.tool.hbm2ddl.SchemaUpdate.execute方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaUpdate.execute方法的具体用法?Java SchemaUpdate.execute怎么用?Java SchemaUpdate.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.tool.hbm2ddl.SchemaUpdate
的用法示例。
在下文中一共展示了SchemaUpdate.execute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleColumnAddition
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的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() );
}
示例2: schemaExport
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的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);
}
}
示例3: generateCreateAnUpdateDDL
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的package包/类
@Test
public void generateCreateAnUpdateDDL() throws IOException {
logger.debug("Generate create and update DDL");
EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) lcemfb.getNativeEntityManagerFactory();
SessionFactoryImpl sf = emf.getSessionFactory();
SessionFactoryServiceRegistryImpl serviceRegistry = (SessionFactoryServiceRegistryImpl) sf.getServiceRegistry();
Configuration cfg = null;
try {
Field field = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration");
field.setAccessible(true);
cfg = (Configuration) field.get(serviceRegistry);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
Files.createDirectories(Paths.get("target/db/migration/"));
SchemaUpdate update = new SchemaUpdate(serviceRegistry, cfg);
update.setDelimiter(";");
update.setOutputFile("target/db/migration/Vx__yy_zz.sql");
update.execute(false, false);
SchemaExport export = new SchemaExport(serviceRegistry, cfg);
export.setDelimiter(";");
export.setOutputFile("target/db/migration/create.sql");
export.execute(false, false, false, true);
}
示例4: testSchemaTools
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的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();
}
示例5: testSchemaToolsNonQuote
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的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();
}
示例6: updateSchema
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的package包/类
/** Updates the current DB-Schema with the schema defined by the hbm.xml files.
*
* @param script Print the DDL to the console.
* @param export
*/
public void updateSchema(Configuration cfg, boolean script, boolean export) {
try {
SchemaUpdate exp = new SchemaUpdate(cfg);
exp.execute(script, export);
} catch (HibernateException ex) {
log.fatal("Cant't update database schema: " + ex.getMessage(), ex);
return;
}
}
示例7: main
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的package包/类
public static void main(String[] args) {
File currentDirectory = new File("");
File config = new File(currentDirectory.getAbsolutePath() + File.separatorChar + RESOURCES_PATH + "hibernate.cfg.xml");
Configuration cfg = new AnnotationConfiguration();
cfg.configure(config);
SchemaUpdate se = new SchemaUpdate(cfg);
se.setOutputFile(RESOURCES_PATH + "openhds-schema-update.sql");
se.execute(false, false);
}
示例8: main
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
Configuration configuration = new Configuration();
configuration
.configure("/br/com/dlp/jazzqa/hibernateLocal.cfg.xml");
SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
schemaUpdate.execute(true, true);
} catch (HibernateException e) {
e.printStackTrace();
}
}
示例9: updateTable
import org.hibernate.tool.hbm2ddl.SchemaUpdate; //导入方法依赖的package包/类
public static void updateTable(String[] args) {
Configuration config = new Configuration().configure();
SchemaUpdate su = new SchemaUpdate(config);
su.execute(true, true);
}