本文整理匯總了Java中org.hibernate.tool.hbm2ddl.SchemaExport.execute方法的典型用法代碼示例。如果您正苦於以下問題:Java SchemaExport.execute方法的具體用法?Java SchemaExport.execute怎麽用?Java SchemaExport.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.tool.hbm2ddl.SchemaExport
的用法示例。
在下文中一共展示了SchemaExport.execute方法的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);
}
}
示例2: 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);
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: generate
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
/**
* Method that actually creates the file.
*
* @param dbDialect to use
*/
private void generate(Dialect dialect) {
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
StandardServiceRegistry standardServiceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
for (Class clzz : jpaClasses) {
metadataSources.addAnnotatedClass(clzz);
}
Metadata metadata = metadataSources.buildMetadata();
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
//export.execute(true, false, false, true);
export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
示例7: createSQLSchema
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
private void createSQLSchema(String fileName) throws Exception {
org.hibernate.cfg.Configuration configuration = new Configuration();
Properties properties = new Properties();
properties.putAll(sessionFactoryBean.getJpaPropertyMap());
configuration.setProperties(properties);
configuration.setNamingStrategy(new GizmoNamingStrategy());
System.out.println("Dialect: " + properties.getProperty("hibernate.dialect"));
addAnnotatedClasses("sk.lazyman.gizmo.data", configuration);
SchemaExport export = new SchemaExport(configuration);
export.setOutputFile(fileName);
export.setDelimiter(";");
export.execute(true, false, false, true);
}
示例8: generateCreate
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
@Test
public void generateCreate() throws ClassNotFoundException {
final long now = System.currentTimeMillis() - LAST_MODIFIED_PRECISION;
final Configuration cfg = new Configuration();
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
cfg.setProperty("hibernate.dialect", ORACLE_DIALECT);
cfg.setNamingStrategy(new MyNamingStrategy());
for (final String className : findEntities()) {
cfg.addAnnotatedClass(Class.forName(className));
}
final SchemaExport export = new SchemaExport(cfg);
export.setDelimiter(";");
export.setOutputFile(CREATE_FILE_NAME);
export.execute(true, false, false, true);
File file = new File(CREATE_FILE_NAME);
assertThat(file.lastModified()).as("the file should be generated").isGreaterThan(now);
}
示例9: main
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public static void main(String[] args) {
Ejb3Configuration ejb3Cfg = new Ejb3Configuration();
// set propeties (these were set based on the persistence.xml file)
Properties props = new Properties();
props.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
ejb3Cfg.addProperties(props);
ejb3Cfg.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);
// add annotated classes
ejb3Cfg.addAnnotatedClass(EndUser.class);
ejb3Cfg.addAnnotatedClass(Individual.class);
ejb3Cfg.addAnnotatedClass(Location.class);
ejb3Cfg.addAnnotatedClass(SocialGroup.class);
ejb3Cfg.addAnnotatedClass(Visit.class);
Configuration cfg = ejb3Cfg.getHibernateConfiguration();
SchemaExport se = new SchemaExport(cfg).setOutputFile(RESOURCES_PATH + "specialstudy-schema-ddl.sql");
se.execute(false, false, false, true);
}
示例10: main
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
public static void main(String[] args){
String file = "camping-db-creation.sql";
new File(file).delete();
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder().configure().build());
SchemaExport export = new SchemaExport();
export.setOutputFile(file);
export.setDelimiter(";");
export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}
示例11: generateCreateAnUpdateDDL
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的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);
}
示例12: 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);
}
示例13: 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);
}
示例14: generate
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
private void generate(Dialect dialect) {
cfg.setProperty("hibernate.dialect", dialect.getDialectClass());
SchemaExport export = new SchemaExport(cfg);
export.setDelimiter(";");
export.setOutputFile("_ddl_" + dialect.name().toLowerCase() + ".sql");
export.setFormat(true);
export.execute(true, false, false, false);
}
示例15: createSQLSchema
import org.hibernate.tool.hbm2ddl.SchemaExport; //導入方法依賴的package包/類
private void createSQLSchema(String fileName, String dialect) {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.implicit_naming_strategy", new MidPointImplicitNamingStrategy())
.applySetting("hibernate.physical_naming_strategy", new MidPointPhysicalNamingStrategy())
.applySetting("hibernate.dialect", dialect)
.build());
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", metadata);
metadata.addPackage("com.evolveum.midpoint.repo.sql.type");
SchemaExport export = new SchemaExport();
export.setOutputFile(fileName);
export.setDelimiter(";");
// export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}