Moving from persistence.xml to ConfigurationAdmin [message #1016269] |
Tue, 05 March 2013 13:25  |
Eclipse User |
|
|
|
I was dealing with this problem: http://www.eclipse.org/forums/index.php/t/457852/
and probably came to a solution. As I described on the other topic, I need to create plug-ins to some clients, and these plug-ins will create new tables on our base. I just created a fragment with these new models, and need to make the 'core' plugin scan this fragment too, and add those classes to the current persitent unit...
I came across Standalone Configuration (http://wiki.eclipse.org/Gemini/JPA/Documentation/OtherTopics#Standalone_Configuration) but I need to know how to make this works with our current code...by now, we have a persitence.xml file, and a EntityManagerHelper class that creates the EMF and the EM too, like this
package br.com.germantech.ecf.infraestrutura.persistencia.entityManager;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.apache.log4j.Logger;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.config.TargetDatabase;
import org.eclipse.persistence.internal.jpa.EntityManagerImpl;
import org.eclipse.persistence.jpa.PersistenceProvider;
import org.eclipse.persistence.sessions.UnitOfWork;
import org.postgresql.Driver;
import br.com.germantech.ecf.Bootstrap;
import br.com.germantech.ecf.aplicacao.helpers.PropertiesHelper;
public abstract class GermantechEntityManager {
private static Logger log = Logger.getLogger(GermantechEntityManager.class);
private static EntityManagerFactory emf = null;
private static Map<String, Object> properties = new HashMap<String, Object>();
private static UnitOfWork uow;
private static final ThreadLocal<EntityManager> ENTITY_MANAGER_CACHE = new ThreadLocal<EntityManager>();
private synchronized static void init() {
properties.put(PersistenceUnitProperties.TARGET_DATABASE, TargetDatabase.PostgreSQL);
properties.put(PersistenceUnitProperties.JDBC_DRIVER, Driver.class.getCanonicalName());
properties.put(PersistenceUnitProperties.JDBC_URL, PropertiesHelper.getProperty(PropertiesHelper.URL));
properties.put(PersistenceUnitProperties.JDBC_USER, PropertiesHelper.getProperty(PropertiesHelper.USUARIO));
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, PropertiesHelper.getProperty(PropertiesHelper.SENHA));
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MIN, "1");
properties.put(PersistenceUnitProperties.CONNECTION_POOL_MAX, "10");
properties.put(PersistenceUnitProperties.CACHE_STATEMENTS, "true");
properties.put(PersistenceUnitProperties.BATCH_WRITING, "JDBC");
properties.put(PersistenceUnitProperties.CLASSLOADER, Bootstrap.class.getClassLoader());
// Cria tabelas novas (mas não atualiza)
if("true".equalsIgnoreCase(PropertiesHelper.getProperty(PropertiesHelper.GERAR_TABELAS))){
log.info("Gerando tabelas...");
properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_OR_EXTEND);
}
// Cria os arquivos de geração do banco de dados
// properties.put(PersistenceUnitProperties.CREATE_JDBC_DDL_FILE, "createDDL_ddlGeneration.jdbc");
// properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_BOTH_GENERATION);
properties.put("eclipselink.logging.level", "FINE");
properties.put("eclipselink.logging.timestamp", "true");
properties.put("eclipselink.logging.session", "true");
properties.put("eclipselink.logging.thread", "true");
properties.put("eclipselink.logging.exceptions", "true");
emf = new PersistenceProvider().createEntityManagerFactory("gtech", properties);
}
/**
* Retorna um {@link EntityManager}. Caso não exista, cria um novo
*/
public synchronized static EntityManager getEntityManager() {
EntityManager entityManager = ENTITY_MANAGER_CACHE.get();
if (entityManager == null) {
log.info("entityManager é null");
init();
ENTITY_MANAGER_CACHE.set(entityManager = emf.createEntityManager());
}
return entityManager;
}
}
any idea is much appreciated
[Updated on: Tue, 05 March 2013 13:29] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04439 seconds