Galera,
preciso da ajuda de vc´s, estou com um problema.
A minha aplicação roda em paralelo varios processamentos, e para cada classe(que inicia um processamento, por essa razão tb não posso criar o EntiTyManager como static, o q resolveria meu problema.), e inicia uma transação. Ate aqui td bem, so que dentro desse metodos eu tenho que registrar as interfaces DAO, para fazer o insert então faço o seguinte.
private static ArquivosDao arquivosDao;
this.arquivosDao = (ArquivosDao) factory.getDao(ArquivosDao.class);
onde ele executa essa classe.
public CrudDAO getDao(Class<? extends CrudDAO> iface) {
Class<?> impl = mappedImpl.get(iface);
CrudDAO dao = null;
try {
if (impl == null){
throw new RuntimeException("Implementacao nao existe para a interface = "+iface.getName());
}
dao = (CrudDAO) impl.newInstance();
} catch (Exception e) {
// TODO: handle exception
}
return dao;
}
so que cada vez que ele chama esse metodo ele cria uma nova instância da classe, ficando o Dao em outra transação. e sendo assim não consigo dar commit.
Então tentei usar esse metodo abaixo, so que o mesmo nem chega a resgistar o Dao e me retorna uma exception.
@SuppressWarnings("unchecked")
public <T extends CrudDAO> T getDaos(Class<T> daoInterface) throws DAOException{
T dao = null;
String daoPackage = daoInterface.getPackage().getName() + "." + getPrefixoImpl();
String daoInterfaceName = daoInterface.getSimpleName();
String daoClassSimpleName = getPrefixoImpl().substring(0, 1).toUpperCase().concat( getPrefixoImpl().substring(1) ) + daoInterfaceName;
String daoClassName = daoPackage + "." + daoClassSimpleName;
logger.debug("Implementação solicitada para o DAO: "+ daoClassName);
try {
daoClassName = "br.com.digicon.dao.LinhaDao";
//daoClassName = daoInterface.getCanonicalName();
Class daoClass = Class.forName( daoClassName);
dao = (T) daoClass.getConstructor(getRepositoryTypes()).newInstance(getRepositoryArgs());
} catch (IllegalArgumentException e) {
throw new DAOException(e);
} catch (SecurityException e) {
throw new DAOException(e);
} catch (InstantiationException e) {
throw new DAOException(e);
} catch (IllegalAccessException e) {
throw new DAOException(e);
} catch (InvocationTargetException e) {
throw new DAOException(e);
} catch (NoSuchMethodException e) {
throw new DAOException(e);
}
catch (ClassNotFoundException e) {
throw new DAOException(e);
}
return dao;
}
@Override
protected String getPrefixoImpl() {
return "jpa";
}
@Override
protected Object[] getRepositoryArgs() {
return new Object[]{
manager
};
}
@Override
protected Class[] getRepositoryTypes() {
return new Class[]{
EntityManagerImpl.class
};
}
Obrigado, fica aguardando a ajuda de vc´s.
Obrigado.