br.com.andrewribeiro.ribrest.dao.abstracts.AbstractPersistenceCenter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Ribrest Show documentation
Show all versions of Ribrest Show documentation
Ribrest Framework - A simple Java framework that truly improve your productivity when developing restful based webservices.
package br.com.andrewribeiro.ribrest.dao.abstracts;
import br.com.andrewribeiro.ribrest.dao.interfaces.CRUD;
import br.com.andrewribeiro.ribrest.dao.interfaces.DAO;
import br.com.andrewribeiro.ribrest.dao.interfaces.PersistenceCenter;
import br.com.andrewribeiro.ribrest.exceptions.RibrestDefaultException;
import br.com.andrewribeiro.ribrest.exceptions.RibrestDefaultExceptionConstants;
import br.com.andrewribeiro.ribrest.exceptions.RibrestDefaultExceptionFactory;
import br.com.andrewribeiro.ribrest.services.FlowContainer;
import br.com.andrewribeiro.ribrest.utils.RibrestUtils;
import javax.inject.Inject;
import org.glassfish.hk2.api.ServiceLocator;
/**
*
* @author Andrew Ribeiro
*/
public abstract class AbstractPersistenceCenter implements PersistenceCenter {
private DAO dao;
protected Class daoClass;
@Inject
private ServiceLocator sl;
@Inject
FlowContainer fc;
@Override
public void perform() throws RibrestDefaultException{
dao = this.create();
sl.inject(dao);
sl.postConstruct(dao);
try {
dao.perform();
} catch(IllegalArgumentException e){
throw RibrestDefaultExceptionFactory.getRibrestDefaultException(RibrestDefaultExceptionConstants.RESOURCE_ISNT_AN_ENTITY, RibrestUtils.getResourceName(fc.getModel().getClass()));
}
}
@Override
public void setCurrentDAOClass(Class daoClass) {
this.daoClass = daoClass;
}
}