no message

main
이범준 1 year ago
parent 2286f36e9f
commit 1a16c3b73e

@ -1,239 +0,0 @@
package cokr.xit.fims.framework.core.utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.io.Resource;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
*
* @: Mybatis mapper
* @: mybatis mapper .
* JDK 1.5 , Spring, mybatis, spring-mybatis .
*
* : https://sbcoba.tistory.com/16 [홍이의 개발 노트]
*
*
* [ ]
* -. Tomcat .
* -> Publising "Never publish automatically"
* -> Publising "Automatically publish when resources change " "Automatically publish after a build event"
* @: 2020. 10. 14. 3:50:56
* @:
* @author ()
* @since 2002. 2. 2.
* @version 1.0 Copyright(c) XIT All rights reserved.
*/
public class XitRefreshableSqlSessionFactoryBean extends SqlSessionFactoryBean implements DisposableBean{
private static final Log log = LogFactory.getLog(XitRefreshableSqlSessionFactoryBean.class);
private SqlSessionFactory proxy;
private int interval = 500;
private Timer timer;
private TimerTask task;
private Resource[] mapperLocations;
/**
* .
*/
private boolean running = false;
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
private final Lock rl = rwl.readLock();
private final Lock wl = rwl.writeLock();
public void setMapperLocations(Resource[] mapperLocations) {
super.setMapperLocations(mapperLocations);
this.mapperLocations = mapperLocations;
}
public void setInterval(int interval) {
this.interval = interval;
}
/**
* @throws Exception
*/
public void refresh() throws Exception {
if (log.isInfoEnabled()) {
log.info("refreshing sqlMapClient.");
}
wl.lock();
try {
super.afterPropertiesSet();
} finally {
wl.unlock();
}
}
/**
* SqlMapClient .
*/
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
setRefreshable();
}
private void setRefreshable() {
proxy = (SqlSessionFactory) Proxy.newProxyInstance(
SqlSessionFactory.class.getClassLoader()
, new Class[]{SqlSessionFactory.class}
, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// log.debug("method.getName() : " + method.getName());
return method.invoke(getParentObject(), args);
}
});
task = new TimerTask() {
private Map<Resource, Long> map = new HashMap<Resource, Long>();
public void run() {
if (isModified()) {
try {
refresh();
} catch (Exception e) {
log.error("caught exception", e);
}
}
}
private boolean isModified() {
boolean retVal = false;
if (mapperLocations != null) {
for (int i = 0; i < mapperLocations.length; i++) {
Resource mappingLocation = mapperLocations[i];
retVal |= findModifiedResource(mappingLocation);
}
}
return retVal;
}
private boolean findModifiedResource(Resource resource) {
boolean retVal = false;
List<String> modifiedResources = new ArrayList<String>();
try {
long modified = resource.lastModified();
if (map.containsKey(resource)) {
long lastModified = ((Long) map.get(resource)) .longValue();
if (lastModified != modified) {
map.put(resource, new Long(modified));
modifiedResources.add(resource.getDescription());
retVal = true;
}
} else {
map.put(resource, new Long(modified));
}
} catch (IOException e) {
log.error("caught exception", e);
}
if (retVal) {
if (log.isInfoEnabled()) {
log.info("modified files : " + modifiedResources);
}
}
return retVal;
}
};
timer = new Timer(true);
resetInterval();
}
private Object getParentObject() throws Exception {
rl.lock();
try {
return super.getObject();
} finally {
rl.unlock();
}
}
public SqlSessionFactory getObject() {
return this.proxy;
}
public Class<? extends SqlSessionFactory> getObjectType() {
return (this.proxy != null ? this.proxy.getClass() : SqlSessionFactory.class);
}
public boolean isSingleton() {
return true;
}
public void setCheckInterval(int ms) {
interval = ms;
if (timer != null) {
resetInterval();
}
}
private void resetInterval() {
if (running) {
timer.cancel(); running = false;
}
if (interval > 0) {
timer.schedule(task, 0, interval); running = true;
}
}
public void destroy() throws Exception {
timer.cancel();
}
}

@ -1,122 +0,0 @@
package cokr.xit.fims.framework.core.utils;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/* **************************************
* request Wrapping forward
* @author
************************************** */
//RequestDispatcher rd = req.getRequestDispatcher("/example/CallUrl");
//try {
// XitRequestWrapper reqWrap = new XitRequestWrapper(req);
// reqWrap.setParameter("param1", "abc");
// reqWrap.setParameter("param2", "123");
// rd.forward(reqWrap, resp);
//} catch (ServletException e1) {
// e1.printStackTrace();
//} catch (IOException e1) {
// e1.printStackTrace();
//}
/**
*
* <ul>
* <li> : HttpServletRequest Wrapper </li>
* <li> : </li>
* <li>: 2018. 9. 6. 4:45:16
* </ul>
*
* @author
*
*/
public class XitRequestWrapper extends HttpServletRequestWrapper{
HashMap<String, Object> params;
public XitRequestWrapper(HttpServletRequest request) {
super(request);
this.params = new HashMap<String, Object>(request.getParameterMap());
}
public String getParameter(String name){
String returnValue = null;
String[] paramArray = getParameterValues(name);
if (paramArray != null && paramArray.length > 0){
returnValue = paramArray[0];
}
return returnValue;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map getParameterMap() {
return Collections.unmodifiableMap(params);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getParameterNames() {
return Collections.enumeration(params.keySet());
}
public String[] getParameterValues(String name) {
String[] result = null;
String[] temp = (String[])params.get(name);
if (temp != null){
result = new String[temp.length];
System.arraycopy(temp, 0, result, 0, temp.length);
}
return result;
}
public void setParameter(String name, String value){
String[] oneParam = {value};
setParameter(name, oneParam);
}
public void setParameter(String name, Map<String, String> value){
for(String key : value.keySet())
setParameter(name, value.get(key));
}
public void setParameter(String name, String[] value){
params.put(name, value);
}
/**
* <pre> : .</pre>
* @param url
* @param response HttpServletResponse
* @throws ServletException
* @throws IOException void
* @author:
* @date: 2020. 9. 10.
*/
public void forward(String url, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = this.getRequestDispatcher(url);
dispatcher.forward(this, response);
}
}
Loading…
Cancel
Save