All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.epos.handler.dbapi.dbapiimplementation.EPOSDataModelDBAPI Maven / Gradle / Ivy

package org.epos.handler.dbapi.dbapiimplementation;

import org.epos.eposdatamodel.EPOSDataModelEntity;
import org.epos.eposdatamodel.State;
import org.epos.handler.dbapi.EPOSDataModel;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Deprecated(forRemoval = true)
@SuppressWarnings("unchecked")
public class EPOSDataModelDBAPI {

    private EPOSDataModelDBAPI() {
    }

    public static void save(EPOSDataModelEntity eposDataModel) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {

        String objectName = eposDataModel.getClass().getSimpleName();
        System.out.println("EDM"+objectName);
        EPOSDataModel implementationDBAPI = getImplementationDBAPI(objectName);
        implementationDBAPI.save(eposDataModel);

    }

    public static  T get(String uid, Class classObject) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        EPOSDataModel implementationDBAPI = getImplementationDBAPI(classObject.getSimpleName());

        List collect = ((List) implementationDBAPI.getByUid(uid)).stream()
                .filter(i -> i.getState().equals(State.PUBLISHED))
                .collect(Collectors.toList());

        return !collect.isEmpty() ? collect.get(0) : null;
    }

    public static  List getAll(Class classObject) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        EPOSDataModel implementationDBAPI = getImplementationDBAPI(classObject.getSimpleName());

        return (List) implementationDBAPI.getAllByState(State.PUBLISHED);
    }


    public static void saveAll(Collection eposDataModelList) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        for (EPOSDataModelEntity o : eposDataModelList) {
            save(o);
        }
    }

    public static  void delete(String uid, Class classObject) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        EPOSDataModel implementationDBAPI = getImplementationDBAPI(classObject.getSimpleName());

        implementationDBAPI.delete(uid);

    }

    public static  void update(String id, Object eposDataModel) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {

        String objectName = eposDataModel.getClass().getSimpleName();
        EPOSDataModel implementationDBAPI = getImplementationDBAPI(objectName);

        implementationDBAPI.hardUpdate(id, (EPOSDataModelEntity) eposDataModel);
    }


    private static EPOSDataModel getImplementationDBAPI(String simpleName) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        String classNameDBAPI = "org.epos.handler.dbapi.dbapiimplementation." + simpleName + "DBAPI";

        Class classDBAPI = Class.forName(classNameDBAPI);
        Constructor ctorDBAPI = classDBAPI.getConstructor();
        return (EPOSDataModel) ctorDBAPI.newInstance();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy