Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JavaBeanStack FrameWork
*
* Copyright (C) 2017 Jorge Enciso
* Email: [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.javabeanstack.services;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.JoinColumn;
import javax.persistence.Query;
import org.apache.log4j.Logger;
import org.javabeanstack.error.ErrorManager;
import org.javabeanstack.error.IErrorReg;
import org.javabeanstack.exceptions.SessionError;
import org.javabeanstack.security.IUserSession;
import org.javabeanstack.data.DataInfo;
import org.javabeanstack.data.DataResult;
import org.javabeanstack.data.IDataResult;
import org.javabeanstack.data.IDataRow;
import org.javabeanstack.annotation.CheckMethod;
import org.javabeanstack.data.IDBConnectFactory;
import org.javabeanstack.data.IDBManager;
import org.javabeanstack.data.IDataObject;
import org.javabeanstack.data.IDataSet;
import org.javabeanstack.data.IGenericDAO;
import org.javabeanstack.error.ErrorReg;
import org.javabeanstack.util.Fn;
/**
* Esta clase deriva de AbstractDAO, a travéz de ella se recupera, válida y se
* graban los registros en la base de datos. Es un ejb que se ejecuta en la capa
* de la lógica del negocio.
*
* El test unitario se encuentra en TestProjects clase
* py.com.oym.test.data.TestDataService
*
* @author Jorge Enciso
*/
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public abstract class AbstractDataService implements IDataService {
private static final Logger LOGGER = Logger.getLogger(AbstractDataService.class);
protected List methodList = this.setListCheckMethods();
@EJB
protected IGenericDAO dao;
/**
* Devuelve la unidad de persistencia asociado a la empresa en la cual
* inicio sesión el usuario.
*
* @param sessionId identificador de la sesión.
* @return unidad de persistencia.
*/
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
protected String getPersistentUnit(String sessionId) {
IUserSession userSession = getUserSession(sessionId);
if (userSession == null || userSession.getUser() == null) {
return null;
}
return userSession.getPersistenceUnit();
}
@Override
public IUserSession getUserSession(String sessionId) {
return dao.getUserSession(sessionId);
}
@Override
public Map getEntityManagerProp(String persistUnit) {
return dao.getEntityManagerProp(persistUnit);
}
@Override
public Map getPersistUnitProp(String persistUnit) {
return dao.getPersistUnitProp(persistUnit);
}
@Override
public String getDataEngine(String persistentUnit) {
return dao.getDataEngine(persistentUnit);
}
@Override
public String getSchema(String persistentUnit) {
return dao.getSchema(persistentUnit);
}
/**
* Genera una lista de los metodos que existen con el proposito de validar
* datos.
*
* @return lista de metodos.
*/
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
protected final List setListCheckMethods() {
List methods = new ArrayList();
for (Method method : this.getClass().getDeclaredMethods()) {
CheckMethod anotation = method.getAnnotation(CheckMethod.class);
/* Ejecutar los metodos cuyo nombre inician con check */
if (anotation != null) {
methods.add(method);
}
}
return methods;
}
// TODO ver este metodo.
@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public T setListFieldCheck(T row) {
if (row != null && row.getFieldChecked() == null) {
String fieldName;
String key;
String namePrefix;
CheckMethod anotation;
Map fieldChecked = new HashMap<>();
for (Method method : this.getClass().getDeclaredMethods()) {
namePrefix = method.getName().toLowerCase().substring(0, 5);
anotation = method.getAnnotation(CheckMethod.class);
if ("check".equals(namePrefix) || anotation != null) {
if (anotation == null) {
fieldName = method.getName().toLowerCase().substring(5);
} else {
fieldName = anotation.fieldName().toLowerCase();
}
key = "_" + fieldName;
fieldChecked.put(key, true);
}
}
row.setFieldChecked(fieldChecked);
}
return row;
}
@Override
public T findById(Class entityClass, String sessionId, Object id) throws Exception {
return dao.findById(entityClass, sessionId, id);
}
@Override
public T findByUk(String sessionId, T ejb) throws Exception {
return dao.findByUk(sessionId, ejb);
}
@Override
public List find(Class entityClass, String sessionId) throws Exception {
return dao.find(entityClass, sessionId);
}
@Override
public List find(Class entityClass, String sessionId, String order, String filter, Map params) throws Exception {
return dao.find(entityClass, sessionId, order, filter, params);
}
@Override
public List find(Class entityClass, String sessionId, String order, String filter, Map params, int first, int max) throws Exception {
return dao.find(entityClass, sessionId, order, filter, params, first, max);
}
@Override
public List