List of usage examples for org.hibernate.tool.hbm2ddl SchemaExport drop
public void drop(EnumSet<TargetType> targetTypes, Metadata metadata)
From source file:com.yahoo.elide.datastores.hibernate5.HibernateDataStoreSupplier.java
License:Apache License
@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 {/*from w w w . j av a 2 s.co m*/ 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 HibernateStore(metadataImplementor.buildSessionFactory(), true, ScrollMode.FORWARD_ONLY); }
From source file:com.yahoo.elide.datastores.hibernate5.HibernateEntityManagerDataStoreSupplier.java
License:Apache License
@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); Map<String, Object> options = new HashMap<>(); ArrayList<Class> bindClasses = new ArrayList<>(); try {/* w w w . jav a 2s .co m*/ bindClasses.addAll(ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class)); } catch (MappingException e) { throw new IllegalStateException(e); } options.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); options.put("javax.persistence.jdbc.url", JDBC_PREFIX + System.getProperty(MYSQL_PORT_PROPERTY, MYSQL_PORT) + JDBC_SUFFIX); options.put("javax.persistence.jdbc.user", ROOT); options.put("javax.persistence.jdbc.password", ROOT); options.put(AvailableSettings.LOADED_CLASSES, bindClasses); EntityManagerFactory emf = Persistence.createEntityManagerFactory("elide-tests", options); HibernateEntityManager em = (HibernateEntityManager) emf.createEntityManager(); // 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_PREFIX + System.getProperty(MYSQL_PORT_PROPERTY, MYSQL_PORT) + JDBC_SUFFIX) .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 IllegalStateException(e); } MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata(); EnumSet<TargetType> type = EnumSet.of(TargetType.DATABASE); // create example tables from beans SchemaExport schemaExport = new SchemaExport(); schemaExport.drop(type, metadataImplementor); schemaExport.execute(type, SchemaExport.Action.CREATE, metadataImplementor); if (!schemaExport.getExceptions().isEmpty()) { throw new IllegalStateException(schemaExport.getExceptions().toString()); } return new AbstractHibernateStore.Builder(em).withScrollEnabled(true) .withScrollMode(ScrollMode.FORWARD_ONLY).build(); }
From source file:com.yahoo.elide.datastores.multiplex.bridgeable.BridgeableStoreSupplier.java
License:Apache License
@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()); }//from w ww. j a v a 2 s . c o m LATEST_HIBERNATE_STORE = new HibernateStore.Builder(metadataImplementor.buildSessionFactory()) .withScrollEnabled(true).withScrollMode(ScrollMode.FORWARD_ONLY).build(); BridgeableRedisStore hbaseStore = new BridgeableRedisStore(); return new MultiplexManager(LATEST_HIBERNATE_STORE, hbaseStore); }
From source file:com.yahoo.elide.hibernate.AHibernateTest.java
License:Apache License
protected static void databaseManagerInit() { // method to force class initialization Configuration c = new Configuration(); try {//from ww w. j a v a2s . c o m ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class).forEach(c::addAnnotatedClass); } catch (MappingException e) { throw new RuntimeException(e); } sessionFactory = c.configure("hibernate.cfg.xml") .setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread") .setProperty(Environment.URL, "jdbc:mysql://localhost:" + System.getProperty("mysql.port", "3306") + "/root") .setProperty(Environment.USER, "root").setProperty(Environment.PASS, "root").buildSessionFactory(); // create Example tables from beans SchemaExport se = new SchemaExport(c).setHaltOnError(true); se.drop(false, true); se.execute(false, true, false, true); if (se.getExceptions().size() != 0) { throw new RuntimeException("" + se.getExceptions()); } hibernateManager = new HibernateManager(sessionFactory); }
From source file:gov.nih.nci.cabig.ctms.acegi.csm.AbstractCSMTestCase.java
License:BSD License
public void setUp() throws Exception { Configuration cfg = new Configuration().configure(new File("src/test/resources/hibernate.cfg.xml")); SchemaExport se = new SchemaExport(cfg); try {/*from w ww .j av a 2 s .c om*/ se.drop(false, true); } catch (Exception ex) { } se.create(false, true); super.setUp(); }
From source file:org.eclipse.emf.cdo.server.internal.hibernate.HibernatePackageHandler.java
License:Open Source License
@Override protected void doDeactivate() throws Exception { if (sessionFactory != null) { sessionFactory.close();/*from w w w .j ava 2 s .co m*/ sessionFactory = null; } if (doDropSchema) { final SchemaExport se = new SchemaExport(configuration); se.drop(false, true); } configuration = null; super.doDeactivate(); }
From source file:org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.java
License:Open Source License
@Override protected void doDeactivate() throws Exception { Configuration configuration = null; if (cdoDataStore != null) { configuration = cdoDataStore.getConfiguration(); if (TRACER.isEnabled()) { TRACER.trace("Closing SessionFactory"); //$NON-NLS-1$ }//ww w .j av a 2 s . co m cdoDataStore.close(); } // and now do the drop action if (configuration != null && doDropSchema) { final SchemaExport se = new SchemaExport(configuration); se.drop(false, true); } cdoDataStore = null; hibernateAuditHandler = null; // get rid of the audit epackages if (auditEPackages != null) { for (EPackage ePackage : auditEPackages) { getRepository().getPackageRegistry().remove(ePackage.getNsURI()); } auditEPackages = null; } LifecycleUtil.deactivate(packageHandler, OMLogger.Level.WARN); super.doDeactivate(); }
From source file:org.evolizer.core.hibernate.session.EvolizerSessionHandler.java
License:Apache License
/** * Drops the database schema. Can only be executed when session is closed. * //w w w .ja va2s .co m * @param properties Database connection properties * @throws EvolizerException */ public void dropSchema(Properties properties) throws EvolizerException { try { AnnotationConfiguration configuration = configureDataBaseConnection(properties); SchemaExport exporter = new SchemaExport(configuration); exporter.drop(false, true); } catch (HibernateException he) { throw new EvolizerException(he); } }
From source file:org.geolatte.common.cql.hibernate.HibernateUtil.java
License:Open Source License
public void createDatabase() { SchemaExport e = new SchemaExport(configuration); e.drop(true, true); e.create(true, true); }
From source file:org.glite.security.voms.admin.persistence.deployer.SchemaDeployer.java
License:Apache License
private void doUndeploy() { checkVoExistence();/*from w w w .j a v a 2 s . com*/ log.info("Undeploying voms database..."); int existingDB = checkDatabaseExistence(); if (existingDB == 1) { log.error( "This tool cannot undeploy voms-admin 1.2.x database! Please upgrade to voms-admin 2 or use voms-admin-configure 1.2.x tools to undeploy this database."); System.exit(-1); } if (existingDB == 2) { log.error( "This tool cannot undeploy voms-admin 2.0.x databases! Please either upgrade the database to voms-admin 2.5 (using this tool) or use voms-admin-configure 2.0.x" + " tools to undeploy this database"); System.exit(-1); } if (existingDB < 0) { log.error("No voms-admin database found!"); System.exit(-1); } checkDatabaseWritable(); SchemaExport export = new SchemaExport(); EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.DATABASE); Metadata md = getHibernateMetadataSources().getMetadataBuilder().build(); export.drop(targetTypes, md); @SuppressWarnings("rawtypes") List l = export.getExceptions(); if (!l.isEmpty()) { log.error("Error undeploying voms database!"); printExceptions(l); System.exit(2); } log.info("Database undeployed correctly!"); }