本文整理汇总了Java中org.hibernate.tool.hbm2ddl.SchemaExport.drop方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaExport.drop方法的具体用法?Java SchemaExport.drop怎么用?Java SchemaExport.drop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.tool.hbm2ddl.SchemaExport
的用法示例。
在下文中一共展示了SchemaExport.drop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: get
import org.hibernate.tool.hbm2ddl.SchemaExport; //导入方法依赖的package包/类
@Override
public DataStore get() {
// method to force class initialization
MetadataSources metadataSources = new MetadataSources(
new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml")
.applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
.applySetting(Environment.URL, "jdbc:mysql://localhost:"
+ System.getProperty("mysql.port", "3306")
+ "/root?serverTimezone=UTC")
.applySetting(Environment.USER, "root")
.applySetting(Environment.PASS, "root")
.build());
metadataSources.addAnnotatedClass(HibernateUser.class);
MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata();
// create example tables from beans
SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true);
schemaExport.drop(false, true);
schemaExport.execute(false, true, false, true);
if (!schemaExport.getExceptions().isEmpty()) {
throw new RuntimeException(schemaExport.getExceptions().toString());
}
LATEST_HIBERNATE_STORE = new AbstractHibernateStore.Builder(metadataImplementor.buildSessionFactory())
.withScrollEnabled(true)
.withScrollMode(ScrollMode.FORWARD_ONLY)
.build();
BridgeableRedisStore hbaseStore = new BridgeableRedisStore();
return new MultiplexManager(LATEST_HIBERNATE_STORE, hbaseStore);
}
示例6: get
import org.hibernate.tool.hbm2ddl.SchemaExport; //导入方法依赖的package包/类
@Override
public DataStore get() {
// Add additional checks to our static check mappings map.
// NOTE: This is a bit hacky. We need to do a major overhaul on our test architecture
TestCheckMappings.MAPPINGS.put("filterCheck", Filtered.FilterCheck.class);
TestCheckMappings.MAPPINGS.put("filterCheck3", Filtered.FilterCheck3.class);
// method to force class initialization
Configuration configuration = new Configuration();
try {
ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class)
.forEach(configuration::addAnnotatedClass);
} catch (MappingException e) {
throw new RuntimeException(e);
}
SessionFactory sessionFactory = configuration.configure("hibernate.cfg.xml")
.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
.setProperty(Environment.URL, "jdbc:mysql://localhost:"
+ System.getProperty("mysql.port", "3306")
+ "/root?serverTimezone=UTC")
.setProperty(Environment.USER, "root")
.setProperty(Environment.PASS, "root")
.buildSessionFactory();
// create example tables from beans
SchemaExport schemaExport = new SchemaExport(configuration).setHaltOnError(true);
schemaExport.drop(false, true);
schemaExport.execute(false, true, false, true);
if (!schemaExport.getExceptions().isEmpty()) {
throw new RuntimeException(schemaExport.getExceptions().toString());
}
return new HibernateStore(sessionFactory, true, ScrollMode.FORWARD_ONLY);
}
示例7: get
import org.hibernate.tool.hbm2ddl.SchemaExport; //导入方法依赖的package包/类
@Override
public DataStore get() {
// Add additional checks to our static check mappings map.
// NOTE: This is a bit hacky. We need to do a major overhaul on our test architecture
TestCheckMappings.MAPPINGS.put("filterCheck", Filtered.FilterCheck.class);
TestCheckMappings.MAPPINGS.put("filterCheck3", Filtered.FilterCheck3.class);
// method to force class initialization
MetadataSources metadataSources = new MetadataSources(
new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml")
.applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
.applySetting(Environment.URL, "jdbc:mysql://localhost:"
+ System.getProperty("mysql.port", "3306")
+ "/root?serverTimezone=UTC")
.applySetting(Environment.USER, "root")
.applySetting(Environment.PASS, "root")
.build());
try {
ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class)
.forEach(metadataSources::addAnnotatedClass);
} catch (MappingException e) {
throw new RuntimeException(e);
}
MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata();
// create example tables from beans
SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true);
schemaExport.drop(false, true);
schemaExport.execute(false, true, false, true);
if (!schemaExport.getExceptions().isEmpty()) {
throw new RuntimeException(schemaExport.getExceptions().toString());
}
return new AbstractHibernateStore.Builder(metadataImplementor.buildSessionFactory())
.withScrollEnabled(true)
.withScrollMode(ScrollMode.FORWARD_ONLY)
.build();
}