List of usage examples for org.hibernate.boot.spi MetadataImplementor buildSessionFactory
SessionFactory buildSessionFactory();
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 ww w. j a va 2 s . c o 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.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);/*ww w . j a v a 2s . c om*/ schemaExport.execute(false, true, false, true); if (!schemaExport.getExceptions().isEmpty()) { throw new RuntimeException(schemaExport.getExceptions().toString()); } 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); }