
io.lightlink.dao.LightLinkDAO Maven / Gradle / Ivy
package io.lightlink.dao;
/*
* #%L
* lightlink-core
* %%
* Copyright (C) 2015 Vitaliy Shevchuk
* %%
* This program 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 program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import io.lightlink.config.ConfigManager;
import io.lightlink.core.ScriptRunner;
import io.lightlink.dao.mapping.BeanMapper;
import io.lightlink.output.ObjectBufferResponseStream;
import org.apache.commons.collections.BeanMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class LightLinkDAO {
public static final Logger LOG = LoggerFactory.getLogger(LightLinkDAO.class);
private String rootPackage, action;
private ScriptRunner scriptRunner;
private ServletContext servletContext;
public LightLinkDAO(String rootPackage, String action, ServletContext servletContext) {
this.servletContext = servletContext;
this.rootPackage = rootPackage;
this.action = action;
scriptRunner = new ScriptRunner(rootPackage,servletContext);
}
protected LightLinkDAO(String rootPackage, String action) {
this.rootPackage = rootPackage;
this.action = action;
scriptRunner = new ScriptRunner(rootPackage);
}
public static LightLinkDAO getInstance(ServletContext servletContext,String rootPackage,String action){
return new LightLinkDAO(rootPackage, action);
}
public static LightLinkDAO getInstance(String rootPackage,String action){
return new LightLinkDAO(rootPackage, action);
}
public static LightLinkDAO getInstance(String action){
return new LightLinkDAO(ConfigManager.DEFAULT_ROOT_PACKAGE, action);
}
public Map execute(Object params) {
try {
return doExecute(params);
} catch (Exception e) {
LOG.error(e.toString(), e);
throw new RuntimeException(e.toString(), e);
}
}
public T execute(Object params, Class aClass) {
try {
Map data = doExecute(params);
return (T) new BeanMapper(aClass, getFieldNames(data)).convertObject(data, false);
} catch (Exception e) {
LOG.error(e.toString(), e);
throw new RuntimeException(e.toString(), e);
}
}
private List getFieldNames(Map data) {
return new ArrayList(data.keySet());
}
private List getFieldNames(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy