org.apache.openjpa.persistence.OpenJPAEntityManagerFactory Java Examples

The following examples show how to use org.apache.openjpa.persistence.OpenJPAEntityManagerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAHasBeanManagerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public OpenJPAEntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo pui, final Map m) {
    MAP = m;
    // only works cause of lazy property
    final BeanManager beanManager = BeanManager.class.cast(m.get("javax.persistence.bean.manager"));
    assertNotNull(beanManager.getReference(beanManager.resolve(beanManager.getBeans(Dao.class)), Dao.class, null));
    // just delegate to openjpa since we don't aim at reimplementing JPA in a test ;)
    return super.createContainerEntityManagerFactory(pui, m);
}
 
Example #2
Source File: Ddl.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean execute(String type) throws Exception {

		// List<String> containerEntityNames = new ArrayList<>();
		// containerEntityNames.addAll((List<String>)
		// Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
		// List<String> classNames =
		// ListTools.includesExcludesWildcard(containerEntityNames,
		// Config.dumpRestoreData().getIncludes(),
		// Config.dumpRestoreData().getExcludes());
		// File persistence = new File(Config.dir_local_temp_classes(),
		// "META-INF/persistence.xml");
		// PersistenceXmlHelper.writeForDdl(persistence.getAbsolutePath());
		// String[] arguments = new String[4];
		// arguments[0] = "-schemaAction";
		// arguments[1] = StringUtils.equals(type ,"create")? "build":"add";
		// arguments[2] = "-sql";
		// arguments[3] = Config.dir_local_temp_sql(true) + "/" + type + ".sql";
		// MappingTool.main(arguments);
		// return true;
		String flag = "build";
		if (StringUtils.equalsIgnoreCase(type, "createDB")) {
			flag = "createDB";
		} else if (StringUtils.equalsIgnoreCase(type, "dropDB")) {
			flag = "dropDB";
		} else if (StringUtils.equalsIgnoreCase(type, "drop")) {
			flag = "drop";
			// } else if (StringUtils.equalsIgnoreCase(type, "deleteTableContents")) {
			// flag = "deleteTableContents";
		}
		List<String> containerEntityNames = new ArrayList<>();
		containerEntityNames.addAll((List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
		List<String> classNames = ListTools.includesExcludesWildcard(containerEntityNames,
				Config.dumpRestoreData().getIncludes(), Config.dumpRestoreData().getExcludes());
		File persistence = new File(Config.dir_local_temp_classes(), "persistence_sql.xml");
		PersistenceXmlHelper.writeForDdl(persistence.getAbsolutePath());
		OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory("enhance",
				persistence.getName());
		EntityManagerImpl em = (EntityManagerImpl) emf.createEntityManager();
		String[] arguments = null;
		String[] args = null;
		Options opts = new Options();
		if (StringUtils.equals(flag, "build") || StringUtils.equals(flag, "drop")
				|| StringUtils.equals(flag, "createDB") || StringUtils.equals(flag, "dropDB")) {
			arguments = new String[4];
			File file = new File(Config.dir_local_temp_sql(true), flag + ".sql");
			arguments[0] = "-schemaAction";
			arguments[1] = flag;
			arguments[2] = "-sql";
			arguments[3] = file.getAbsolutePath();
			args = opts.setFromCmdLine(arguments);
			MappingTool.run((JDBCConfiguration) em.getConfiguration(), args, opts, null);
			logger.print("file : {}.", file.getAbsolutePath());
		} else if (StringUtils.equals(flag, "deleteTableContents")) {
			// arguments = new String[2];
			// arguments[0] = "-schemaAction";
			// arguments[1] = flag;
			// args = opts.setFromCmdLine(arguments);
			// MappingTool.run((JDBCConfiguration) em.getConfiguration(), args, opts, null);
			// logger.print("delete all table contents.");
		}
		em.close();
		emf.close();
		return true;
	}
 
Example #3
Source File: OpenJpaEntityManagerFactoryIntegrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void testCanCastNativeEntityManagerFactoryToOpenJpaEntityManagerFactoryImpl() {
	EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
	assertTrue("native EMF expected", emfi.getNativeEntityManagerFactory() instanceof OpenJPAEntityManagerFactory);
}