Bernarto P Tjahjono
3 years ago
182 changed files with 22964 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>iexec</artifactId> |
||||||
|
<version>3.0.0-Beta1</version> |
||||||
|
<name>iexec</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<!--Cache system--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.commons</groupId> |
||||||
|
<artifactId>commons-jcs-core</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--JCS's required dependency--> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-logging</groupId> |
||||||
|
<artifactId>commons-logging</artifactId> |
||||||
|
<version>1.2</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--4ECAP Libs--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--Log dependencies--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||||
|
</properties> |
||||||
|
</project> |
@ -0,0 +1,74 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.iexec.common; |
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import com.fourelementscapital.db.IExecDB; |
||||||
|
import com.fourelementscapital.db.vo.ValueObject; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Use lib-db to generate tree menu on iExec |
||||||
|
*/ |
||||||
|
|
||||||
|
public class IExecMgmt{ |
||||||
|
|
||||||
|
private HttpServletRequest request=null; |
||||||
|
private Logger log = LogManager.getLogger(IExecMgmt.class.getName()); |
||||||
|
|
||||||
|
public IExecMgmt() throws Exception { |
||||||
|
super(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Map getTreeViewData() throws Exception { |
||||||
|
|
||||||
|
IExecDB iedb=IExecDB.getIExcecDB(); |
||||||
|
|
||||||
|
try{ |
||||||
|
HashMap rtn=new HashMap(); |
||||||
|
|
||||||
|
iedb.connectDB(); |
||||||
|
|
||||||
|
List glist=iedb.listGroups(); |
||||||
|
List folders=iedb.listFolders(); |
||||||
|
List strategies=iedb.listStrategies(); |
||||||
|
|
||||||
|
Vector groups=new Vector(); |
||||||
|
HashMap colors=new HashMap(); |
||||||
|
for(Iterator it=glist.iterator();it.hasNext();){ |
||||||
|
Map data=(Map)it.next(); |
||||||
|
|
||||||
|
ValueObject vo=new ValueObject(); |
||||||
|
vo.setKey((String)data.get("group_uid")); |
||||||
|
vo.setValue((String)data.get("group_name")); |
||||||
|
groups.add(vo); |
||||||
|
colors.put(data.get("group_uid"), data.get("color_code")); |
||||||
|
} |
||||||
|
rtn.put("folders", folders); |
||||||
|
rtn.put("groups",groups); |
||||||
|
rtn.put("group_colors",colors); |
||||||
|
rtn.put("strategies",strategies); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
|
||||||
|
}catch(Exception e){ |
||||||
|
throw e; |
||||||
|
}finally{ |
||||||
|
iedb.closeDB(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,78 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>qLib</artifactId> |
||||||
|
<version>${revision}${changelist}</version> |
||||||
|
<packaging>war</packaging> |
||||||
|
<name>qLib</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<revision>3.0.0</revision> |
||||||
|
<changelist>-Beta1</changelist> |
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||||
|
</properties> |
||||||
|
|
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<!--4ECAP Libs--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-config</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
|
||||||
|
<!--Log dependencies--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.slf4j</groupId> |
||||||
|
<artifactId>slf4j-simple</artifactId> |
||||||
|
<version>1.7.25</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.commons</groupId> |
||||||
|
<artifactId>commons-compress</artifactId> |
||||||
|
<version>1.15</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--Cache system--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.commons</groupId> |
||||||
|
<artifactId>commons-jcs-core</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</dependency> |
||||||
|
<!--JCS's required dependency--> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-logging</groupId> |
||||||
|
<artifactId>commons-logging</artifactId> |
||||||
|
<version>1.2</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!-- Added on 30 March 2018--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-client</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,305 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.rfunction.common; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
import com.fourelementscapital.config.Constant; |
||||||
|
import com.fourelementscapital.auth.UserThemeAccessPermission; |
||||||
|
import com.fourelementscapital.db.AbstractTeamOrgDB; |
||||||
|
import com.fourelementscapital.db.SchedulerDB; |
||||||
|
import com.fourelementscapital.client.Authenticated; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* This class is abstract and provide basic implementation for all Team Organization related moudles |
||||||
|
* for example: Themes tag support on scheduler, R function * |
||||||
|
* @author Administrator |
||||||
|
* |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public abstract class AbstractTeamOrgMgmt extends Authenticated{ |
||||||
|
|
||||||
|
protected static String ACCESS_PRIVILEGE_RWX="RWX"; |
||||||
|
protected static String ACCESS_PRIVILEGE_RX="RX"; |
||||||
|
protected static String ACCESS_PRIVILEGE_R="R"; |
||||||
|
private Logger log = LogManager.getLogger(AbstractTeamOrgMgmt.class.getName()); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* this constructor to be used only for DWR, manual invoking to get the object using of this constructor will mis-behave |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public AbstractTeamOrgMgmt() throws Exception { |
||||||
|
super(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* this constructor will be used only when JSP or Httprequest request is available. |
||||||
|
* @param request |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public AbstractTeamOrgMgmt(HttpServletRequest request) throws Exception { |
||||||
|
super(request); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* to be used in child class
|
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected Map getThemeAccessData(AbstractTeamOrgDB sdb) throws Exception { |
||||||
|
|
||||||
|
UserThemeAccessPermission auth=getAuthenticatedUserObj(sdb); |
||||||
|
HashMap rtn=new HashMap(); |
||||||
|
if(auth!=null){ |
||||||
|
rtn.put("rwx_tags",auth.getRwx()); |
||||||
|
rtn.put("rx_tags",auth.getRx()); |
||||||
|
rtn.put("r_tags",auth.getR()); |
||||||
|
} |
||||||
|
|
||||||
|
String superuser=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_SUPERUSER); |
||||||
|
if(superuser!=null && !superuser.equals("")){ |
||||||
|
rtn.put("superuser",superuser); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param scheduler_id |
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected String getAccessPrivilege(int scheduler_id, AbstractTeamOrgDB sdb) throws Exception { |
||||||
|
String rtn=""; |
||||||
|
UserThemeAccessPermission user=getAuthenticatedUserObj(sdb); |
||||||
|
if(user!=null){ |
||||||
|
List<String> themes=sdb.getThemeTags(scheduler_id); |
||||||
|
|
||||||
|
log.debug("themes:"+themes); |
||||||
|
log.debug("user.getRwx():"+user.getRwx()); |
||||||
|
log.debug("user.getRx():"+user.getRx()); |
||||||
|
log.debug("user.getR():"+user.getR()); |
||||||
|
|
||||||
|
for(String ttag:themes){ |
||||||
|
if(user.getRwx().contains(ttag)) rtn=ACCESS_PRIVILEGE_RWX; |
||||||
|
if(user.getRx().contains(ttag) && (!rtn.equals(ACCESS_PRIVILEGE_RWX) )) rtn=ACCESS_PRIVILEGE_RX; |
||||||
|
if(user.getR().contains(ttag) && rtn.equals("")) rtn=ACCESS_PRIVILEGE_R; |
||||||
|
} |
||||||
|
if(themes.size()==0) rtn=ACCESS_PRIVILEGE_RWX; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
log.debug("user:"+user); |
||||||
|
log.debug("getAccessPrivilege:rtn:"+rtn); |
||||||
|
String superuser=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_SUPERUSER); |
||||||
|
if(superuser!=null && !superuser.equals("")){ |
||||||
|
rtn=ACCESS_PRIVILEGE_RWX; |
||||||
|
} |
||||||
|
if(rtn.equals("")) rtn=null; |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @deprecated |
||||||
|
* @param notity_tags |
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected ArrayList <String> getNotifications(List notity_tags, AbstractTeamOrgDB sdb) throws Exception { |
||||||
|
|
||||||
|
Map<String,String> priv_data=getThemeHirarchy(notity_tags,sdb); |
||||||
|
ArrayList <String> user_notification=new ArrayList<String>(); |
||||||
|
|
||||||
|
for(Iterator<String> i=priv_data.keySet().iterator();i.hasNext();){ |
||||||
|
String ky=i.next(); |
||||||
|
if(priv_data.get(ky)!=null && priv_data.get(ky).equalsIgnoreCase("rwx")){ |
||||||
|
user_notification.add(ky); |
||||||
|
} |
||||||
|
} |
||||||
|
return user_notification; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected boolean isAuthorizedUser(SchedulerDB sdb) throws Exception { |
||||||
|
|
||||||
|
String user=getAuthenticatedUser(); |
||||||
|
if(user!=null){ |
||||||
|
Map u=sdb.getSVNUser4WikiUser(user); |
||||||
|
if(u!=null && u.get("svn_username")!=null && u.get("svn_password")!=null |
||||||
|
&& !((String)u.get("svn_username")).equals("") && !((String)u.get("svn_password")).equals("") |
||||||
|
){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected String getAuthorizedUser(SchedulerDB sdb) throws Exception { |
||||||
|
|
||||||
|
String user=getAuthenticatedUser(); |
||||||
|
log.debug("getAuthorizedUser() user:"+user); |
||||||
|
if(user!=null){ |
||||||
|
Map u=sdb.getSVNUser4WikiUser(user); |
||||||
|
if(u!=null && u.get("svn_username")!=null && u.get("svn_password")!=null |
||||||
|
&& !((String)u.get("svn_username")).equals("") && !((String)u.get("svn_password")).equals("") |
||||||
|
){ |
||||||
|
return (String)u.get("svn_username"); |
||||||
|
}else{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param scheduler_id |
||||||
|
* @param sdb |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
|
||||||
|
protected Map getItemTags2(int scheduler_id,AbstractTeamOrgDB sdb) throws Exception { |
||||||
|
|
||||||
|
//SchedulerDB sdb=SchedulerDB.getSchedulerDB();
|
||||||
|
|
||||||
|
//try{
|
||||||
|
HashMap h=new HashMap(); |
||||||
|
Vector tagids=sdb.getTagIds4Item(scheduler_id); |
||||||
|
Vector tags=sdb.getTags(); |
||||||
|
Vector follow_tagids=sdb.getFollowTagIds4Item(scheduler_id); |
||||||
|
|
||||||
|
ArrayList<String> themes=sdb.getThemeNames4Item(scheduler_id); |
||||||
|
//Vector followers=sdb.getFollowers(scheduler_id);
|
||||||
|
|
||||||
|
|
||||||
|
Map priv_data=getThemeHirarchy(themes,sdb); |
||||||
|
if(priv_data.get("theme")!=null){ |
||||||
|
priv_data.remove("theme"); |
||||||
|
} |
||||||
|
|
||||||
|
List ftags=sdb.getFollowTags4Item(scheduler_id); |
||||||
|
List user_notifications=ftags.size()>0?getNotifications(ftags,sdb):new ArrayList(); |
||||||
|
ArrayList<String> all=new ArrayList<String>(ftags); |
||||||
|
all.addAll(themes); |
||||||
|
|
||||||
|
h.put("tagids", tagids); |
||||||
|
h.put("user_privileges",priv_data); |
||||||
|
h.put("user_notifications",user_notifications); |
||||||
|
h.put("follow_tagids",follow_tagids); |
||||||
|
h.put("notice_escalated", getThemeHirarchy(all,sdb)); |
||||||
|
h.put("tags", tags); |
||||||
|
h.putAll(priv_data); |
||||||
|
return h; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param item_id |
||||||
|
* @param newtask_tags |
||||||
|
* @param follow_tags |
||||||
|
* @param atodb |
||||||
|
* @param sdb |
||||||
|
* @param name |
||||||
|
* @param comment |
||||||
|
* @param rev |
||||||
|
* @param diff |
||||||
|
* @param tempdata |
||||||
|
* @param templ_file |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
protected void updateAllItemTags(int item_id, List newtask_tags,List follow_tags,AbstractTeamOrgDB atodb,SchedulerDB sdb,String name, String comment,long rev,String diff, Map tempdata, String templ_file) throws Exception { |
||||||
|
|
||||||
|
ArrayList<Integer> ids=new ArrayList<Integer>(); |
||||||
|
for(Iterator i=newtask_tags.iterator();i.hasNext();){ |
||||||
|
String tid=(String)i.next(); |
||||||
|
ids.add(Integer.parseInt(tid)); |
||||||
|
} |
||||||
|
atodb.updateItemTagIds(item_id, ids); |
||||||
|
String owner_tag=null; |
||||||
|
if(ids.size()>0){ |
||||||
|
owner_tag=atodb.getThemeTagName(ids.get(0)); |
||||||
|
} |
||||||
|
ArrayList<Integer> fids=new ArrayList<Integer>(); |
||||||
|
for(Iterator i=follow_tags.iterator();i.hasNext();){ |
||||||
|
String tid=(String)i.next(); |
||||||
|
fids.add(Integer.parseInt(tid)); |
||||||
|
} |
||||||
|
atodb.updateFollwerTagIds(item_id, fids); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected Map getItemPrivilegeNotifications(ArrayList<String> themes,ArrayList<String> ftags,AbstractTeamOrgDB sdb) throws Exception { |
||||||
|
|
||||||
|
|
||||||
|
Map priv_data=getThemeHirarchy(themes,sdb); |
||||||
|
HashMap h=new HashMap(); |
||||||
|
|
||||||
|
ArrayList<String> all=new ArrayList<String>(ftags); |
||||||
|
all.addAll(themes); |
||||||
|
List user_notifications=getNotifications(all,sdb); |
||||||
|
h.put("user_notifications",user_notifications); |
||||||
|
h.put("user_privileges",priv_data); |
||||||
|
h.put("notice_escalated",getThemeHirarchy(all,sdb)); |
||||||
|
|
||||||
|
return h; |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,164 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.rfunction.common; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import org.apache.commons.jcs.JCS; |
||||||
|
import org.apache.commons.jcs.access.CacheAccess; |
||||||
|
import org.apache.commons.jcs.engine.behavior.IElementAttributes; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import com.fourelementscapital.db.RFunctionDB; |
||||||
|
import com.fourelementscapital.db.SchedulerDB; |
||||||
|
import com.fourelementscapital.db.vo.ValueObject; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* This class exposes data to R function editor in Ajax call |
||||||
|
* Remember all methods in the class are required user to be logged in |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public class RFunctionMgmt extends AbstractTeamOrgMgmt { |
||||||
|
|
||||||
|
private HttpServletRequest request=null; |
||||||
|
private Logger log = LogManager.getLogger(RFunctionMgmt.class.getName()); |
||||||
|
private static CacheAccess<String, HashMap> lockcache=null; |
||||||
|
private String cache_packaged_key="packaged_functions"; |
||||||
|
public static String RFUNCTION_FILE_EXTENSION=".r"; |
||||||
|
|
||||||
|
private static String FUNCTION_ID="function_id"; |
||||||
|
private static String LOCK_DURATION="duration"; |
||||||
|
private static String USER="user"; |
||||||
|
|
||||||
|
/** |
||||||
|
* DWR invocation |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public RFunctionMgmt() throws Exception { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* JSP or internal invocation |
||||||
|
* @param request |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public RFunctionMgmt(HttpServletRequest request) throws Exception { |
||||||
|
super(request); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* JCS caching for speed data retrival and not necessary to hit the database for every user. |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static CacheAccess getLockCache() throws Exception { |
||||||
|
if(RFunctionMgmt.lockcache==null) RFunctionMgmt.lockcache=JCS.getInstance("lock-cache"); |
||||||
|
return RFunctionMgmt.lockcache; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Locking r function while a user is editing |
||||||
|
* @param function_id |
||||||
|
* @param seconds |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public boolean lockFunction(int function_id, long seconds) throws Exception { |
||||||
|
SchedulerDB sdb=SchedulerDB.getSchedulerDB(); |
||||||
|
RFunctionDB rfdb=RFunctionDB .getRFunctionDB(); |
||||||
|
try{ |
||||||
|
sdb.connectDB(); |
||||||
|
rfdb.connectDB(); |
||||||
|
String usr=new SchedulerMgmt(getRequest()).getAuthorizedUser(sdb); |
||||||
|
if(seconds>0){ |
||||||
|
refreshCache(function_id, seconds,usr); |
||||||
|
}else{ |
||||||
|
rfdb.updateLock(function_id, usr); |
||||||
|
} |
||||||
|
return true; |
||||||
|
}catch(Exception e){ |
||||||
|
|
||||||
|
throw e; |
||||||
|
}finally{ |
||||||
|
sdb.closeDB(); |
||||||
|
rfdb.closeDB(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void removeLockFromCache(int function_id, String usr ) throws Exception { |
||||||
|
//String ky=usr+"_"+function_id;
|
||||||
|
String ky=usr+function_id; |
||||||
|
if(getLockCache().get(ky)!=null)getLockCache().remove(ky); |
||||||
|
} |
||||||
|
|
||||||
|
private void refreshCache(int function_id, long seconds, String usr ) throws Exception { |
||||||
|
|
||||||
|
//String ky=usr+"_"+function_id;
|
||||||
|
String ky=usr+function_id; |
||||||
|
HashMap h=new HashMap(); |
||||||
|
h.put(RFunctionMgmt.FUNCTION_ID, function_id); |
||||||
|
h.put(RFunctionMgmt.LOCK_DURATION, seconds); |
||||||
|
h.put(RFunctionMgmt.USER, usr); |
||||||
|
|
||||||
|
IElementAttributes att= getLockCache().getDefaultElementAttributes(); |
||||||
|
att.setMaxLife(seconds); |
||||||
|
if(getLockCache().get(ky)!=null)getLockCache().remove(ky); |
||||||
|
getLockCache().put(ky,h,att); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* return data for folder generation. |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Map getFolderTree() throws Exception { |
||||||
|
|
||||||
|
RFunctionDB rfdb=RFunctionDB.getRFunctionDB(); |
||||||
|
|
||||||
|
try{ |
||||||
|
HashMap rtn=new HashMap(); |
||||||
|
|
||||||
|
rfdb.connectDB(); |
||||||
|
List glist=rfdb.listFunctionGroups(); |
||||||
|
List folders=rfdb.listOfFolders(); |
||||||
|
|
||||||
|
//TreeMap groups=new TreeMap();
|
||||||
|
Vector groups=new Vector(); |
||||||
|
|
||||||
|
for(Iterator it=glist.iterator();it.hasNext();){ |
||||||
|
Map data=(Map)it.next(); |
||||||
|
//groups.put(data.get("group_uid"),data.get("group_name"));
|
||||||
|
|
||||||
|
ValueObject vo=new ValueObject(); |
||||||
|
vo.setKey((String)data.get("group_uid")); |
||||||
|
vo.setValue((String)data.get("group_name")); |
||||||
|
groups.add(vo); |
||||||
|
} |
||||||
|
rtn.put("folders", folders); |
||||||
|
rtn.put("groups",groups); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
|
||||||
|
|
||||||
|
}catch(Exception e){ |
||||||
|
throw e; |
||||||
|
}finally{ |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.rfunction.common; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public class SchedulerMgmt extends AbstractTeamOrgMgmt { |
||||||
|
|
||||||
|
private Logger log = LogManager.getLogger(SchedulerMgmt.class.getName()); |
||||||
|
private HttpServletRequest request=null; |
||||||
|
private static String USER="user"; |
||||||
|
|
||||||
|
/** |
||||||
|
* for DWR invocation |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public SchedulerMgmt() throws Exception { |
||||||
|
super(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Invocation only when you have HttpRequest is available, |
||||||
|
* in JSP or internally. |
||||||
|
* @param request |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public SchedulerMgmt(HttpServletRequest request) throws Exception { |
||||||
|
super(request); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
protected String getPeerIPAddress() throws Exception { |
||||||
|
String rtn=(String) getRequest().getSession().getAttribute(REMOTE_IP); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-app</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,26 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-app</artifactId> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<name>archetype-app</name> |
||||||
|
<description>A fourelementscapital archetype as the basis of building a four elements capital application</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
<build> |
||||||
|
<extensions> |
||||||
|
<extension> |
||||||
|
<groupId>org.apache.maven.archetype</groupId> |
||||||
|
<artifactId>archetype-packaging</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</extension> |
||||||
|
</extensions> |
||||||
|
</build> |
||||||
|
</project> |
@ -0,0 +1,36 @@ |
|||||||
|
<archetype-descriptor |
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" |
||||||
|
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<fileSets> |
||||||
|
<fileSet filtered="true" packaged="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/java</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.java</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
<fileSet filtered="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
<fileSet filtered="true" packaged="true" encoding="UTF-8"> |
||||||
|
<directory>src/test/java</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.java</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
</fileSets> |
||||||
|
<requiredProperties> |
||||||
|
<requiredProperty key="version"> |
||||||
|
<defaultValue>1.0</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="groupId"> |
||||||
|
<defaultValue>com.fourelementscapital</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="package"> |
||||||
|
<defaultValue>com.fourelementscapital.${artifactId}</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
</requiredProperties> |
||||||
|
</archetype-descriptor> |
@ -0,0 +1,149 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>${groupId}</groupId> |
||||||
|
<artifactId>${artifactId}</artifactId> |
||||||
|
<version>${version}</version> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<artifactId>maven-shade-plugin</artifactId> |
||||||
|
<version>2.3</version> |
||||||
|
<executions> |
||||||
|
<execution> |
||||||
|
<phase>package</phase> |
||||||
|
<goals> |
||||||
|
<goal>shade</goal> |
||||||
|
</goals> |
||||||
|
<configuration> |
||||||
|
<transformers> |
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> |
||||||
|
<mainClass>${package}.App</mainClass> |
||||||
|
</transformer> |
||||||
|
</transformers> |
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom> |
||||||
|
<filters> |
||||||
|
<filter> |
||||||
|
<artifact>*:*</artifact> |
||||||
|
<excludes> |
||||||
|
<exclude>META-INF/*.SF</exclude> |
||||||
|
<exclude>META-INF/*.DSA</exclude> |
||||||
|
<exclude>META-INF/*.RSA</exclude> |
||||||
|
</excludes> |
||||||
|
</filter> |
||||||
|
</filters> |
||||||
|
</configuration> |
||||||
|
</execution> |
||||||
|
</executions> |
||||||
|
</plugin> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-site-plugin</artifactId> |
||||||
|
<version>3.5.1</version> |
||||||
|
<executions> |
||||||
|
<execution> |
||||||
|
<id>attach-javadocs</id> |
||||||
|
<phase>package</phase> |
||||||
|
<goals> |
||||||
|
<goal>site</goal> |
||||||
|
<goal>stage</goal> |
||||||
|
</goals> |
||||||
|
</execution> |
||||||
|
</executions> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
<distributionManagement> |
||||||
|
<site> |
||||||
|
<id>${artifactId}</id> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
</site> |
||||||
|
</distributionManagement> |
||||||
|
|
||||||
|
<reporting> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-javadoc-plugin</artifactId> |
||||||
|
<version>2.10.4</version> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reportSets> |
||||||
|
<reportSet> |
||||||
|
<id>aggregate</id> |
||||||
|
<inherited>true</inherited> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reports> |
||||||
|
<report>javadoc</report> |
||||||
|
<report>test-javadoc</report> |
||||||
|
</reports> |
||||||
|
</reportSet> |
||||||
|
</reportSets> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</reporting> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>junit</groupId> |
||||||
|
<artifactId>junit</artifactId> |
||||||
|
<version>3.8.1</version> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-alarm</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-fileutils</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-r</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-socket</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-tts</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-imonitor</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,26 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package ${package}; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* A com.fourelementscapital Class |
||||||
|
*/ |
||||||
|
public class App { |
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(App.class.getName()); |
||||||
|
|
||||||
|
public static void main( String[] args ) |
||||||
|
{ |
||||||
|
log.debug( "Hello Four Elements Capital !" ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,13 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<Configuration status="WARN"> |
||||||
|
<Appenders> |
||||||
|
<Console name="CONSOLE" target="SYSTEM_OUT"> |
||||||
|
<PatternLayout pattern="%4p %d{HH:mm:ss,SSS} %C - %m%n" /> |
||||||
|
</Console> |
||||||
|
</Appenders> |
||||||
|
<Loggers> |
||||||
|
<Root level="DEBUG"> |
||||||
|
<AppenderRef ref="CONSOLE"/> |
||||||
|
</Root> |
||||||
|
</Loggers> |
||||||
|
</Configuration> |
@ -0,0 +1,47 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package ${package}; |
||||||
|
|
||||||
|
import junit.framework.Test; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import junit.framework.TestSuite; |
||||||
|
|
||||||
|
/** |
||||||
|
* Unit test for App |
||||||
|
*/ |
||||||
|
public class AppTest extends TestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* Create the test case |
||||||
|
* |
||||||
|
* @param testName name of the test case |
||||||
|
*/ |
||||||
|
public AppTest( String testName ) |
||||||
|
{ |
||||||
|
super( testName ); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the suite of tests being tested |
||||||
|
*/ |
||||||
|
public static Test suite() |
||||||
|
{ |
||||||
|
return new TestSuite( AppTest.class ); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Empty Test |
||||||
|
*/ |
||||||
|
public void testApp() |
||||||
|
{ |
||||||
|
assertTrue( true ); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-lib</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,26 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-lib</artifactId> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<name>archetype-lib</name> |
||||||
|
<description>A fourelementscapital archetype as the basis of creating a com.fourelementscapital library / jar file</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
<build> |
||||||
|
<extensions> |
||||||
|
<extension> |
||||||
|
<groupId>org.apache.maven.archetype</groupId> |
||||||
|
<artifactId>archetype-packaging</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</extension> |
||||||
|
</extensions> |
||||||
|
</build> |
||||||
|
</project> |
@ -0,0 +1,30 @@ |
|||||||
|
<archetype-descriptor |
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" |
||||||
|
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<fileSets> |
||||||
|
<fileSet filtered="true" packaged="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/java</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.java</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
<fileSet filtered="true" packaged="true" encoding="UTF-8"> |
||||||
|
<directory>src/test/java</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.java</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
</fileSets> |
||||||
|
<requiredProperties> |
||||||
|
<requiredProperty key="version"> |
||||||
|
<defaultValue>1.0</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="groupId"> |
||||||
|
<defaultValue>com.fourelementscapital</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="package"> |
||||||
|
<defaultValue>com.fourelementscapital.${artifactId}</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
</requiredProperties> |
||||||
|
</archetype-descriptor> |
@ -0,0 +1,119 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>${groupId}</groupId> |
||||||
|
<artifactId>${artifactId}</artifactId> |
||||||
|
<version>${version}</version> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-site-plugin</artifactId> |
||||||
|
<version>3.5.1</version> |
||||||
|
<executions> |
||||||
|
<execution> |
||||||
|
<id>attach-javadocs</id> |
||||||
|
<phase>package</phase> |
||||||
|
<goals> |
||||||
|
<goal>site</goal> |
||||||
|
<goal>stage</goal> |
||||||
|
</goals> |
||||||
|
</execution> |
||||||
|
</executions> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
<distributionManagement> |
||||||
|
<site> |
||||||
|
<id>${artifactId}</id> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
</site> |
||||||
|
</distributionManagement> |
||||||
|
|
||||||
|
<reporting> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-javadoc-plugin</artifactId> |
||||||
|
<version>2.10.4</version> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reportSets> |
||||||
|
<reportSet> |
||||||
|
<id>aggregate</id> |
||||||
|
<inherited>true</inherited> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reports> |
||||||
|
<report>javadoc</report> |
||||||
|
<report>test-javadoc</report> |
||||||
|
</reports> |
||||||
|
</reportSet> |
||||||
|
</reportSets> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</reporting> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>junit</groupId> |
||||||
|
<artifactId>junit</artifactId> |
||||||
|
<version>3.8.1</version> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-alarm</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-fileutils</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-r</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-socket</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-tts</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-imonitor</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,22 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package ${package}; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
/** |
||||||
|
* A com.fourelementscapital Class |
||||||
|
*/ |
||||||
|
public class App { |
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(App.class.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,46 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package ${package}; |
||||||
|
|
||||||
|
import junit.framework.Test; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import junit.framework.TestSuite; |
||||||
|
|
||||||
|
/** |
||||||
|
* Unit test for App |
||||||
|
*/ |
||||||
|
public class AppTest extends TestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* Create the test case |
||||||
|
* |
||||||
|
* @param testName name of the test case |
||||||
|
*/ |
||||||
|
public AppTest( String testName ) |
||||||
|
{ |
||||||
|
super( testName ); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the suite of tests being tested |
||||||
|
*/ |
||||||
|
public static Test suite() |
||||||
|
{ |
||||||
|
return new TestSuite( AppTest.class ); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Empty Test |
||||||
|
*/ |
||||||
|
public void testApp() |
||||||
|
{ |
||||||
|
assertTrue( true ); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,22 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-webapp</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,26 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>archetype-webapp</artifactId> |
||||||
|
<packaging>maven-archetype</packaging> |
||||||
|
<name>archetype-webapp</name> |
||||||
|
<description>A fourelementscapital archetype as the basis of building a four elements capital web application</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
<build> |
||||||
|
<extensions> |
||||||
|
<extension> |
||||||
|
<groupId>org.apache.maven.archetype</groupId> |
||||||
|
<artifactId>archetype-packaging</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</extension> |
||||||
|
</extensions> |
||||||
|
</build> |
||||||
|
</project> |
@ -0,0 +1,36 @@ |
|||||||
|
<archetype-descriptor |
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" |
||||||
|
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<fileSets> |
||||||
|
<fileSet filtered="true" packaged="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/java</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.java</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
<fileSet filtered="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/webapp</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
<fileSet filtered="true" encoding="UTF-8"> |
||||||
|
<directory>src/main/resources</directory> |
||||||
|
<includes> |
||||||
|
<include>**/*.*</include> |
||||||
|
</includes> |
||||||
|
</fileSet> |
||||||
|
</fileSets> |
||||||
|
<requiredProperties> |
||||||
|
<requiredProperty key="version"> |
||||||
|
<defaultValue>1.0</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="groupId"> |
||||||
|
<defaultValue>com.fourelementscapital</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
<requiredProperty key="package"> |
||||||
|
<defaultValue>com.fourelementscapital.${artifactId}</defaultValue> |
||||||
|
</requiredProperty> |
||||||
|
</requiredProperties> |
||||||
|
</archetype-descriptor> |
@ -0,0 +1,125 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>${groupId}</groupId> |
||||||
|
<artifactId>${artifactId}</artifactId> |
||||||
|
<version>${version}</version> |
||||||
|
<packaging>war</packaging> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<build> |
||||||
|
<finalName>${artifactId}</finalName> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-site-plugin</artifactId> |
||||||
|
<version>3.5.1</version> |
||||||
|
<executions> |
||||||
|
<execution> |
||||||
|
<id>attach-javadocs</id> |
||||||
|
<phase>package</phase> |
||||||
|
<goals> |
||||||
|
<goal>site</goal> |
||||||
|
<goal>stage</goal> |
||||||
|
</goals> |
||||||
|
</execution> |
||||||
|
</executions> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
<distributionManagement> |
||||||
|
<site> |
||||||
|
<id>${artifactId}</id> |
||||||
|
<name>${artifactId}</name> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
</site> |
||||||
|
</distributionManagement> |
||||||
|
|
||||||
|
<reporting> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-javadoc-plugin</artifactId> |
||||||
|
<version>2.10.4</version> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reportSets> |
||||||
|
<reportSet> |
||||||
|
<id>aggregate</id> |
||||||
|
<inherited>true</inherited> |
||||||
|
<configuration> |
||||||
|
</configuration> |
||||||
|
<reports> |
||||||
|
<report>javadoc</report> |
||||||
|
<report>test-javadoc</report> |
||||||
|
</reports> |
||||||
|
</reportSet> |
||||||
|
</reportSets> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</reporting> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>junit</groupId> |
||||||
|
<artifactId>junit</artifactId> |
||||||
|
<version>3.8.1</version> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.servlet</groupId> |
||||||
|
<artifactId>servlet-api</artifactId> |
||||||
|
<version>2.5</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-alarm</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-fileutils</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-r</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-socket</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-tts</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-imonitor</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,39 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package ${package}.servlet; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.HttpServlet; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
public class HelloServlet extends HttpServlet { |
||||||
|
|
||||||
|
private Logger log = LogManager.getLogger(HelloServlet.class.getName()); |
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
||||||
|
throws ServletException, IOException { |
||||||
|
|
||||||
|
String str = "Hello four elements capital !"; |
||||||
|
|
||||||
|
log.debug(">>> String result : " + str); |
||||||
|
|
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.println(str); |
||||||
|
out.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,13 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<Configuration status="WARN"> |
||||||
|
<Appenders> |
||||||
|
<Console name="CONSOLE" target="SYSTEM_OUT"> |
||||||
|
<PatternLayout pattern="%4p %d{HH:mm:ss,SSS} %C - %m%n" /> |
||||||
|
</Console> |
||||||
|
</Appenders> |
||||||
|
<Loggers> |
||||||
|
<Root level="DEBUG"> |
||||||
|
<AppenderRef ref="CONSOLE"/> |
||||||
|
</Root> |
||||||
|
</Loggers> |
||||||
|
</Configuration> |
@ -0,0 +1,22 @@ |
|||||||
|
<?xml version="1.0"?> |
||||||
|
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" |
||||||
|
version="2.4"> |
||||||
|
|
||||||
|
<display-name>Four Elements Capital Web Application</display-name> |
||||||
|
<description> |
||||||
|
This is a simple web application. |
||||||
|
</description> |
||||||
|
|
||||||
|
<servlet> |
||||||
|
<servlet-name>hello</servlet-name> |
||||||
|
<servlet-class>${package}.servlet.HelloServlet</servlet-class> |
||||||
|
</servlet> |
||||||
|
|
||||||
|
<servlet-mapping> |
||||||
|
<servlet-name>hello</servlet-name> |
||||||
|
<url-pattern>/hello</url-pattern> |
||||||
|
</servlet-mapping> |
||||||
|
|
||||||
|
</web-app> |
@ -0,0 +1 @@ |
|||||||
|
<jsp:forward page="/hello"/> |
@ -0,0 +1,33 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-alarm</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-httpclient</groupId> |
||||||
|
<artifactId>commons-httpclient</artifactId> |
||||||
|
<version>3.0</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,29 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-alarm</artifactId> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>lib-alarm</name> |
||||||
|
<description>Alarm functions, call iMonitor API</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-httpclient</groupId> |
||||||
|
<artifactId>commons-httpclient</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,300 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.alarm; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.io.OutputStreamWriter; |
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.net.Socket; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpClient; |
||||||
|
import org.apache.commons.httpclient.methods.PostMethod; |
||||||
|
import org.apache.commons.httpclient.methods.StringRequestEntity; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
/** |
||||||
|
* Send alarm to iMonitor API |
||||||
|
*/ |
||||||
|
public class Alarm { |
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(Alarm.class.getName()); |
||||||
|
|
||||||
|
/** |
||||||
|
* Private constructor |
||||||
|
*/ |
||||||
|
private Alarm(){} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Construct alarm message with default parameters and send it to iMonitor API |
||||||
|
* @param themes ThemeVO array list |
||||||
|
* @param alarm_type Alarm type |
||||||
|
* @param subject Subject |
||||||
|
* @param message Message |
||||||
|
* @param say Is Say |
||||||
|
* @param email Is Email |
||||||
|
* @param phone Is Phone |
||||||
|
* @param attachmentfile Attachment file |
||||||
|
* @param exc_add Exclude Address |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public static void sendAlarm(ArrayList<ThemeVO> themes, AlarmType alarm_type,String subject,String message, boolean say, boolean email, boolean phone, String attachmentfile,String exc_add) throws IOException { |
||||||
|
|
||||||
|
if(themes!=null && themes.size()>0 && message!=null && alarm_type!=null){ |
||||||
|
|
||||||
|
// ignore alarm ? :
|
||||||
|
String c_noalarm=getConfigValue("ignore.alarm"); |
||||||
|
if(c_noalarm!=null && c_noalarm.equalsIgnoreCase("true")) { |
||||||
|
//do nothing
|
||||||
|
}else{ |
||||||
|
|
||||||
|
//String xml=constructXMLWithFile(themes,subject,message,say,email,phone,attachmentfile,exc_add);
|
||||||
|
String socketMessage=constructSocketMessageWithFile(themes,subject,message,say,email,phone,attachmentfile,exc_add); |
||||||
|
//log.debug("Sending alarm:xml:"+xml);
|
||||||
|
//log.debug("Sending alarm:socketMessage:"+socketMessage);
|
||||||
|
|
||||||
|
// check whether dump XML to file or send to iMonitor API :
|
||||||
|
|
||||||
|
boolean isDump = Boolean.parseBoolean(getConfigValue("alarm.dump")); |
||||||
|
|
||||||
|
if (isDump) { |
||||||
|
// create folder if not exist. format : 'yyyyMMdd' (today's date)
|
||||||
|
String dumpFolder = getConfigValue("alarm.dump.folder"); |
||||||
|
SimpleDateFormat sdfDumpFolder = new SimpleDateFormat("yyyyMMdd"); |
||||||
|
dumpFolder = dumpFolder + sdfDumpFolder.format(new Date()) + "/"; // setup today folder
|
||||||
|
File dir = new File(dumpFolder); |
||||||
|
dir.mkdirs(); |
||||||
|
|
||||||
|
// write dump file. format : 'HHmmss.xml' (HHmmss : current time)
|
||||||
|
SimpleDateFormat sdfFile = new SimpleDateFormat("HHmmssSSS"); |
||||||
|
PrintWriter writer = new PrintWriter(dumpFolder + sdfFile.format(new Date()) + ".xml", "UTF-8"); |
||||||
|
//writer.println(xml);
|
||||||
|
//writer.println(socketMessage);
|
||||||
|
writer.close(); |
||||||
|
} |
||||||
|
else { |
||||||
|
//sendXML(xml); // send to iMonitor
|
||||||
|
sendSocketMessage(socketMessage); // send to iMonitor
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Send phone alarm with list of theme and a message |
||||||
|
* @param themes ThemeVO array list |
||||||
|
* @param message Message |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public static void sendAlarm(ArrayList<ThemeVO> themes, String message) throws IOException { |
||||||
|
Alarm.sendAlarm(themes,AlarmType.PHONE,null,message,false,false,true,null,null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Send phone alarm with a theme and a message |
||||||
|
* @param theme Theme |
||||||
|
* @param message Message |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public static void sendAlarm(String theme, String message) throws IOException { |
||||||
|
ArrayList<ThemeVO> themes = new ArrayList<ThemeVO>(); |
||||||
|
themes.add(new ThemeVO(theme)); |
||||||
|
Alarm.sendAlarm(themes,AlarmType.PHONE,null,message,false,false,true,null,null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Construct XML with file attachment |
||||||
|
* @param themes Themes |
||||||
|
* @param subject Subject |
||||||
|
* @param bodymsg Body message |
||||||
|
* @param say Is say |
||||||
|
* @param email Is email alert |
||||||
|
* @param phone Is phone alert |
||||||
|
* @param attachment Attachment |
||||||
|
* @param exc_add Exclude Address |
||||||
|
* @return XML |
||||||
|
*/ |
||||||
|
private static String constructXMLWithFile(List<ThemeVO> themes,String subject,String bodymsg,boolean say,boolean email,boolean phone, String attachment,String exc_add) { |
||||||
|
subject = escapeChar(subject); |
||||||
|
String xml="<IMONITOR>"; |
||||||
|
|
||||||
|
for (int i=0; i<themes.size(); i++) { |
||||||
|
ThemeVO themeVO = themes.get(i); |
||||||
|
if (themeVO != null) { |
||||||
|
xml+="<THEME>"+themeVO.getName()+"</THEME>"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
xml+="<SUBJECT>"+subject+"</SUBJECT>"; |
||||||
|
xml+="<BODY><![CDATA["+bodymsg+"]]></BODY>"; |
||||||
|
xml+="<OVERRIDEALARMLEVEL>m</OVERRIDEALARMLEVEL> "; |
||||||
|
xml+="<SAY>"+(say+"").toUpperCase()+"</SAY> "; |
||||||
|
xml+="<EMAIL>"+(email+"").toUpperCase()+"</EMAIL>"; |
||||||
|
xml+="<PHONE>"+(phone+"").toUpperCase()+"</PHONE>"; |
||||||
|
xml+="<ESCALATETICKS>5</ESCALATETICKS>"; |
||||||
|
xml+="<ESCALATEINTERVAL>15</ESCALATEINTERVAL>"; |
||||||
|
if(attachment!=null){ |
||||||
|
xml+="<EMAILIMAGES>"+attachment+"</EMAILIMAGES>"; |
||||||
|
} |
||||||
|
if(exc_add!=null){ |
||||||
|
xml+="<EXCLUDEADDRESS>"+exc_add+"</EXCLUDEADDRESS>"; |
||||||
|
} |
||||||
|
xml+="</IMONITOR>"; |
||||||
|
return xml; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct message with file attachment |
||||||
|
* @param themes Themes |
||||||
|
* @param subject Subject |
||||||
|
* @param bodymsg Body message |
||||||
|
* @param say Is say |
||||||
|
* @param email Is email |
||||||
|
* @param phone Is phone |
||||||
|
* @param attachment Attachment |
||||||
|
* @param exc_add Exclude Address |
||||||
|
* @return XML |
||||||
|
*/ |
||||||
|
private static String constructSocketMessageWithFile(List<ThemeVO> themes,String subject,String bodymsg,boolean say,boolean email,boolean phone, String attachment,String exc_add) { |
||||||
|
subject = escapeChar(subject); |
||||||
|
|
||||||
|
String message = ""; |
||||||
|
for (int i=0; i<themes.size(); i++) { |
||||||
|
ThemeVO themeVO = themes.get(i); |
||||||
|
if (themeVO != null) { |
||||||
|
message+="~theme$#="+themeVO.getName(); |
||||||
|
} |
||||||
|
} |
||||||
|
message+="~subject$#="+subject; |
||||||
|
message+="~body$#="+bodymsg; |
||||||
|
//message+="~recipients$#="+theme;
|
||||||
|
message+="~sayIt$#="+(say+"").toUpperCase(); |
||||||
|
message+="~emailIt$#="+(email+"").toUpperCase(); |
||||||
|
message+="~phoneCall$#="+(phone+"").toUpperCase(); |
||||||
|
message+="~emailAttachments$#="+attachment; |
||||||
|
//message+="~ym$#="+theme;
|
||||||
|
//message+="~sms$#="+theme;
|
||||||
|
message+="<EOF>"; |
||||||
|
|
||||||
|
// remove first char : '~'
|
||||||
|
message=message.substring(1, message.length()); |
||||||
|
|
||||||
|
/* |
||||||
|
xml+="<OVERRIDEALARMLEVEL>m</OVERRIDEALARMLEVEL> "; |
||||||
|
xml+="<ESCALATETICKS>5</ESCALATETICKS>"; |
||||||
|
xml+="<ESCALATEINTERVAL>15</ESCALATEINTERVAL>"; |
||||||
|
if(attachment!=null){ |
||||||
|
xml+="<EMAILIMAGES>"+attachment+"</EMAILIMAGES>"; |
||||||
|
} |
||||||
|
if(exc_add!=null){ |
||||||
|
xml+="<EXCLUDEADDRESS>"+exc_add+"</EXCLUDEADDRESS>"; |
||||||
|
} |
||||||
|
*/ |
||||||
|
|
||||||
|
return message; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Send XML to iMonitor API |
||||||
|
* @param xml XML |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private static void sendXML(String xml) throws IOException { |
||||||
|
try{ |
||||||
|
String url=getConfigValue("imonitor.url"); |
||||||
|
|
||||||
|
PostMethod post = new PostMethod(url); |
||||||
|
try { |
||||||
|
post.setRequestEntity(new StringRequestEntity(xml,"text/xml",null )); |
||||||
|
post.setRequestHeader("Content-type", "text/xml; utf-8"); |
||||||
|
HttpClient httpclient = new HttpClient(); |
||||||
|
int result = httpclient.executeMethod(post); |
||||||
|
} catch (IOException e) { |
||||||
|
// e.printStackTrace();
|
||||||
|
throw e; |
||||||
|
} finally { |
||||||
|
post.releaseConnection(); |
||||||
|
} |
||||||
|
}catch(Exception e){ |
||||||
|
e.printStackTrace(); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Send message via Socket to iMonitor API |
||||||
|
* @param message Message |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static void sendSocketMessage(String socketMessage) throws IOException { |
||||||
|
String ip = getConfigValue("imonitor.ip"); |
||||||
|
int port = Integer.parseInt(getConfigValue("imonitor.port")); |
||||||
|
Socket socket = new Socket(ip, port); |
||||||
|
OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream(), "UTF-8"); |
||||||
|
osw.write(socketMessage, 0, socketMessage.length()); |
||||||
|
osw.flush(); |
||||||
|
socket.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Escape XML characters |
||||||
|
* @param str String |
||||||
|
* @return String with escape characters |
||||||
|
*/ |
||||||
|
private static String escapeChar(String str) { |
||||||
|
String result = null; |
||||||
|
if (str != null) { |
||||||
|
result = str.replaceAll("&", "&"); |
||||||
|
result = result.replaceAll("\"", """); |
||||||
|
result = result.replaceAll("'", "'"); |
||||||
|
result = result.replaceAll("<", "<"); |
||||||
|
result = result.replaceAll(">", ">"); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get the value of a property defined in config file |
||||||
|
* @param propertyName - the name or key of the property you want to retrieve |
||||||
|
* @return the string value |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private static String getConfigValue(String propertyName) throws IOException |
||||||
|
{ |
||||||
|
Properties prop = new Properties(); |
||||||
|
String propFileName = "config_alarm.properties"; |
||||||
|
|
||||||
|
InputStream inputStream = Alarm.class.getClassLoader().getResourceAsStream(propFileName); |
||||||
|
|
||||||
|
if (inputStream != null) { |
||||||
|
prop.load(inputStream); |
||||||
|
} else { |
||||||
|
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); |
||||||
|
} |
||||||
|
|
||||||
|
// get the property value and print it out
|
||||||
|
String value = prop.getProperty(propertyName); |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,17 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.alarm; |
||||||
|
|
||||||
|
/** |
||||||
|
* Enumeration class for type of the Alarm |
||||||
|
*/ |
||||||
|
public enum AlarmType { |
||||||
|
EMAIL, PHONE |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,40 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.alarm; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* Theme Value Object to store theme name used by Alarm |
||||||
|
*/ |
||||||
|
public class ThemeVO implements Serializable { |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* Theme name |
||||||
|
*/ |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor with name parameter |
||||||
|
*/ |
||||||
|
public ThemeVO(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Windows peer couldn't start Rserve</li> |
||||||
|
<li>Make sure there is only one tomcat and Rserve process in the peer</li> |
||||||
|
<li>Restart tomcat and Rserve</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,8 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Peer connection pool for managing multiple RServe connections are not working properly</li> |
||||||
|
<li>On unix peer, this may happen when Rserve is not started</li> |
||||||
|
<li>On windows, Rserve port used by someother program </li> |
||||||
|
</ul> |
||||||
|
</div> |
||||||
|
|
@ -0,0 +1,5 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>This is uncategorized error due to certain Runtime error messages on peer or Rengine/Rserve</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,7 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Null Error message by RServe/REngine at the end of execution of script. According to RForge documentation, it is classified as unknow and something went wrong, Check http://www.rforge.net/Rserve/faq.html for more info</li> |
||||||
|
<li>Your script might not be reached end and could have been Runtime error in the middle</li> |
||||||
|
<li>Try running your script with low memory usage settings on your R</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,6 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>R script thrown Runtime exception</li> |
||||||
|
<li>Make sure runtime exceptions from Database,Network and File resources are caught and written in console</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,8 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>If the script is taking more than specified time, then it will be removed from the queue not matter eventually successful or failure</li> |
||||||
|
<li>Consider increasing execution time out by clicking speaker icon above the live queue of the scheduler</li> |
||||||
|
<li>Code modified and the new code consumes more time than previous executions</li> |
||||||
|
<li>This will also happen when peer restarted or stopped while task is running</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,7 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>The task still in the queue because peer couldn't reach server to update the status of task and server removes it as later found no longer running in peer</li> |
||||||
|
<li>Peer was running memory intensive script or unix peer Rserve threads were fully utilized at that time</li> |
||||||
|
<li>Please check the queue history later to know the final status of the execution</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,5 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>No Room to Execute the Script because peer receives 2 tasks at the same time and accepts only one and the other sent back to server and it will be resent to different peer</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,6 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Task removed because peer says it is no longer running in peer</li> |
||||||
|
<li>This can happen if peer restarted</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,6 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Any run time exception message at peer side, usually this will be thrown when if there was problem in database connectivity, unexpected value, unchecked null vale and so on</li> |
||||||
|
<li>Make sure runtime exceptions from Database,Network and File resources are caught and written in console</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,6 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>Any runtime exception message on server side,usually this will be thrown when there is problem in database connectivity, unexpected value, unchecked null vale and so on. </li> |
||||||
|
<li>Make sure runtime exceptions from Database,Network and File resources are caught and written in console</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,5 @@ |
|||||||
|
<div style='margin:10px 0px 10px 0px border:1px solid #b0b0b0;padding:5px'> |
||||||
|
<ul style="list-style-type:circle;padding-left: 5px;margin-top: 0px;"> |
||||||
|
<li>This will happen when the next trigger time of the script arrived and still current triggered execution is waiting because of one or more dependecies not successfull.</li> |
||||||
|
</ul> |
||||||
|
</div> |
@ -0,0 +1,12 @@ |
|||||||
|
ignore.alarm=false |
||||||
|
|
||||||
|
#imonitor.url=http://10.153.64.31:5001/iMonitor/Responder.aspx |
||||||
|
imonitor.ip=127.0.0.1 |
||||||
|
imonitor.port=1777 |
||||||
|
|
||||||
|
#dump XML to file instead of sending it to iMonitor API |
||||||
|
alarm.dump=false |
||||||
|
#alarm.dump=true |
||||||
|
#alarm.dump.folder=/temp/scheduler-alarm/ |
||||||
|
|
||||||
|
|
@ -0,0 +1,13 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<Configuration status="WARN"> |
||||||
|
<Appenders> |
||||||
|
<Console name="CONSOLE" target="SYSTEM_OUT"> |
||||||
|
<PatternLayout pattern="%4p %d{HH:mm:ss,SSS} %C - %m%n" /> |
||||||
|
</Console> |
||||||
|
</Appenders> |
||||||
|
<Loggers> |
||||||
|
<Root level="ERROR"> |
||||||
|
<AppenderRef ref="CONSOLE"/> |
||||||
|
</Root> |
||||||
|
</Loggers> |
||||||
|
</Configuration> |
@ -0,0 +1,54 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.alarm; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import javax.swing.JOptionPane; |
||||||
|
import junit.framework.TestCase; |
||||||
|
|
||||||
|
/** |
||||||
|
* lib-alarm unit test |
||||||
|
*/ |
||||||
|
public class LibAlarmTest extends TestCase { |
||||||
|
|
||||||
|
/** |
||||||
|
* Test send alarm |
||||||
|
*/ |
||||||
|
public void testSendAlarm() |
||||||
|
{ |
||||||
|
|
||||||
|
try{ |
||||||
|
|
||||||
|
ArrayList<ThemeVO> themes=new ArrayList<ThemeVO>(); |
||||||
|
themes.add(new ThemeVO("computing")); |
||||||
|
themes.add(new ThemeVO("etrading")); |
||||||
|
|
||||||
|
// Remove the comment tag to test. The code are commented out to prevent sending alarm when installing this lib :
|
||||||
|
|
||||||
|
// send alarm (default) :
|
||||||
|
//Alarm.sendAlarm( themes, AlarmType.EMAIL, "Test subject", "Test message", false, true, false, null, null);
|
||||||
|
|
||||||
|
// send alarm with list of theme & a message :
|
||||||
|
//Alarm.sendAlarm( themes, "Test message 2");
|
||||||
|
|
||||||
|
// send alarm with a theme & a message :
|
||||||
|
//Alarm.sendAlarm( "computing", "Test message 3");
|
||||||
|
//JOptionPane.showMessageDialog(null, "send socket message done");
|
||||||
|
assertTrue(true); |
||||||
|
}catch(Exception e){ |
||||||
|
e.printStackTrace(); |
||||||
|
assertTrue(false); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,51 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>mysql</groupId> |
||||||
|
<artifactId>mysql-connector-java</artifactId> |
||||||
|
<version>5.1.12</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.servlet</groupId> |
||||||
|
<artifactId>servlet-api</artifactId> |
||||||
|
<version>2.5</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.kohsuke</groupId> |
||||||
|
<artifactId>libpam4j</artifactId> |
||||||
|
<version>1.8</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-codec</groupId> |
||||||
|
<artifactId>commons-codec</artifactId> |
||||||
|
<version>1.2</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,42 @@ |
|||||||
|
<?xml version="1.0"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-auth</artifactId> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>lib-auth</name> |
||||||
|
<description>Wiki authentication, Superuser authentication, Get user themes access permission</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>mysql</groupId> |
||||||
|
<artifactId>mysql-connector-java</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.servlet</groupId> |
||||||
|
<artifactId>servlet-api</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.kohsuke</groupId> |
||||||
|
<artifactId>libpam4j</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-codec</groupId> |
||||||
|
<artifactId>commons-codec</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||||
|
</properties> |
||||||
|
</project> |
@ -0,0 +1,148 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* The DBManager class provides an Access Interface between the Database and Java. |
||||||
|
* It can be used to get data from the database, insert new data and update existing data. |
||||||
|
* The config file containing the details for the database hostname and credentials is located in the resources folder. |
||||||
|
*/ |
||||||
|
class DBManager { |
||||||
|
|
||||||
|
/** |
||||||
|
* The database name for the current instance of DBManager |
||||||
|
*/ |
||||||
|
private String dbName; |
||||||
|
|
||||||
|
/** |
||||||
|
* The connection string for the database connection. Stored in config file |
||||||
|
*/ |
||||||
|
private String connectionString; |
||||||
|
|
||||||
|
/** |
||||||
|
* The resultSet which contains the returned results from the SQL Query of GetDatabase |
||||||
|
*/ |
||||||
|
ResultSet resultSet = null; |
||||||
|
|
||||||
|
/** |
||||||
|
* The connection object of the current connection. |
||||||
|
*/ |
||||||
|
private Connection conn = null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Initialize the DBManager with the database name. |
||||||
|
* @param dbName The name of the database e.x. trading, tradingRef, fundamentals |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public DBManager(String dbName) throws IOException |
||||||
|
{ |
||||||
|
this.dbName = dbName; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This function connects to the dbName database; |
||||||
|
* @throws SQLException This is thrown incase we are not able to connect to the database; |
||||||
|
* @throws ClassNotFoundException This is thrown incase the driver is not found on this machine |
||||||
|
* @throws IOException This is thrown incase the config file if not found on this machine under resources folder |
||||||
|
*/ |
||||||
|
public void connect() throws SQLException, ClassNotFoundException, IOException |
||||||
|
{ |
||||||
|
//String url = "jdbc:jtds:sqlserver://"+databaseServerAddress+";DatabaseName="+databaseName;
|
||||||
|
String driver = Utils.GetConfigValue("database_"+dbName.toLowerCase()+"_"+"driver"); |
||||||
|
|
||||||
|
Class.forName(driver); |
||||||
|
conn = DriverManager.getConnection(Utils.GetConfigValue("database_"+dbName.toLowerCase()+"_"+"connstring")); |
||||||
|
connectionString = conn.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Closes the current Database connection. |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public void closeConnection() throws SQLException |
||||||
|
{ |
||||||
|
if(!conn.isClosed()) |
||||||
|
conn.close(); |
||||||
|
if(resultSet!=null) |
||||||
|
resultSet.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This function returns the result set of the SQL Query used by GetDatabase; |
||||||
|
* @param query The SQL Query passed to it. |
||||||
|
* @return |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
private ResultSet executeQuery(String query) throws SQLException |
||||||
|
{ |
||||||
|
Date start = new Date(); |
||||||
|
Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); |
||||||
|
resultSet = statement.executeQuery(query); |
||||||
|
Date end = new Date(); |
||||||
|
long duration = (end.getTime() - start.getTime()); |
||||||
|
//Utils.Log("DEBUG: Query ("+query+") took "+duration+ " miliseconds");
|
||||||
|
return resultSet; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to query a database and access the resultant data in a ResultSet |
||||||
|
* @param tableName The name of the database table to be accessed |
||||||
|
* @param selectedFields A list of the values to be selected through the queries. <code>new ArrayList<String>();</code> |
||||||
|
* be passed to select all fields (*) |
||||||
|
* @param queryParams A hashmap containing the selection filters in the format <code>[column_name]=[value]</code> |
||||||
|
* @param customQuery Any additional parameters to be added after the Where clause. Could be a GROUP BY or ORDER BY |
||||||
|
* @return The resulting data in a ResultSet |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public ResultSet GetDatabase(String tableName,ArrayList<String> selectedFields, Map<String,Object> queryParams, String customQuery) throws SQLException |
||||||
|
{ |
||||||
|
String queryBuilder = ""; |
||||||
|
if(selectedFields.size()==0) |
||||||
|
{ |
||||||
|
selectedFields.add("*"); |
||||||
|
} |
||||||
|
|
||||||
|
queryBuilder += "SELECT "+Utils.Join(selectedFields,",")+" FROM "+tableName; |
||||||
|
|
||||||
|
if(queryParams != null && queryParams.size()>0) |
||||||
|
{ |
||||||
|
queryBuilder += " WHERE "; |
||||||
|
for (Map.Entry<String,Object> entry : queryParams.entrySet()) { |
||||||
|
|
||||||
|
try{ |
||||||
|
Float f = Float.parseFloat(entry.getValue().toString()); |
||||||
|
queryBuilder += " "+entry.getKey() + " = "+entry.getValue()+" AND"; |
||||||
|
} |
||||||
|
catch(Exception ex) |
||||||
|
{ |
||||||
|
queryBuilder += " "+entry.getKey() + " = '"+entry.getValue()+"' AND"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
if(customQuery!= null && customQuery!="") |
||||||
|
queryBuilder += customQuery+" AND"; |
||||||
|
queryBuilder = queryBuilder.substring(0,queryBuilder.length()-3); |
||||||
|
} |
||||||
|
//System.out.println(queryBuilder);
|
||||||
|
return executeQuery(queryBuilder); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,126 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
import org.jvnet.libpam.PAM; |
||||||
|
import org.jvnet.libpam.PAMException; |
||||||
|
import org.jvnet.libpam.UnixUser; |
||||||
|
|
||||||
|
/** |
||||||
|
* PAMAuthentication will authenticate user to local unix machine using PAM. |
||||||
|
* This class is a wrapper of libpam4j, a Java/PAM bindings using JNA, to use internally in 4ECaps. |
||||||
|
*/ |
||||||
|
public class PAMAuthentication { |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether user is exist |
||||||
|
* @param username Username |
||||||
|
* @return true if user is exist |
||||||
|
*/ |
||||||
|
public static boolean isExist(String username) { |
||||||
|
return UnixUser.exists(username); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get current user logged in Unix system |
||||||
|
* @return username of user logged in |
||||||
|
*/ |
||||||
|
public static String getCurrentUserLoggedIn() { |
||||||
|
return System.getProperty("user.name"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get username of current user logged in |
||||||
|
* @return username of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static String getUsername() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getUserName(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get UID of current user logged in |
||||||
|
* @return UID of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static int getUID() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getUID(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get GID of current user logged in |
||||||
|
* @return GID of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static int getGID() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getGID(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get gecos (the real name) of current user logged in |
||||||
|
* @return gecos of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static String getGecos() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getGecos(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get home directory of current user logged in |
||||||
|
* @return home directory of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static String getDir() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getDir(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the shell of current user logged in |
||||||
|
* @return the shell of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static String getShell() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getShell(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the groups that user logged in belongs to |
||||||
|
* @return the groups of user logged in |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static Set<String> getGroups() throws PAMException { |
||||||
|
UnixUser ux = new UnixUser(getCurrentUserLoggedIn()); |
||||||
|
return ux.getGroups(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Authenticate user |
||||||
|
* @param service Service |
||||||
|
* @param username Username |
||||||
|
* @param password Password |
||||||
|
* @return authenticated user in UnixUser object |
||||||
|
* @throws PAMException |
||||||
|
*/ |
||||||
|
public static UnixUser authenticate(String service, String username, String password) throws PAMException { |
||||||
|
PAM p = new PAM(service); |
||||||
|
return p.authenticate(username, password); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,177 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.BufferedWriter; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.FileWriter; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.MessageDigest; |
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Hex; |
||||||
|
|
||||||
|
/** |
||||||
|
* SuperUserAuthentication provides mechanism to store password into a file. |
||||||
|
* This mechanism is implemented in superuser authentication of an application. |
||||||
|
* The config file containing the path of saved password located in the resources folder. |
||||||
|
*/ |
||||||
|
public class SuperUserAuthentication { |
||||||
|
|
||||||
|
/** |
||||||
|
* Private constructor to prevent instantiation. |
||||||
|
*/ |
||||||
|
private SuperUserAuthentication() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Password filename that will be created in the folder path. |
||||||
|
*/ |
||||||
|
private static String passwordFilename = "superuser.pwd"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Validate password whether it equals with the encrypted file, if file is not exist then set the password by creating it. |
||||||
|
* @param pwd Password |
||||||
|
* @return true if process succeed |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static boolean validateOrSet(String pwd) throws Exception { |
||||||
|
File file=getPwdFile(); |
||||||
|
String encpwd=null; |
||||||
|
boolean rtn=false; |
||||||
|
if(file.exists()){ |
||||||
|
encpwd=readFile(file); |
||||||
|
} |
||||||
|
if(encpwd!=null && !encpwd.equals("")){ |
||||||
|
rtn=isValid(pwd,encpwd); |
||||||
|
}else{ |
||||||
|
setPassword(pwd); |
||||||
|
rtn=true; |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Change password to a new one if password is valid |
||||||
|
* @param pwd Password |
||||||
|
* @param newpassword New password |
||||||
|
* @return true if process succeed |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static boolean changePwd(String pwd,String newpassword) throws Exception { |
||||||
|
boolean rtn=validateOrSet(pwd); |
||||||
|
|
||||||
|
if(rtn){ |
||||||
|
//Thread.sleep(1000); //wait till it closes the stream ....
|
||||||
|
setPassword(newpassword); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether password is valid, compared to encrypted password |
||||||
|
* @param password Password |
||||||
|
* @param encpass Encrypted password |
||||||
|
* @return true if encrypted password equals salt password |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static boolean isValid(String password, String encpass) throws Exception { |
||||||
|
String salt=encpass.split(":")[2]; |
||||||
|
String saltpass=":B:"+salt+":"+getMD5(salt+"-"+getMD5(password)); |
||||||
|
if(encpass.equals(saltpass)){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get MD5 of source string |
||||||
|
* @param source Source string |
||||||
|
* @return MD5 string |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static String getMD5(String source) throws Exception { |
||||||
|
|
||||||
|
byte[] bytesOfMessage = source.getBytes(); |
||||||
|
|
||||||
|
java.security.MessageDigest md = MessageDigest.getInstance("MD5"); |
||||||
|
byte[] thedigest = md.digest(bytesOfMessage); |
||||||
|
|
||||||
|
final String result = new String(Hex.encodeHex(thedigest)); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Set password to encrypted file |
||||||
|
* @param plain_pwd Plain password |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static void setPassword(String plain_pwd) throws Exception { |
||||||
|
BufferedWriter writer = null; |
||||||
|
try { |
||||||
|
String salt="d1e93dec"; |
||||||
|
String saltpass=":B:"+salt+":"+getMD5(salt+"-"+getMD5(plain_pwd)); |
||||||
|
File file=getPwdFile(); |
||||||
|
writer = new BufferedWriter(new FileWriter(file)); |
||||||
|
writer.write(saltpass); |
||||||
|
} |
||||||
|
finally { |
||||||
|
if (writer != null) writer.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get password file |
||||||
|
* @return file |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static File getPwdFile() throws Exception { |
||||||
|
String root = Utils.GetConfigValue("superuser_password_folder"); |
||||||
|
File file =new File(root + passwordFilename); |
||||||
|
if ( !file.exists() ) { |
||||||
|
file.createNewFile(); |
||||||
|
} |
||||||
|
return file; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Read file |
||||||
|
* @param path Path file |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private static String readFile(File path) throws IOException { |
||||||
|
StringBuilder contents = new StringBuilder(); |
||||||
|
BufferedReader input = null; |
||||||
|
try { |
||||||
|
input = new BufferedReader(new FileReader(path)); |
||||||
|
String line = input.readLine(); |
||||||
|
if (line != null) { |
||||||
|
contents.append(line); |
||||||
|
} |
||||||
|
} |
||||||
|
finally { |
||||||
|
if (input != null) input.close(); |
||||||
|
} |
||||||
|
return contents.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,30 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
public class SystemAuthentication { |
||||||
|
|
||||||
|
/** |
||||||
|
* Get current user logged in Unix system |
||||||
|
* @return username of user logged in |
||||||
|
*/ |
||||||
|
public static String getCurrentUserLoggedIn() { |
||||||
|
return System.getProperty("user.name"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether a user logged in to the system |
||||||
|
* @return true if user logged in |
||||||
|
*/ |
||||||
|
public static boolean isUserLoggedIn() { |
||||||
|
return (null != getCurrentUserLoggedIn() && !"".equals(getCurrentUserLoggedIn())); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,147 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* UserThemeAccessPermission provides functions to convert theme access permissions into 'rwx' permission group. |
||||||
|
* Example : a user has 'X' permission in 'computing' theme. The 'computing' theme then will be included in 'rwx' permission group. |
||||||
|
* Another Example : a user has 'U' permission in 'etrading' theme. The 'etrading' theme then will be included in 'rx' permission group. |
||||||
|
*/ |
||||||
|
public class UserThemeAccessPermission { |
||||||
|
|
||||||
|
/** |
||||||
|
* Username |
||||||
|
*/ |
||||||
|
private String username; |
||||||
|
|
||||||
|
/** |
||||||
|
* 'rwx' permission group |
||||||
|
*/ |
||||||
|
private ArrayList<String> rwx = new ArrayList<String>(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 'rx' permission group |
||||||
|
*/ |
||||||
|
private ArrayList<String> rx = new ArrayList<String>(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 'r' permission group |
||||||
|
*/ |
||||||
|
private ArrayList<String> r = new ArrayList<String>(); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor. Creates a new UserThemeAccessPermission object |
||||||
|
* @param un Username |
||||||
|
*/ |
||||||
|
public UserThemeAccessPermission(String un) { |
||||||
|
this.username=un; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get rwx permission group |
||||||
|
* @return rwx list |
||||||
|
*/ |
||||||
|
public ArrayList<String> getRwx() { |
||||||
|
return rwx; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get rx permission group |
||||||
|
* @return rx list |
||||||
|
*/ |
||||||
|
public ArrayList<String> getRx() { |
||||||
|
return rx; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get r permission group |
||||||
|
* @return r list |
||||||
|
*/ |
||||||
|
public ArrayList<String> getR() { |
||||||
|
return r; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Add permission with user's themes |
||||||
|
* @param themes |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void addPermissionWithThemes(Map<String,String> themes) throws Exception { |
||||||
|
try{ |
||||||
|
Map<String,String> resolved = this.replacePermissions(themes); |
||||||
|
for(Iterator<String> it=resolved.keySet().iterator();it.hasNext();){ |
||||||
|
String theme=it.next(); |
||||||
|
String val=resolved.get(theme); |
||||||
|
if(val!=null && val.trim().equalsIgnoreCase("rwx")) getRwx().add(theme); |
||||||
|
if(val!=null && val.trim().equalsIgnoreCase("rx")) getRx().add(theme); |
||||||
|
if(val!=null && val.trim().equalsIgnoreCase("r")) getR().add(theme); |
||||||
|
} |
||||||
|
} catch(Exception e) { |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Replace the permission letter with 'rwx'. |
||||||
|
* @param data |
||||||
|
* @return themes with 'rwx' permissions |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static Map<String,String> replacePermissions(Map<String,String> data) throws Exception { |
||||||
|
HashMap<String,String> perm = new HashMap<String,String>(); |
||||||
|
perm.put("X","rwx"); |
||||||
|
perm.put("S","rwx"); |
||||||
|
perm.put("B","rwx"); |
||||||
|
perm.put("C","rwx"); |
||||||
|
perm.put("U","rx"); |
||||||
|
perm.put("N","r"); |
||||||
|
perm.put("M","rwx"); |
||||||
|
for(String key: data.keySet()){ |
||||||
|
data.put(key, perm.get(data.get(key))); |
||||||
|
} |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Overriding to make unique objects per username |
||||||
|
* @param obj Instance of AuthUser or other object |
||||||
|
* @return true if obj's username is equal with class' username |
||||||
|
*/ |
||||||
|
public boolean equals(Object obj ) { |
||||||
|
if(obj instanceof UserThemeAccessPermission){ |
||||||
|
UserThemeAccessPermission other=(UserThemeAccessPermission)obj; |
||||||
|
if(other.username.equals(this.username)){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Override toString() method |
||||||
|
* @return username string |
||||||
|
*/ |
||||||
|
public String toString() { |
||||||
|
return ""+this.username; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,82 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
/** |
||||||
|
* This class contains Static Utility functions |
||||||
|
*/ |
||||||
|
class Utils { |
||||||
|
|
||||||
|
/** |
||||||
|
* Accepts an ArrayList of strings and then returns a delimiter separated string |
||||||
|
* @param al The arraylist of strings |
||||||
|
* @param delimiter The delimiter |
||||||
|
* @return The delimiter separated string |
||||||
|
*/ |
||||||
|
protected static String Join(ArrayList<String> al,String delimiter) |
||||||
|
{ |
||||||
|
return al.toString().replaceAll("\\[|\\]", "").replaceAll(", ",delimiter); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the value of a property defined in config file |
||||||
|
* @param propertyName - the name or key of the property you want to retrieve |
||||||
|
* @return the string value |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
protected static String GetConfigValue(String propertyName) throws IOException |
||||||
|
{ |
||||||
|
Properties prop = new Properties(); |
||||||
|
String propFileName = "config_auth.properties"; |
||||||
|
|
||||||
|
InputStream inputStream = Utils.class.getClassLoader().getResourceAsStream(propFileName); |
||||||
|
|
||||||
|
if (inputStream != null) { |
||||||
|
prop.load(inputStream); |
||||||
|
} else { |
||||||
|
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); |
||||||
|
} |
||||||
|
|
||||||
|
Date time = new Date(System.currentTimeMillis()); |
||||||
|
|
||||||
|
// get the property value and print it out
|
||||||
|
String value = prop.getProperty(propertyName); |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Capitalize first char of a word. |
||||||
|
* Example : 'this is text. another text' will be converted to 'This Is Text. Another Text' |
||||||
|
* @param string |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected static String capitalizeString(String string) { |
||||||
|
char[] chars = string.toLowerCase().toCharArray(); |
||||||
|
boolean found = false; |
||||||
|
for (int i = 0; i < chars.length; i++) { |
||||||
|
if (!found && Character.isLetter(chars[i])) { |
||||||
|
chars[i] = Character.toUpperCase(chars[i]); |
||||||
|
found = true; |
||||||
|
} else if (Character.isWhitespace(chars[i]) || chars[i]=='.' || chars[i]=='\'') { // You can add other chars here
|
||||||
|
found = false; |
||||||
|
} |
||||||
|
} |
||||||
|
return String.valueOf(chars); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,176 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Hex; |
||||||
|
|
||||||
|
/** |
||||||
|
* WikiAuthentication will check / validate user authentication to Wiki database. |
||||||
|
* It also provide functions to get encrypted password of specific user & get list of Wiki users. |
||||||
|
*/ |
||||||
|
public class WikiAuthentication { |
||||||
|
|
||||||
|
public static final String SESSION_LOGGED_USER = "session^logged^user"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Private constructor to prevent instantiation. |
||||||
|
*/ |
||||||
|
private WikiAuthentication() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Validate Wiki User. If user_name is valid & password being encrypted equals value in database then it will return true. |
||||||
|
* @param user_name |
||||||
|
* @param password |
||||||
|
* @return is user valid |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static boolean validateUser(String user_name, String password) throws Exception { |
||||||
|
String encpass = getEncryptedPwd(user_name); |
||||||
|
return isValid(password,encpass); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Validate Wiki User With Encrypted Password. If user_name is valid & encrypted password equals value in database then it will return true. |
||||||
|
* @param user_name |
||||||
|
* @param encryptedPassword |
||||||
|
* @return is user valid |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static boolean validateUserEncryptedPassword(String user_name, String encryptedPassword) throws Exception { |
||||||
|
String encpass = getEncryptedPwd(user_name); |
||||||
|
if (encryptedPassword == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return (encryptedPassword.equals(encpass)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether password is valid, compare to encrypted password |
||||||
|
* @param password Password |
||||||
|
* @param encpass Encrypted password |
||||||
|
* @return true if encrypted password equals salt password |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static boolean isValid(String password, String encpass) throws Exception { |
||||||
|
if (encpass == null || password == null) return false; |
||||||
|
String salt=encpass.split(":")[2]; |
||||||
|
String saltpass=":B:"+salt+":"+getMD5(salt+"-"+getMD5(password)); |
||||||
|
if(encpass.equals(saltpass)){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get MD5 of source string |
||||||
|
* @param source Source string |
||||||
|
* @return MD5 string |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static String getMD5(String source) throws Exception { |
||||||
|
|
||||||
|
byte[] bytesOfMessage = source.getBytes(); |
||||||
|
|
||||||
|
java.security.MessageDigest md = MessageDigest.getInstance("MD5"); |
||||||
|
byte[] thedigest = md.digest(bytesOfMessage); |
||||||
|
|
||||||
|
final String result = new String(Hex.encodeHex(thedigest)); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* List / get all Wiki users. The fields returned are : user_name, user_real_name, user_password, user_email. |
||||||
|
* @return users |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static Vector<HashMap<String, String>> listUsers() throws Exception { |
||||||
|
|
||||||
|
Vector<HashMap<String, String>> rtn = null; |
||||||
|
|
||||||
|
DBManager dbm = new DBManager("wiki"); |
||||||
|
dbm.connect(); |
||||||
|
|
||||||
|
//sql = "select user_name,user_real_name,user_password,user_email from user";
|
||||||
|
|
||||||
|
ArrayList<String> selectedFields = new ArrayList<String>(); |
||||||
|
selectedFields.add("user_name"); |
||||||
|
selectedFields.add("user_real_name"); |
||||||
|
selectedFields.add("user_password"); |
||||||
|
selectedFields.add("user_email"); |
||||||
|
|
||||||
|
ResultSet rs = dbm.GetDatabase("user", selectedFields, null, null); |
||||||
|
|
||||||
|
rtn = new Vector<HashMap<String, String>>(); |
||||||
|
|
||||||
|
while(rs.next()){ |
||||||
|
String user_name=rs.getString("user_name"); |
||||||
|
String user_real_name=rs.getString("user_real_name"); |
||||||
|
String user_password=rs.getString("user_password"); |
||||||
|
String user_email=rs.getString("user_email"); |
||||||
|
HashMap<String, String> h=new HashMap<String, String>(); |
||||||
|
h.put("user_name",user_name ); |
||||||
|
h.put("user_real_name",user_real_name ); |
||||||
|
h.put("user_password",user_password ); |
||||||
|
h.put("user_email",user_email ); |
||||||
|
rtn.add(h); |
||||||
|
} |
||||||
|
dbm.closeConnection(); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get encrypted password of specific user |
||||||
|
* @param user |
||||||
|
* @return encrypted password |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String getEncryptedPwd(String user) throws Exception { |
||||||
|
|
||||||
|
if ((user == null) || user.equals("")) return null; |
||||||
|
|
||||||
|
String rtn = null; |
||||||
|
|
||||||
|
DBManager dbm = new DBManager("wiki"); |
||||||
|
dbm.connect(); |
||||||
|
|
||||||
|
//sql = "select CAST(user_password AS CHAR(10000) CHARACTER SET utf8) as pass from user where user_name=?"
|
||||||
|
|
||||||
|
ArrayList<String> selectedFields = new ArrayList<String>(); |
||||||
|
selectedFields.add("CAST(user_password AS CHAR(10000) CHARACTER SET utf8) as pass"); |
||||||
|
|
||||||
|
Map<String,Object> queryParams = new HashMap<String,Object>(); |
||||||
|
queryParams.put("user_name", Utils.capitalizeString(user)); |
||||||
|
|
||||||
|
ResultSet rs = dbm.GetDatabase("user", selectedFields, queryParams, null); |
||||||
|
|
||||||
|
while(rs.next()){ |
||||||
|
rtn=rs.getString("pass"); |
||||||
|
} |
||||||
|
dbm.closeConnection(); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,99 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.HttpServlet; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
|
||||||
|
/** |
||||||
|
* WikiAuthenticationServlet is a servlet to facilitate automatic Wiki authentication. |
||||||
|
* How to use this servlet, see documentation : http://wiki.4ecap.com/4ECwiki/Lib-auth#Automatic_Wiki_Authentication.
|
||||||
|
*/ |
||||||
|
public class WikiAuthenticationServlet extends HttpServlet { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private static final String LOGOUT = "logout"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Handle post request, validate username & encrypted password by comparing them with Wiki database. |
||||||
|
* If valid, generate session to be used throughout the app then redirect to app url. |
||||||
|
* If not valid, redirect to wiki login url. |
||||||
|
* @param request request |
||||||
|
* @param response response |
||||||
|
*/ |
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||||
|
|
||||||
|
try { |
||||||
|
|
||||||
|
// get request parameters :
|
||||||
|
String username = request.getParameter("username"); |
||||||
|
String encryptedPassword = request.getParameter("encryptedPassword"); |
||||||
|
String redirectUrl = request.getParameter("redirectUrl"); |
||||||
|
|
||||||
|
// get wiki login url from config file
|
||||||
|
String wikiLoginUrl = Utils.GetConfigValue("wiki_login_url"); |
||||||
|
|
||||||
|
// if there's already session then redirect to app url
|
||||||
|
if (request.getSession().getAttribute(WikiAuthentication.SESSION_LOGGED_USER) != null) { |
||||||
|
response.sendRedirect(redirectUrl); |
||||||
|
} |
||||||
|
|
||||||
|
// if there's null parameter then redirect to wiki login
|
||||||
|
else if (username == null || encryptedPassword == null || redirectUrl == null) { |
||||||
|
response.sendRedirect(wikiLoginUrl); |
||||||
|
} |
||||||
|
|
||||||
|
// validate username & encrypted password, if valid then redirect to app url
|
||||||
|
else if (WikiAuthentication.validateUserEncryptedPassword(username, encryptedPassword)) { |
||||||
|
// set session for app using lib-auth
|
||||||
|
request.getSession().setAttribute(WikiAuthentication.SESSION_LOGGED_USER, username); |
||||||
|
response.sendRedirect(redirectUrl); |
||||||
|
} |
||||||
|
|
||||||
|
// else, redirect to wiki login
|
||||||
|
else { |
||||||
|
response.sendRedirect(wikiLoginUrl); |
||||||
|
} |
||||||
|
|
||||||
|
}catch(Exception e){ |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Handle get request, logout (remove session) and redirect to a url. |
||||||
|
* @param request request |
||||||
|
* @param response response |
||||||
|
*/ |
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||||
|
|
||||||
|
String method = request.getParameter("method"); |
||||||
|
|
||||||
|
// logout, remove session
|
||||||
|
if(method != null && method.equals(this.LOGOUT)) { |
||||||
|
if (request.getSession().getAttribute(WikiAuthentication.SESSION_LOGGED_USER) != null) { |
||||||
|
request.getSession().removeAttribute(WikiAuthentication.SESSION_LOGGED_USER); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// redirect to Wiki page
|
||||||
|
response.sendRedirect(Utils.GetConfigValue("wiki_login_url")); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@ |
|||||||
|
database_wiki_connstring=jdbc:mysql://wiki.4ecap.com/4EwikiDB1?user=4ecremoteuser&password=4ecrmt2011 |
||||||
|
database_wiki_driver=com.mysql.jdbc.Driver |
||||||
|
|
||||||
|
wiki_login_url=http://wiki.4ecap.com |
||||||
|
|
||||||
|
superuser_password_folder=/tmp/ |
||||||
|
#superuser_password_folder=d:\\tmp\\ |
@ -0,0 +1,13 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<Configuration status="WARN"> |
||||||
|
<Appenders> |
||||||
|
<Console name="CONSOLE" target="SYSTEM_OUT"> |
||||||
|
<PatternLayout pattern="%4p %d{HH:mm:ss,SSS} %C - %m%n" /> |
||||||
|
</Console> |
||||||
|
</Appenders> |
||||||
|
<Loggers> |
||||||
|
<Root level="ERROR"> |
||||||
|
<AppenderRef ref="CONSOLE"/> |
||||||
|
</Root> |
||||||
|
</Loggers> |
||||||
|
</Configuration> |
@ -0,0 +1,215 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.auth; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
import javax.swing.JOptionPane; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
import junit.framework.Assert; |
||||||
|
import junit.framework.TestCase; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* lib-auth unit test |
||||||
|
*/ |
||||||
|
public class LibAuthTest extends TestCase { |
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(LibAuthTest.class.getName()); |
||||||
|
|
||||||
|
/** |
||||||
|
* Wiki authentication test : login, check login, get authenticated user, get user access. |
||||||
|
*/ |
||||||
|
public void testWikiAuthentication() |
||||||
|
{ |
||||||
|
log.debug(">>>>>> testWikiAuthentication()"); |
||||||
|
try { |
||||||
|
|
||||||
|
// wiki login :
|
||||||
|
String user = "bot"; |
||||||
|
String password = "bot2018"; |
||||||
|
|
||||||
|
boolean success= WikiAuthentication.validateUser(user, password); // validate wiki user
|
||||||
|
log.debug("validate wiki user : " + success); |
||||||
|
JOptionPane.showMessageDialog(null, "validate wiki user success"); |
||||||
|
|
||||||
|
HashMap<String, String> loginMap = new HashMap<String, String>(); |
||||||
|
if(!success){ |
||||||
|
loginMap.put("message", "Invalid username or password"); |
||||||
|
Assert.assertTrue(false); // scenario : login must success
|
||||||
|
}else{ |
||||||
|
loginMap.put("authenticatedUser", user); |
||||||
|
// example : get encrypted password and store it to map for further process
|
||||||
|
String pss = WikiAuthentication.getEncryptedPwd(user); |
||||||
|
loginMap.put("encryptedPassword", pss); |
||||||
|
} |
||||||
|
|
||||||
|
// store validate user result to map
|
||||||
|
loginMap.put("loggedin", Boolean.toString(success)); |
||||||
|
|
||||||
|
// check whether user login / not :
|
||||||
|
boolean loggedin = Boolean.parseBoolean(loginMap.get("loggedin")); |
||||||
|
log.debug("is user logged in : " + loggedin); |
||||||
|
Assert.assertTrue(loggedin); |
||||||
|
|
||||||
|
// get authenticated user :
|
||||||
|
String authenticatedUser = loginMap.get("authenticatedUser"); |
||||||
|
log.debug("get authenticatedUser : " + authenticatedUser); |
||||||
|
|
||||||
|
// Get user access. Use dummy themes for testing purpose.
|
||||||
|
// To get themes from infrastructureDB : Map themes = infrastructureDB.getThemes4Users(user). It needs lib-db library.
|
||||||
|
Map<String, String> themes= new HashMap<String, String>(); |
||||||
|
themes.put("computing", "X"); |
||||||
|
themes.put("etrading", "U"); |
||||||
|
themes.put("execution", "N"); |
||||||
|
themes.put("bb", "B"); |
||||||
|
|
||||||
|
UserThemeAccessPermission userTheme = new UserThemeAccessPermission(user); |
||||||
|
userTheme.addPermissionWithThemes(themes); |
||||||
|
ArrayList<String> rwxList = userTheme.getRwx(); |
||||||
|
log.debug("rwxList : "); |
||||||
|
for (String rwx : rwxList) { |
||||||
|
log.debug("- " + rwx); |
||||||
|
} |
||||||
|
Assert.assertTrue(rwxList.contains("computing") && rwxList.contains("bb")); // getRwx() must contains 'computing' & 'bb'
|
||||||
|
|
||||||
|
ArrayList<String> rxList = userTheme.getRx(); |
||||||
|
log.debug("rxList : "); |
||||||
|
for (String rx : rxList) { |
||||||
|
log.debug("- " + rx); |
||||||
|
} |
||||||
|
Assert.assertTrue(rxList.contains("etrading")); // getRx() must contains 'etrading'
|
||||||
|
|
||||||
|
ArrayList<String> rList = userTheme.getR(); |
||||||
|
log.debug("rList : "); |
||||||
|
for (String r : rList) { |
||||||
|
log.debug("- " + r); |
||||||
|
} |
||||||
|
Assert.assertTrue(rList.contains("execution")); // getR() must contains 'execution'
|
||||||
|
} |
||||||
|
catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
assertTrue( false ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Super user authentication test : validate / set / change password, check login, get authenticated user |
||||||
|
*/ |
||||||
|
public void testSuperUserAuthentication() |
||||||
|
{ |
||||||
|
log.debug(">>>>>> testSuperUserAuthentication()"); |
||||||
|
try { |
||||||
|
|
||||||
|
String user = "administrator"; |
||||||
|
String password = "password1"; |
||||||
|
String newpassword = "password1"; |
||||||
|
|
||||||
|
Map<String, String> loginMap = new HashMap<String, String>(); |
||||||
|
boolean success = false; |
||||||
|
|
||||||
|
// if user is 'administrator' and newpassword is not null & not empty then it's a change password :
|
||||||
|
if(user.equalsIgnoreCase("administrator") && newpassword!=null && !newpassword.equals("")){ |
||||||
|
|
||||||
|
// Remove the comment tag to test. The code are commented out to prevent creating password file when installing this lib (edit properties file first) :
|
||||||
|
//success = SuperUserAuthentication.changePwd(password,newpassword);
|
||||||
|
//temporary var value when install this lib :
|
||||||
|
success = true; |
||||||
|
|
||||||
|
//log.debug("change superuser password : " + newpassword);
|
||||||
|
//JOptionPane.showMessageDialog(null, "Change superuser password done. Password located in /tmp/superuser.pwd");
|
||||||
|
} |
||||||
|
// else : validate if password is already set or set password if password has not been set :
|
||||||
|
else{ |
||||||
|
|
||||||
|
// Remove the comment tag to test. The code are commented out to prevent creating password file when installing this lib (edit properties file first) :
|
||||||
|
//success= SuperUserAuthentication.validateOrSet(password);
|
||||||
|
//temporary var value when install this lib :
|
||||||
|
success = true; |
||||||
|
|
||||||
|
//log.debug("validate / set superuser password : " + password);
|
||||||
|
//JOptionPane.showMessageDialog(null, "validate/set superuser password");
|
||||||
|
} |
||||||
|
|
||||||
|
if(!success){ |
||||||
|
loginMap.put("message", "Invalid username or password"); |
||||||
|
Assert.assertTrue(false); // scenario : login must success
|
||||||
|
} |
||||||
|
else { |
||||||
|
loginMap.put("authenticatedUser", user); |
||||||
|
} |
||||||
|
loginMap.put("loggedin", Boolean.toString(success)); // store validate superuser result to map
|
||||||
|
|
||||||
|
// check whether login / not :
|
||||||
|
boolean loggedin = Boolean.parseBoolean(loginMap.get("loggedin")); |
||||||
|
log.debug("is superuser logged in : " + loggedin); |
||||||
|
Assert.assertTrue(loggedin); |
||||||
|
|
||||||
|
// get authenticated user :
|
||||||
|
String authenticated_user = loginMap.get("authenticatedUser"); |
||||||
|
log.debug("authenticated superuser : " + authenticated_user); |
||||||
|
|
||||||
|
//Assert.assertTrue(true);
|
||||||
|
} |
||||||
|
catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* List Wiki users test |
||||||
|
*/ |
||||||
|
public void testListWikiUsers() |
||||||
|
{ |
||||||
|
log.debug(">>>>>> testListWikiUsers()"); |
||||||
|
try { |
||||||
|
Vector<HashMap<String, String>> result = WikiAuthentication.listUsers(); |
||||||
|
|
||||||
|
log.debug("wiki user count : " + result.size()); |
||||||
|
JOptionPane.showMessageDialog(null, "Wiki user count: "+result.size()); |
||||||
|
|
||||||
|
for (int i=0; i<result.size(); i++) { |
||||||
|
HashMap<String, String> h = (HashMap<String, String>) result.get(i); |
||||||
|
/* |
||||||
|
log.debug(">>>>>>>>>> user_name : " + h.get("user_name")); |
||||||
|
log.debug(">>>>>>>>>> user_real_name : " + h.get("user_real_name")); |
||||||
|
log.debug(">>>>>>>>>> user_password : " + h.get("user_password")); |
||||||
|
log.debug(">>>>>>>>>> user_email : " + h.get("user_email")); |
||||||
|
*/ |
||||||
|
} |
||||||
|
assertTrue( true ); |
||||||
|
} |
||||||
|
catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
assertTrue( false ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* System authentication test |
||||||
|
*/ |
||||||
|
public void testSystemAuthentication() |
||||||
|
{ |
||||||
|
log.debug(">>>>>> testSystemAuthentication()"); |
||||||
|
log.debug("SystemAuthentication.isUserLoggedIn() : " + SystemAuthentication.isUserLoggedIn()); |
||||||
|
|
||||||
|
assertTrue( SystemAuthentication.isUserLoggedIn() ); |
||||||
|
//assertTrue( true );
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,57 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<version>2.0</version> |
||||||
|
<licenses> |
||||||
|
<license> |
||||||
|
<name>The software is only allowed to be used in Four Elements - no license is given to any other parties</name> |
||||||
|
</license> |
||||||
|
</licenses> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-dbutils</groupId> |
||||||
|
<artifactId>commons-dbutils</artifactId> |
||||||
|
<version>1.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.commons</groupId> |
||||||
|
<artifactId>commons-jcs-core</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.jolbox</groupId> |
||||||
|
<artifactId>bonecp</artifactId> |
||||||
|
<version>0.7.1.RELEASE</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>mysql</groupId> |
||||||
|
<artifactId>mysql-connector-java</artifactId> |
||||||
|
<version>5.1.12</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.microsoft.sqlserver</groupId> |
||||||
|
<artifactId>mssql-jdbc</artifactId> |
||||||
|
<version>6.1.0.jre7</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
<scope>compile</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,53 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<parent> |
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<groupId>com.fourelementscapital</groupId> |
||||||
|
<artifactId>lib-db</artifactId> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>lib-db</name> |
||||||
|
<description>Lower level DAL (Data Access Layer) for database call</description> |
||||||
|
<url>http://www.fourelementscapital.com</url> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>commons-dbutils</groupId> |
||||||
|
<artifactId>commons-dbutils</artifactId> |
||||||
|
<version>1.1</version> |
||||||
|
</dependency> |
||||||
|
<!--Cache system used to get queue--> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.commons</groupId> |
||||||
|
<artifactId>commons-jcs-core</artifactId> |
||||||
|
<version>2.2</version> |
||||||
|
</dependency> |
||||||
|
<!--JCS's required dependency--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.jolbox</groupId> |
||||||
|
<artifactId>bonecp</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>mysql</groupId> |
||||||
|
<artifactId>mysql-connector-java</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.microsoft.sqlserver</groupId> |
||||||
|
<artifactId>mssql-jdbc</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.8.1</version> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
@ -0,0 +1,345 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.commons.dbutils.BasicRowProcessor; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* This abstract class implements the methods that are related to Theme organisation tags |
||||||
|
*/ |
||||||
|
public abstract class AbstractTeamOrgDB extends SuperDB{ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag table |
||||||
|
* @return tag table |
||||||
|
*/ |
||||||
|
public abstract String getTagTable(); //tags
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item table |
||||||
|
* @return tag item table |
||||||
|
*/ |
||||||
|
public abstract String getTagItemTable(); //example: scheduler_tags
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item id |
||||||
|
* @return tag item id |
||||||
|
*/ |
||||||
|
public abstract String getTagItemId(); // example: scheduler_id or function_id;
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item follow table |
||||||
|
* @return tag item follow table |
||||||
|
*/ |
||||||
|
public abstract String getTagItemFollowTable(); //example: scheduler_tags
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Returns list of All tags of the tool ( for example, if it was implemented for scheduler then it will return all scheduler themes) |
||||||
|
* @return tags |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Vector getTags() throws Exception { |
||||||
|
Vector rtn=new Vector(); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select * FROM "+getTagTable()+" ORDER BY tagname"); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
|
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get tags details |
||||||
|
* @param tags tag names |
||||||
|
* @return tags |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Vector getTagsDetails(String tags[]) throws Exception { |
||||||
|
Vector rtn=new Vector(); |
||||||
|
String stags=null; |
||||||
|
for(int i=0;i<tags.length;i++){ |
||||||
|
stags=(stags==null)?"'"+tags[i]+"'":stags+",'"+tags[i]+"'"; |
||||||
|
} |
||||||
|
|
||||||
|
if(stags!=null){ |
||||||
|
String query="select * FROM "+getTagTable()+" WHERE tagname IN ("+stags+") ORDER BY tagname"; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag ids by item id |
||||||
|
* @param item_id item id |
||||||
|
* @return tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Vector getTagIds4Item(int item_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select tag_id FROM "+getTagItemTable()+" WHERE "+getTagItemId()+"=?"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getInt("tag_id")); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get follow tag ids by item id |
||||||
|
* @param item_id item id |
||||||
|
* @return tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Vector getFollowTagIds4Item(int item_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select tag_id FROM "+getTagItemFollowTable()+" WHERE "+getTagItemId()+"=?"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getInt("tag_id")); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update tag ids by item id |
||||||
|
* @param item_id item id |
||||||
|
* @param tag_ids tag ids |
||||||
|
* @param removeExisting is remove existing |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void updateTagIds4Item(int item_id, Vector tag_ids,int removeExisting) throws Exception { |
||||||
|
if(SchedulerDB.REMOVE_BEFORE_UPDATE==removeExisting){ |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM "+getTagItemTable()+" WHERE "+getTagItemId()+"=?"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("INSERT INTO "+getTagItemTable()+"("+getTagItemId()+",tag_id) VALUES(?,?)"); |
||||||
|
for(Iterator i=tag_ids.iterator();i.hasNext();){ |
||||||
|
ps1.setInt(1, item_id); |
||||||
|
ps1.setInt(2, Integer.parseInt((String)i.next())); |
||||||
|
ps1.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
ps1.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove tag ids by item id |
||||||
|
* @param item_id item id |
||||||
|
* @param tag_id tag id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void removeTagIds4Item(int item_id, int tag_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM "+getTagItemTable()+" WHERE "+getTagItemId()+"=? and tag_id=?"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ps.setInt(2, tag_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update tag item by tag id |
||||||
|
* @param item_id item id |
||||||
|
* @param tagids tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void updateItemTagIds(int item_id, List<Integer> tagids) throws Exception { |
||||||
|
|
||||||
|
String query="DELETE FROM "+getTagItemTable()+" WHERE id IN (select * from (select a.id from "+getTagItemTable()+" as a left outer join "+getTagTable()+" as b on a.tag_id = b.id where "+getTagItemId()+"=? and left(b.tagname,3)<>'usr') temp_table ) "; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
|
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("INSERT INTO "+getTagItemTable()+"("+getTagItemId()+",tag_id) VALUES(?,?)"); |
||||||
|
for(Integer i:tagids){ |
||||||
|
ps1.setInt(1, item_id); |
||||||
|
ps1.setInt(2, i); |
||||||
|
ps1.executeUpdate(); |
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update follower tag id |
||||||
|
* @param item_id item id |
||||||
|
* @param tagids tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void updateFollwerTagIds(int item_id, List<Integer> tagids) throws Exception { |
||||||
|
|
||||||
|
String query="DELETE FROM "+getTagItemFollowTable()+" WHERE id IN (select * from (select a.id from "+getTagItemFollowTable()+" as a left outer join "+getTagTable()+" as b on a.tag_id = b.id where "+getTagItemId()+"=? and left(b.tagname,3)<>'usr') temp_table ) "; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
|
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("INSERT INTO "+getTagItemFollowTable()+"("+getTagItemId()+",tag_id) VALUES(?,?)"); |
||||||
|
for(Integer i:tagids){ |
||||||
|
ps1.setInt(1, item_id); |
||||||
|
ps1.setInt(2, i); |
||||||
|
ps1.executeUpdate(); |
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get theme tags |
||||||
|
* @param item_id item id |
||||||
|
* @return theme tags |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public List getThemeTags(int item_id) throws Exception { |
||||||
|
|
||||||
|
String q="select replace(b.tagname,'thm-','') as theme FROM "+getTagItemTable()+" as a "; |
||||||
|
q+="left outer join "+getTagTable()+" as b on a.tag_id=b.id "; |
||||||
|
q+="where a."+getTagItemId()+"=? "; |
||||||
|
q+="and left(b.tagname,4)='thm-' "; |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement(q); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getString("theme")); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get theme tag name |
||||||
|
* @param tag_id tag id |
||||||
|
* @return theme tag name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public String getThemeTagName(int tag_id) throws Exception { |
||||||
|
|
||||||
|
String q="select replace(a.tagname,'thm-','') as theme FROM "+getTagTable()+" as a where id=?"; |
||||||
|
|
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement(q); |
||||||
|
ps.setInt(1, tag_id); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
String rtn=null; |
||||||
|
if(rs.next()){ |
||||||
|
rtn= rs.getString("theme"); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get theme names by item id |
||||||
|
* @param item_id item id |
||||||
|
* @return theme names |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public ArrayList getThemeNames4Item(int item_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select b.tagname FROM "+getTagItemTable()+" as a left outer join "+getTagTable()+" as b on a.tag_id=b.id WHERE a."+getTagItemId()+"=? and left(b.tagname,4)<>'usr-'"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
while(rs.next()){ |
||||||
|
String tagname=rs.getString("tagname"); |
||||||
|
tagname=tagname.replaceAll("thm-", ""); |
||||||
|
rtn.add(tagname); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get followers tag by item id |
||||||
|
* @param item_id item id |
||||||
|
* @return followers tag |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public ArrayList getFollowTags4Item(int item_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select b.tagname FROM "+getTagItemFollowTable()+" as a left outer join "+getTagTable()+" as b on a.tag_id=b.id WHERE a."+getTagItemId()+"=? and left(b.tagname,4)<>'usr-'"); |
||||||
|
ps.setInt(1, item_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
while(rs.next()){ |
||||||
|
String tagname=rs.getString("tagname"); |
||||||
|
tagname=tagname.replaceAll("thm-", ""); |
||||||
|
rtn.add(tagname); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get SVN user for Wiki user |
||||||
|
* @param w_user wiki user |
||||||
|
* @return svn user |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public Map getSVNUser4WikiUser(String w_user) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps5=this.connection().prepareStatement("SELECT * FROM users where svn_username=?"); |
||||||
|
|
||||||
|
ps5.setString(1, w_user); |
||||||
|
ResultSet rs5= ps5.executeQuery(); |
||||||
|
Map rtn=new HashMap(); |
||||||
|
if(rs5.next()){ |
||||||
|
rtn=new BasicRowProcessor().toMap(rs5); |
||||||
|
} |
||||||
|
//added by rams on 5-june-2012
|
||||||
|
rs5.close(); |
||||||
|
ps5.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,227 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.Date; |
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.vo.BBSyncTrigger; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to BBSync |
||||||
|
*/ |
||||||
|
public abstract class BBSyncDB extends SuperDB{ |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_BBSYNC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* List all bbsync |
||||||
|
* @return bbsync |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector listAll() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field mapping by bbsync id |
||||||
|
* @param bbsyncid bbsync id |
||||||
|
* @return field mapping |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract ArrayList fieldMapping4BBSync(int bbsyncid) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get download query |
||||||
|
* @param id bbsync id |
||||||
|
* @return bbsync |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getDownloadQuery(long id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field mapping |
||||||
|
* @return field mapping |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getFieldMapping() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update triggered date |
||||||
|
* @param id bbsync id |
||||||
|
* @param start trigger start date |
||||||
|
* @param end trigger end date |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateTriggeredDate(int id, Timestamp start, |
||||||
|
Timestamp end) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete field mapping |
||||||
|
* @param id field mapping id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteFieldMapping(int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add field mapping |
||||||
|
* @param dbfield field mapping db field |
||||||
|
* @param bbfield field mapping bb field |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addFieldMapping(String dbfield, String bbfield) |
||||||
|
throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update contract logs |
||||||
|
* @param contract contracts |
||||||
|
* @param marketsector market sector |
||||||
|
* @param lastsync last sync |
||||||
|
* @param scommodities scommodities |
||||||
|
* @param fields contract fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateContractLogs(Vector<String> contract,String marketsector, |
||||||
|
Timestamp lastsync, Map<String, String> scommodities,Collection fields) |
||||||
|
throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update securities logs |
||||||
|
* @param contract contracts |
||||||
|
* @param marketsector market sector |
||||||
|
* @param lastsync last sync |
||||||
|
* @param fields contract fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateSecuritiesLogs(Vector<String> contract, |
||||||
|
String marketsector, Timestamp lastsync,Collection fields) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract names to ref synchronized |
||||||
|
* @param pendingonly is pending only |
||||||
|
* @throws Exception |
||||||
|
* @return contract info |
||||||
|
*/ |
||||||
|
public abstract Vector<String> getContractNames2RefSync(boolean pendingonly) |
||||||
|
throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get security names to ref synchronized |
||||||
|
* @param pendingonly is pending only |
||||||
|
* @throws Exception |
||||||
|
* @return security info |
||||||
|
*/ |
||||||
|
public abstract Map<String, String> getSecurityNames2RefSync( |
||||||
|
boolean pendingonly) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get security name to ref synchronized |
||||||
|
* @param ticker ticker |
||||||
|
* @throws Exception |
||||||
|
* @return security info |
||||||
|
*/ |
||||||
|
public abstract Map<String,String> getSecurityName2RefSync(String ticker) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update contract reference |
||||||
|
* @param contractname contract name |
||||||
|
* @param fielddata field data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateContractReference(String contractname, |
||||||
|
Map<String, String> fielddata) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update security reference |
||||||
|
* @param securityname security name |
||||||
|
* @param marketsector market sector |
||||||
|
* @param fielddata field data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateSecurityReference(String securityname, |
||||||
|
String marketsector, Map<String, String> fielddata) |
||||||
|
throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add sync logs |
||||||
|
* @param bbsyncid bbsync id |
||||||
|
* @param start start time |
||||||
|
* @param end end time |
||||||
|
* @param message message |
||||||
|
* @param status status |
||||||
|
* @param manual_scheduler manual scheduler |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addSyncLogs(int bbsyncid, Timestamp start, |
||||||
|
Timestamp end, String message, String status, |
||||||
|
String manual_scheduler) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove schedule ticker |
||||||
|
* @param bbsync_id bbsync id |
||||||
|
* @param ticker contract |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeScheduleTicker(int bbsync_id, String ticker) |
||||||
|
throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Save schedule |
||||||
|
* @param id bbsync id |
||||||
|
* @param name bbsync name |
||||||
|
* @param mkt_secdb is market security db |
||||||
|
* @param dateoption date option |
||||||
|
* @param datefrom date from |
||||||
|
* @param dateto date to |
||||||
|
* @param datenumber date recent number |
||||||
|
* @param fields bbsync fields |
||||||
|
* @param contracts bbsync contracts |
||||||
|
* @param t BBSync trigger |
||||||
|
* @param marketsector market sector |
||||||
|
* @param timezone timezone |
||||||
|
* @return bbsync id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int saveSchedule(int id, String name, String mkt_secdb, |
||||||
|
String dateoption, Date datefrom, Date dateto, int datenumber, |
||||||
|
Vector fields, String contracts, BBSyncTrigger t, |
||||||
|
String marketsector, String timezone) throws Exception; |
||||||
|
|
||||||
|
public abstract void deleteQuery(int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Record started peer |
||||||
|
* @param peername peer name |
||||||
|
* @param sessionid session id |
||||||
|
* @param time time |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void peerStarted(String peername,long sessionid, java.util.Date time) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Record stopped peer |
||||||
|
* @param peername peer name |
||||||
|
* @param sessionid session id |
||||||
|
* @param time time |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void peerStopped(String peername, long sessionid, java.util.Date time) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,147 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.util.MissingResourceException; |
||||||
|
import java.util.Properties; |
||||||
|
import java.util.ResourceBundle; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* This class populates the configuration value from property file |
||||||
|
*/ |
||||||
|
class Config { |
||||||
|
|
||||||
|
/** |
||||||
|
* Configuration file |
||||||
|
*/ |
||||||
|
private static final String BUNDLE_NAME = "config_db"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/** |
||||||
|
* windows peer configuration |
||||||
|
*/ |
||||||
|
private static final String PROPERTY_FILE_WIN = "peer_db_windows.properties"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/** |
||||||
|
* unix peer/server configuration file |
||||||
|
*/ |
||||||
|
private static final String PROPERTY_FILE_UNIX = "peer_db_unix.properties"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static String CONFIG_PROPERTY_LOCATION=null; |
||||||
|
|
||||||
|
private static Properties confpro=null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Private constructor |
||||||
|
*/ |
||||||
|
private Config() { |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get property value of specified key. Return '!key!' if not found. |
||||||
|
* @param key key |
||||||
|
* @return property value |
||||||
|
*/ |
||||||
|
protected static String getString(String key) { |
||||||
|
if(CONFIG_PROPERTY_LOCATION==null){ |
||||||
|
try { |
||||||
|
//return RESOURCE_BUNDLE.getString(key);
|
||||||
|
return getResourceBuddle().getString(key); |
||||||
|
} catch (MissingResourceException e) { |
||||||
|
return '!' + key + '!'; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
try { |
||||||
|
String ky= getPeerProperty(key); |
||||||
|
if(ky==null) throw new Exception(); |
||||||
|
else return ky; |
||||||
|
} catch (Exception e) { |
||||||
|
return '!' + key + '!'; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static ResourceBundle resourceBundle=null; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get resources bundle |
||||||
|
* @return resources bundle |
||||||
|
*/ |
||||||
|
private synchronized static ResourceBundle getResourceBuddle(){ |
||||||
|
|
||||||
|
if(resourceBundle==null){ |
||||||
|
resourceBundle=ResourceBundle.getBundle(BUNDLE_NAME); |
||||||
|
LogManager.getLogger(Config.class.getName()).info("resourceBundle:"+resourceBundle); |
||||||
|
} |
||||||
|
|
||||||
|
return resourceBundle; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get property value of specified key. Return null if not found. |
||||||
|
* @param key key |
||||||
|
* @return property value |
||||||
|
*/ |
||||||
|
protected static String getValue(String key) { |
||||||
|
if(CONFIG_PROPERTY_LOCATION==null){ |
||||||
|
try { |
||||||
|
|
||||||
|
return getResourceBuddle().getString(key); |
||||||
|
} catch (MissingResourceException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
try { |
||||||
|
return getPeerProperty(key); |
||||||
|
} catch (Exception e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get peer property by key |
||||||
|
* @param key key |
||||||
|
* @return peer property |
||||||
|
*/ |
||||||
|
private static String getPeerProperty(String key) throws Exception { |
||||||
|
try{ |
||||||
|
if(confpro==null){ |
||||||
|
String propertyfilename=PROPERTY_FILE_WIN; |
||||||
|
if(System.getProperty("os.name").toLowerCase().equals("freebsd")) |
||||||
|
propertyfilename=PROPERTY_FILE_UNIX; |
||||||
|
|
||||||
|
if(System.getProperty("os.name").toLowerCase().contains("linux")) |
||||||
|
propertyfilename=PROPERTY_FILE_UNIX; |
||||||
|
|
||||||
|
String folder=CONFIG_PROPERTY_LOCATION; |
||||||
|
folder=folder.endsWith(File.separator)?folder:folder+File.separator; |
||||||
|
confpro=new Properties(); |
||||||
|
String filename=folder+"conf"+File.separator+propertyfilename; |
||||||
|
confpro.load(new FileInputStream(filename)); |
||||||
|
} |
||||||
|
return confpro.getProperty(key); |
||||||
|
}catch(Exception e){ |
||||||
|
e.printStackTrace(); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,48 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class to construct query |
||||||
|
*/ |
||||||
|
public abstract class ConstructQueryDB extends SuperDB{ |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_BBSYNC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct date input query |
||||||
|
* @param rtnobj return object |
||||||
|
* @return query |
||||||
|
*/ |
||||||
|
public abstract String constructDateInputQuery(Map rtnobj); |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct recent query |
||||||
|
* @param field table field |
||||||
|
* @param dateQuery date query |
||||||
|
* @return query |
||||||
|
*/ |
||||||
|
public abstract String constructRecentQuery(String field, String dateQuery); |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct queue history query |
||||||
|
* @param rtnobj return object |
||||||
|
* @return query |
||||||
|
*/ |
||||||
|
public abstract String constructQueueHistoryQuery(Map rtnobj); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,130 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to Contract |
||||||
|
*/ |
||||||
|
public abstract class ContractDB extends SuperDB{ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Update records |
||||||
|
* @param con connection |
||||||
|
* @param records records |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateRecords(Connection con,Vector records) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add records |
||||||
|
* @param con connection |
||||||
|
* @param records records |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addRecords(Connection con,Vector records) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create table |
||||||
|
* @param con connection |
||||||
|
* @param decimalpoint decimal point |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void createTable(Connection con, int decimalpoint) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update sval records |
||||||
|
* @param con connection |
||||||
|
* @param records records |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateSValRecords(Connection con,Vector records) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add sval records |
||||||
|
* @param con connection |
||||||
|
* @param records records |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addSValRecords(Connection con,Vector records) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create sval table |
||||||
|
* @param con connection |
||||||
|
* @param decimalpoint decimal point |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void createSValTable(Connection con, int decimalpoint) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Check s value field |
||||||
|
* @param con connection |
||||||
|
* @return record count |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int checkSValueField(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Count records |
||||||
|
* @param con connection |
||||||
|
* @return record count |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int countRecords(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether s value field type exist |
||||||
|
* @param con connection |
||||||
|
* @return true if record exist |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean checkSValueFieldTypeExist(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract titles by connection |
||||||
|
* @param con connection |
||||||
|
* @return contract titles |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getContractTitles(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract titles by connection & date query |
||||||
|
* @param con connection |
||||||
|
* @param datequery date query |
||||||
|
* @return contract titles |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getContractTitles(Connection con, String datequery) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update master table |
||||||
|
* @param con connection |
||||||
|
* @param mtable master table |
||||||
|
* @param fieldname field name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateMasterTable(Connection con,String mtable,String fieldname) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Generate SQL XL Query Plain query |
||||||
|
* @param fieldtable field table |
||||||
|
* @param nmonths n months |
||||||
|
* @param contractTitleList contract title list |
||||||
|
* @return contract date |
||||||
|
*/ |
||||||
|
public abstract String generateSQLXLQueryPlainQuery(String fieldtable, int nmonths, List contractTitleList); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,273 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* The DBManager class provides an Access Interface between the Trading Database and Java. |
||||||
|
* It can be used to get data from the database, insert new data and update existing data. |
||||||
|
* The config file containing the details for the database hostname and credentials is located in the resources folder. |
||||||
|
* @author Manas Maral Misra, Antonius Ari Wicaksono |
||||||
|
* |
||||||
|
*/ |
||||||
|
public class DBManager { |
||||||
|
/** |
||||||
|
* The database name for the current instance of DBManager |
||||||
|
*/ |
||||||
|
private String dbName; |
||||||
|
/** |
||||||
|
* The connection string for the database connection. Stored in config.lib-dal |
||||||
|
*/ |
||||||
|
private String connectionString; |
||||||
|
/** |
||||||
|
* The resultSet which contains the returned results from the SQL Query of GetDatabase |
||||||
|
*/ |
||||||
|
ResultSet resultSet = null; |
||||||
|
/** |
||||||
|
* The connection object of the current connection. |
||||||
|
*/ |
||||||
|
private Connection conn = null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Initialize the DBManager with the database name. |
||||||
|
* @param dbName The name of the database e.x. trading, tradingRef, fundamentals |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public DBManager(String dbName) throws IOException |
||||||
|
{ |
||||||
|
this.dbName = dbName; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This function connects to the dbName database; |
||||||
|
* @throws SQLException This is thrown incase we are not able to connect to the database; |
||||||
|
* @throws ClassNotFoundException This is thrown incase the driver is not found on this machine |
||||||
|
* @throws IOException This is thrown incase the config.lib-dal if not found on this machine under resources folder |
||||||
|
*/ |
||||||
|
public void connect() throws SQLException, ClassNotFoundException, IOException |
||||||
|
{ |
||||||
|
String connString = Utils.getConfig4E(".CONFIG4E_JDBC_CONNECTIONSTRING_" + dbName.toUpperCase()); |
||||||
|
|
||||||
|
String driver = "com.mysql.jdbc.Driver"; |
||||||
|
|
||||||
|
// if connString contains 'sqlserver'. i.e. 'jdbc:sqlserver://10.153.64.3:1433;databaseName=infrastructure;integratedSecurity=false;user=dbuser;password=dbuser'
|
||||||
|
if (connString.contains("sqlserver")) { |
||||||
|
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; |
||||||
|
} |
||||||
|
|
||||||
|
Class.forName(driver); |
||||||
|
conn = DriverManager.getConnection(connString); |
||||||
|
connectionString = conn.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This function returns the result set of the SQL Query used by GetDatabase; |
||||||
|
* @param query The SQL Query passed to it. |
||||||
|
* @return |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
protected ResultSet executeQuery(String query) throws SQLException |
||||||
|
{ |
||||||
|
Date start = new Date(); |
||||||
|
Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); |
||||||
|
resultSet = statement.executeQuery(query); |
||||||
|
Date end = new Date(); |
||||||
|
long duration = (end.getTime() - start.getTime()); |
||||||
|
//Utils.Log("DEBUG: Query ("+query+") took "+duration+ " miliseconds");
|
||||||
|
return resultSet; |
||||||
|
} |
||||||
|
/** |
||||||
|
* This function returns the result set of the SQL Query used by GetDatabase; |
||||||
|
* @param query The SQL Query passed to it. |
||||||
|
* @return |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
protected void executeNonQuery(String query) throws SQLException |
||||||
|
{ |
||||||
|
Date start = new Date(); |
||||||
|
Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); |
||||||
|
statement.execute(query); |
||||||
|
Date end = new Date(); |
||||||
|
long duration = (end.getTime() - start.getTime()); |
||||||
|
//Utils.Log("DEBUG: Query ("+query+") took "+duration+ " miliseconds");
|
||||||
|
|
||||||
|
} |
||||||
|
/** |
||||||
|
* This function executes the Update query from UpdateDatabase |
||||||
|
* @param query |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
private void updateQuery(String query) throws SQLException |
||||||
|
{ |
||||||
|
Date start = new Date(); |
||||||
|
Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); |
||||||
|
statement.executeUpdate(query); |
||||||
|
Date end = new Date(); |
||||||
|
long duration = (end.getTime() - start.getTime()); |
||||||
|
System.out.println("DEBUG: Query took "+duration+ " miliseconds"); |
||||||
|
} |
||||||
|
/** |
||||||
|
* Closes the current Database connection. |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public void closeConnection() |
||||||
|
{ |
||||||
|
try { |
||||||
|
if(!conn.isClosed()) |
||||||
|
conn.close(); |
||||||
|
if(resultSet!=null) |
||||||
|
resultSet.close(); |
||||||
|
} catch (SQLException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to query a database and access the resultant data in a ResultSet |
||||||
|
* @param tableName The name of the database table to be accessed |
||||||
|
* @param selectedFields A list of the values to be selected through the queries. <code>new ArrayList<String>();</code> |
||||||
|
* be passed to select all fields (*) |
||||||
|
* @param queryParams A hashmap containing the selection filters in the format <code>[column_name]=[value]</code> |
||||||
|
* @param customQuery Any additional parameters to be added after the Where clause. Could be a GROUP BY or ORDER BY |
||||||
|
* @return The resulting data in a ResultSet |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public ResultSet getDatabase(String tableName,ArrayList<String> selectedFields, Map<String,Object> queryParams, String customQuery) throws SQLException |
||||||
|
{ |
||||||
|
String queryBuilder = ""; |
||||||
|
if(selectedFields.size()==0) |
||||||
|
{ |
||||||
|
selectedFields.add("*"); |
||||||
|
} |
||||||
|
|
||||||
|
queryBuilder += "SELECT "+Utils.Join(selectedFields,",")+" FROM "+tableName; |
||||||
|
|
||||||
|
if(queryParams != null && queryParams.size()>0) |
||||||
|
{ |
||||||
|
queryBuilder += " WHERE "; |
||||||
|
for (Map.Entry<String,Object> entry : queryParams.entrySet()) { |
||||||
|
|
||||||
|
try{ |
||||||
|
Float f = Float.parseFloat(entry.getValue().toString()); |
||||||
|
queryBuilder += " "+entry.getKey() + " = "+entry.getValue()+" AND"; |
||||||
|
} |
||||||
|
catch(Exception ex) |
||||||
|
{ |
||||||
|
queryBuilder += " "+entry.getKey() + " = '"+entry.getValue()+"' AND"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
if(customQuery!= null && customQuery!="") |
||||||
|
queryBuilder += customQuery+" AND"; |
||||||
|
queryBuilder = queryBuilder.substring(0,queryBuilder.length()-3); |
||||||
|
} |
||||||
|
//System.out.println(queryBuilder);
|
||||||
|
return executeQuery(queryBuilder); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to update a single cell in a table in the database. |
||||||
|
* @param tableName The name of the database table to be accessed |
||||||
|
* @param selectedFields |
||||||
|
* @param queryParams A hashmap containing the selection filters in the format <code>[column_name]=[value]</code> |
||||||
|
* @param selectionFieldValues A list of the values to be selected through the queries. <code>new ArrayList<String>();</code> |
||||||
|
* be passed to select all fields (*) |
||||||
|
* @param newFieldsValues |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public void updateDatabase(String tableName,Map<String,Object> selectionFieldValues, Map<String,Object> newFieldsValues) throws SQLException |
||||||
|
{ |
||||||
|
String queryBuilder = "UPDATE "+tableName+" SET "; |
||||||
|
|
||||||
|
if(newFieldsValues.size()>0) |
||||||
|
{ |
||||||
|
ArrayList<String> al = new ArrayList<String>(); |
||||||
|
for (Map.Entry<String,Object> entry : newFieldsValues.entrySet()) { |
||||||
|
try{ |
||||||
|
Float f = Float.parseFloat(entry.getValue().toString()); |
||||||
|
al.add(entry.getKey()+" = "+entry.getValue()); |
||||||
|
} |
||||||
|
catch(Exception ex) |
||||||
|
{ |
||||||
|
al.add(entry.getKey()+" = '"+entry.getValue()+"'"); |
||||||
|
} |
||||||
|
} |
||||||
|
queryBuilder += Utils.Join(al, ","); |
||||||
|
} |
||||||
|
|
||||||
|
if(selectionFieldValues.size()>0) |
||||||
|
{ |
||||||
|
queryBuilder += " WHERE "; |
||||||
|
for (Map.Entry<String,Object> entry : selectionFieldValues.entrySet()) { |
||||||
|
|
||||||
|
try{ |
||||||
|
Float f = Float.parseFloat(entry.getValue().toString()); |
||||||
|
queryBuilder += " "+entry.getKey() + " = "+entry.getValue()+" AND"; |
||||||
|
} |
||||||
|
catch(Exception ex) |
||||||
|
{ |
||||||
|
queryBuilder += " "+entry.getKey() + " = '"+entry.getValue()+"' AND"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
queryBuilder = queryBuilder.substring(0,queryBuilder.length()-3); |
||||||
|
} |
||||||
|
//Utils.Log(queryBuilder);
|
||||||
|
updateQuery(queryBuilder); |
||||||
|
} |
||||||
|
/** |
||||||
|
* Used to insert a new row in a table in the database. |
||||||
|
* @param tableName The name of the table where the row has to be inserted |
||||||
|
* @param fieldValues the hashmap of column names and values |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public void insertDatabase(String tableName,Map<String,Object> fieldValues,Map<String,Object> nonStringfieldValues) throws SQLException |
||||||
|
{ |
||||||
|
String queryBuilder = "INSERT INTO "+tableName; |
||||||
|
if(nonStringfieldValues==null) nonStringfieldValues = new HashMap<String, Object>(); |
||||||
|
if(fieldValues.size()>0) |
||||||
|
{ |
||||||
|
queryBuilder += " ("+Utils.Join(new ArrayList<String>(fieldValues.keySet()), ","); |
||||||
|
if(!nonStringfieldValues.isEmpty()) |
||||||
|
queryBuilder +=","+Utils.Join(new ArrayList<String>(nonStringfieldValues.keySet()), ","); |
||||||
|
queryBuilder+= " ) VALUES "; |
||||||
|
ArrayList<String> ll = new ArrayList<String>(); |
||||||
|
for (Iterator i = fieldValues.values().iterator(); i.hasNext();) { |
||||||
|
ll.add(i.next().toString()); |
||||||
|
|
||||||
|
} |
||||||
|
ArrayList<String> ll2 = new ArrayList<String>(); |
||||||
|
for (Iterator i = nonStringfieldValues.values().iterator(); i.hasNext();) { |
||||||
|
ll2.add(i.next().toString()); |
||||||
|
|
||||||
|
} |
||||||
|
queryBuilder += " ('"+Utils.Join(ll, "','")+"'"; |
||||||
|
if(!ll2.isEmpty()) |
||||||
|
queryBuilder += ","+Utils.Join(ll2, ","); |
||||||
|
queryBuilder += ") "; |
||||||
|
} |
||||||
|
//Utils.Log(queryBuilder);
|
||||||
|
|
||||||
|
executeNonQuery(queryBuilder); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to database manager |
||||||
|
*/ |
||||||
|
public abstract class DBManagerDB extends SuperDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_BBSYNC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* List database groups |
||||||
|
* @return database groups |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listDBGroups() throws Exception; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,99 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.vo.FlexiField; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to Flexi Field |
||||||
|
*/ |
||||||
|
public abstract class FlexiFieldDB extends SuperDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_BBSYNC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get flexi fields |
||||||
|
* @param tablename tablename string |
||||||
|
* @return flexi fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getFlexiFields(String tablename) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add flexi field |
||||||
|
* @param ffield flexi field |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addFlexiField(FlexiField ffield) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update flexi field |
||||||
|
* @param id flexi field id |
||||||
|
* @param ffield flexi field |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFlexiField(long id,FlexiField ffield) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete flexi field |
||||||
|
* @param id flexi field id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteFlexiField(long id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get flexi field data |
||||||
|
* @param tablename table name |
||||||
|
* @param idfield id field |
||||||
|
* @param idvalue id |
||||||
|
* @return flexi field data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getFlexiFieldData (String tablename, String idfield, String idvalue) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get flexi field data for lucene token |
||||||
|
* @param tablename table name |
||||||
|
* @param idfield id field |
||||||
|
* @param idvalue id |
||||||
|
* @return flexi field data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector<Map> getFlexiFieldData4LuceneToken (String tablename, String idfield, String idvalue) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Save flexi field data |
||||||
|
* @param tablename table name |
||||||
|
* @param idfield id field |
||||||
|
* @param idvalue id |
||||||
|
* @param data data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void saveFlexiFieldData (String tablename, String idfield, String idvalue, Map data) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Update flexi field order |
||||||
|
* @param id flexi field id |
||||||
|
* @param order display order |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFlexiFieldOrder(long id,int order) throws Exception ; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,77 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.ResultSetMetaData; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.StringTokenizer; |
||||||
|
|
||||||
|
/** |
||||||
|
* General utility class for database |
||||||
|
*/ |
||||||
|
public class GeneralUtilDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert resultset to map |
||||||
|
* @param rs ResultSet |
||||||
|
* @return map |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static Map<String, Object> resultsetToMap(ResultSet rs) throws Exception { |
||||||
|
ResultSetMetaData metaData = rs.getMetaData(); |
||||||
|
int colCount = metaData.getColumnCount(); |
||||||
|
Map<String, Object> row = new HashMap<String, Object>(); |
||||||
|
for (int i = 1; i <= colCount; i++) { |
||||||
|
row.put(metaData.getColumnLabel(i), rs.getObject(i)); |
||||||
|
} |
||||||
|
return row; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Convert query from MS-SQL |
||||||
|
* @param sqlquery sql query |
||||||
|
* @return query |
||||||
|
*/ |
||||||
|
public static String convertFromSQL(String sqlquery){ |
||||||
|
|
||||||
|
String rtn=sqlquery; |
||||||
|
if(sqlquery.toUpperCase().contains("BETWEEN") && sqlquery.toUpperCase().contains("GETDATE()") ){ |
||||||
|
|
||||||
|
rtn=sqlquery.replace("GETDATE()", "SYSDATE()"); |
||||||
|
|
||||||
|
}else if(sqlquery.toUpperCase().contains("DATEADD")) { |
||||||
|
|
||||||
|
StringTokenizer st=new StringTokenizer(sqlquery,","); |
||||||
|
if(st.countTokens()>=3){ |
||||||
|
String p1=st.nextToken(); |
||||||
|
String p2=st.nextToken(); |
||||||
|
String p3=st.nextToken(); |
||||||
|
p3=p3.replace(")", ""); |
||||||
|
if(p3.trim().equalsIgnoreCase("current_timestamp")){ |
||||||
|
p3="SYSDATE()"; |
||||||
|
} |
||||||
|
StringTokenizer st1=new StringTokenizer(p1,"("); |
||||||
|
if(st1.countTokens()>=2){ |
||||||
|
String p2a=st1.nextToken(); |
||||||
|
String p2b=st1.nextToken(); |
||||||
|
p2a=p2a.replace("DATEADD", "DATE_ADD"); |
||||||
|
rtn=p2a+"("+p3+", INTERVAL "+p2+" "+p2b+")"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,223 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to IExec |
||||||
|
*/ |
||||||
|
public abstract class IExecDB extends SuperDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_IEXEC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* List groups |
||||||
|
* @return groups |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listGroups() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Set group order |
||||||
|
* @param groupids group id list |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void setGroupOrder( Vector groupids) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List folders |
||||||
|
* @return ie folder list |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listFolders( ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List strategies |
||||||
|
* @return strategies |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listStrategies() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get strategy |
||||||
|
* @param strategy_id strategy id |
||||||
|
* @return strategy |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getStrategy(int strategy_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether it is parent |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @return true if it is parent strategy |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean isParent(String strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get strategies by names |
||||||
|
* @param strategy_names strategy names |
||||||
|
* @return strategies |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getStrategies(Vector strategy_names) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get folder name |
||||||
|
* @param folder_id folder id |
||||||
|
* @return folder name list |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract String getFolderName(int folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get unique contracts |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @return contracts |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getUniqueContracts(String strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add parameters |
||||||
|
* @param data parameter data |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addParameters(ArrayList<Map> data,String strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get parameter values |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @param contract contract |
||||||
|
* @return parameter values |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getParameterValues(String strategy_name, String contract) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove contract |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @param contract contract |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeContract(String strategy_name, String contract) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get strategy by name |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @return strategy |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getStrategy(String strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create strategy |
||||||
|
* @param folder_id folder id |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @param path file name path |
||||||
|
* @return strategy id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int createStrategy(int folder_id,String strategy_name, String path) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create child strategy |
||||||
|
* @param parent_name parent name |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @return strategy id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int createChildStrategy(String parent_name,String strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get folder id |
||||||
|
* @param folder_name folder name |
||||||
|
* @return folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int getFolderID(String folder_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create folder |
||||||
|
* @param folder folder name |
||||||
|
* @param new_group_id new group id |
||||||
|
* @return folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int createFolder(String folder, String new_group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List of folders |
||||||
|
* @param group_id group id |
||||||
|
* @return folders |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listOfFolders(String group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update strategy folder |
||||||
|
* @param strategy_id strategy id |
||||||
|
* @param new_folder_id new folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateStrategyFolder(int strategy_id,int new_folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Move folder |
||||||
|
* @param folder_id folder id |
||||||
|
* @param new_group_id new group id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void moveFolder(int folder_id, String new_group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename strategy |
||||||
|
* @param strategy_id strategy id |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @param file_name file name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void renameStrategy(int strategy_id, String strategy_name, String file_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename parent strategy |
||||||
|
* @param strategy_id strategy id |
||||||
|
* @param strategy_name strategy name |
||||||
|
* @param file_name file name |
||||||
|
* @param old_strategy_name old strategy name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void renameParentStrategy(int strategy_id, String strategy_name, String file_name, String old_strategy_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract tree |
||||||
|
* @return contract tree |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getContractTree() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get commodity tree |
||||||
|
* @return commodity tree |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector<String> getCommodityTree() throws Exception; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,73 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to Infrastructure |
||||||
|
*/ |
||||||
|
public abstract class InfrastructureDB extends SuperDB { |
||||||
|
|
||||||
|
public static final String APPLICATION_IEXEC = "iExec"; |
||||||
|
public static final String APPLICATION_SCHEDULER_PEER_ASSOCIATION = "Scheduler.PeerAssociation"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_INFRASTRUCTURE); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get themes by user |
||||||
|
* @param user user |
||||||
|
* @return themes |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getThemes4Users(String user) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get team organization |
||||||
|
* @param themes themes |
||||||
|
* @param hierarchy hierarchy |
||||||
|
* @return team organization |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getTeamOrg(String themes, List hierarchy) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update Bloomberg daily counter |
||||||
|
* @param date date |
||||||
|
* @param count BBG daily counter |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateBloomberDailyCounter(String date, int count) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* get themes by username access 'X','B','C' |
||||||
|
* @param username username |
||||||
|
* @return themes |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<String> getThemeByUsernameAccess(String username) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get access by app and username |
||||||
|
* @param application application |
||||||
|
* @param username username |
||||||
|
* @return application user access |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getAccessByAppAndUsername(String application, String username) throws Exception; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,446 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.vo.PeerPackage; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to R Function |
||||||
|
*/ |
||||||
|
public abstract class RFunctionDB extends AbstractTeamOrgDB { |
||||||
|
|
||||||
|
public static final int FUNCTION_TYPE_NORMAL=0; |
||||||
|
public static final int FUNCTION_TYPE_CLASS=1; |
||||||
|
public static final int FUNCTION_TYPE_METHOD=2; |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_R_FUNCTION); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag table |
||||||
|
* @return "tags " |
||||||
|
*/ |
||||||
|
public String getTagTable() { return "tags "; } |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item table |
||||||
|
* @return "function_tags" |
||||||
|
*/ |
||||||
|
public String getTagItemTable() { return "function_tags"; } |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item id |
||||||
|
* @return "function_id" |
||||||
|
*/ |
||||||
|
public String getTagItemId() { return "function_id";} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag item follow table |
||||||
|
* @return "function_followtags" |
||||||
|
*/ |
||||||
|
public String getTagItemFollowTable() { return "function_followtags";} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get R function |
||||||
|
* @param function_id function id |
||||||
|
* @return r function |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getRFunction(int function_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get R functions by names |
||||||
|
* @param functionnames function names |
||||||
|
* @return r functions |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getRFunctions(Vector functionnames) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get R functions by name |
||||||
|
* @param function_name function name |
||||||
|
* @return r function |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getRFunction(String function_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get folder name |
||||||
|
* @param folder_id folder id |
||||||
|
* @return folder name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract String getFolderName(int folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List R functions |
||||||
|
* @return R functions |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listRFunctions() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update function order |
||||||
|
* @param function_ids function ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFunctionOrder(int[] function_ids ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update folder order |
||||||
|
* @param folder_ids folder ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFolderOrder(int[] folder_ids ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all R functions names |
||||||
|
* @return R functions names |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listAllRFunctionNames() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all R script names |
||||||
|
* @param folder_id folder id |
||||||
|
* @return R script names |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listAllRScriptNames(int folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List of functions by folder id |
||||||
|
* @param folder_id folder id |
||||||
|
* @return r functions |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<Map> listOfFunctions(int folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List function groups |
||||||
|
* @return function groups |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listFunctionGroups() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List of folders |
||||||
|
* @return folders |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listOfFolders( ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List of folders by group id |
||||||
|
* @param group_id group id |
||||||
|
* @return folders |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listOfFolders(String group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get folder id by name |
||||||
|
* @param folder_name folder name |
||||||
|
* @return folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int getFolderID(String folder_name) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create R function |
||||||
|
* @param folder_id folder id |
||||||
|
* @param functionname function name |
||||||
|
* @param path script file path |
||||||
|
* @param func_type function type |
||||||
|
* @return r function id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int createFunction(int folder_id,String functionname, String path,int func_type) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Move folder |
||||||
|
* @param folder_id folder id |
||||||
|
* @param new_group_id new group id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void moveFolder(int folder_id, String new_group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update R function folder |
||||||
|
* @param function_id function id |
||||||
|
* @param new_folder_id new folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFunctionFolder(int function_id,int new_folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename folder |
||||||
|
* @param folder_id folder id |
||||||
|
* @param foldername folder name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void renameFolder(int folder_id,String foldername) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update last 2 users tag |
||||||
|
* @param function_id function id |
||||||
|
* @param user_tagid user tag id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateLast2UsersTag(int function_id, int user_tagid) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get all tags |
||||||
|
* @return tags |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getTags() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag id by function id |
||||||
|
* @param function_id function id |
||||||
|
* @return tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getTagIds4Function(int function_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add if tag not exist |
||||||
|
* @param tagname tag name |
||||||
|
* @return tag id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int addIfTagNotExist(String tagname) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add tag ids for function |
||||||
|
* @param function_id function id |
||||||
|
* @param tag_id tag id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addTagIds4Function(int function_id, int tag_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove tag ids for function |
||||||
|
* @param function_id function id |
||||||
|
* @param tag_id tag id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeTagIds4Function(int function_id, int tag_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update lock |
||||||
|
* @param function_id function id |
||||||
|
* @param lockedby locked by |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateLock(int function_id,String lockedby) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Set group order |
||||||
|
* @param groupids group ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void setGroupOrder( Vector groupids) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create folder |
||||||
|
* @param folder folder name |
||||||
|
* @param new_group_id new group id |
||||||
|
* @return folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int createFolder(String folder, String new_group_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove folder |
||||||
|
* @param folder_id folder id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeFolder(int folder_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update function deleted |
||||||
|
* @param function_id function id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateFunctionDeleted(int function_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename R function |
||||||
|
* @param function_id function id |
||||||
|
* @param functionname function name |
||||||
|
* @param script_file script file path |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void renameFunction(int function_id, String functionname, String script_file) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete R function |
||||||
|
* @param function_id function id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteFunction(int function_id) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update is wiki done |
||||||
|
* @param function_id function id |
||||||
|
* @param done is done |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateWikiDone(int function_id, int done) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get all function names ID |
||||||
|
* @param wherecond where condition |
||||||
|
* @return function names & ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getAllFunctionNamesID(String wherecond) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Auto complete functions |
||||||
|
* @param func_keyword function keyword |
||||||
|
* @return r function |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List autoCompleteFunctions(String func_keyword) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Updated owner ID |
||||||
|
* @param owner_id owner id |
||||||
|
* @param function_id function id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updatedOwnerIDNow(int owner_id,int function_id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get package info by package name |
||||||
|
* @param pname package name |
||||||
|
* @return package info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getPackageInfo(String pname) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get default hierarchy depends ids by package name |
||||||
|
* @param pname package name |
||||||
|
* @return id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getDefaultHierarchyDependsIds(String pname) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List related folder ids |
||||||
|
* @param parent_folder parent folder id |
||||||
|
* @return related folder ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listRelatedFolderIds(int parent_folder) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update related folder ids |
||||||
|
* @param folder_id folder id |
||||||
|
* @param ids related folder ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateRelatedFolderIds(int folder_id, List<Integer> ids) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add tag for package
|
||||||
|
* @param tag_id tag id |
||||||
|
* @param function_ids function ids |
||||||
|
* @param make_owner_also is make owner also |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addTag4Package(int tag_id,int function_ids[],boolean make_owner_also) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add notification tag for package
|
||||||
|
* @param tag_id tag id |
||||||
|
* @param function_ids function ids |
||||||
|
* @param add_also is add a new record also |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addNotificationTag4Package(int tag_id,int function_ids[],boolean add_also) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove tag for package
|
||||||
|
* @param tag_id tag id |
||||||
|
* @param function_ids function ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeTag4Package(int tag_id,int function_ids[]) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update peer package
|
||||||
|
* @param peername peer name |
||||||
|
* @param plist peer package list |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean updatePeerPackage(String peername, ArrayList<PeerPackage>plist) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get R function for script file |
||||||
|
* @param scriptfile script file |
||||||
|
* @return r functions |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getRFunctionForScriptFile(String scriptfile) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update tag id by folder id |
||||||
|
* @param folder_id folder id |
||||||
|
* @param tag_ids tag ids |
||||||
|
* @param removeExisting is remove existing |
||||||
|
* @param tablename table name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateTagIds4Folder(int folder_id, List tag_ids,int removeExisting, String tablename) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get tag id by folder id |
||||||
|
* @param folder_id folder id |
||||||
|
* @param tablename table name |
||||||
|
* @return tag ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract ArrayList getTagIds4Folder(int folder_id, String tablename) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get theme tags by folder id |
||||||
|
* @param folder_id folder id |
||||||
|
* @return theme tags |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getThemeTags4Folder(int folder_id) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get folder theme by R function id |
||||||
|
* @param r_function_id r function id |
||||||
|
* @return theme |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract String getFolderThemeByRFunctionId(int r_function_id) throws Exception ; |
||||||
|
|
||||||
|
public abstract void syncLib(int counter, int theme, int wikiDone, String rScript) throws Exception ; |
||||||
|
|
||||||
|
public abstract void truncateFunctions() throws Exception ; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,137 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.vo.CommodityInfo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to reference |
||||||
|
*/ |
||||||
|
public abstract class ReferenceDB extends SuperDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect database |
||||||
|
*/ |
||||||
|
public void connectDB() throws Exception { |
||||||
|
super.connectDB(DB_NAME_BBSYNC); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get commodity contracts |
||||||
|
* @return commodity contracts |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getComContracts() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete field mapping |
||||||
|
* @param id field mapping id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteFieldMapping(int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add field mapping |
||||||
|
* @param dbfield friendly name |
||||||
|
* @param bbfield bb field name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addFieldMapping(String dbfield, String bbfield) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field mapping |
||||||
|
* @return field mapping |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getFieldMapping() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete security field mapping |
||||||
|
* @param id security field mapping id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteSecFieldMapping(int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add security field mapping |
||||||
|
* @param dbfield friendly name |
||||||
|
* @param bbfield bb field name |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void addSecFieldMapping(String dbfield, String bbfield) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get security field mapping |
||||||
|
* @return security field mapping |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getSecFieldMapping() throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update commodity |
||||||
|
* @param comm commodity info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateCommodity(CommodityInfo comm) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get commodity info |
||||||
|
* @param commodity commodity |
||||||
|
* @return commodity info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getCommodityInfo(String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract info |
||||||
|
* @param contract contract name |
||||||
|
* @return contract info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getContractInfo(String contract) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get security info |
||||||
|
* @param security security name |
||||||
|
* @return security info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getSecurityInfo(String security) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract BB info, this method may not be useful in future. |
||||||
|
* @param contract contract |
||||||
|
* @return contract BB info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getContractBBInfo(String contract) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get security BB info, this method may not be usefull in future. |
||||||
|
* @param security security |
||||||
|
* @return security BB info |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getSecurityBBInfo(String security) throws Exception; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get all security field values |
||||||
|
* @param friendlyname security field mapping friendly name |
||||||
|
* @return security field values |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getAllSecFieldValues(String friendlyname) throws Exception; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,613 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Vector; |
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
|
||||||
|
import org.apache.commons.jcs.JCS; |
||||||
|
import org.apache.commons.jcs.access.CacheAccess; |
||||||
|
import org.apache.commons.jcs.engine.behavior.IElementAttributes; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.mariadb.BBSyncDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.ConstructQueryDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.ContractDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.DBManagerDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.FlexiFieldDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.IExecDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.InfrastructureDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.RFunctionDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.ReferenceDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.SchedulerDBMariaDB; |
||||||
|
import com.fourelementscapital.db.mariadb.UtilDBMariaDB; |
||||||
|
|
||||||
|
import com.jolbox.bonecp.BoneCP; |
||||||
|
import com.jolbox.bonecp.BoneCPConfig; |
||||||
|
import com.jolbox.bonecp.Statistics; |
||||||
|
|
||||||
|
/** |
||||||
|
* Super class of all db classes |
||||||
|
*/ |
||||||
|
public class SuperDB { |
||||||
|
|
||||||
|
// get db name from config file :
|
||||||
|
public static final String DB_NAME_BBSYNC = "bbsync"; |
||||||
|
//public static final String DB_NAME_R_FUNCTION = "rfunction";
|
||||||
|
public static final String DB_NAME_R_FUNCTION = "quantlib"; |
||||||
|
public static final String DB_NAME_TRADING = "trading"; |
||||||
|
public static final String DB_NAME_TRADINGREF = "tradingRef"; |
||||||
|
public static final String DB_NAME_IEXEC = "iexec"; |
||||||
|
public static final String DB_NAME_INFRASTRUCTURE = "infrastructure"; |
||||||
|
|
||||||
|
public static boolean CONNECTION_POOL_ACTIVE=false; |
||||||
|
public static boolean CONNECTION_POOL_CONN_COUNT=true; |
||||||
|
|
||||||
|
private static int db_close_timeout = 5; // default : 5 minutes
|
||||||
|
|
||||||
|
private Connection con = null; |
||||||
|
|
||||||
|
private String db=null; |
||||||
|
private String driver = "com.mysql.jdbc.Driver"; |
||||||
|
|
||||||
|
private static ConcurrentHashMap<String,BoneCP> connPools=new ConcurrentHashMap<String,BoneCP>(); |
||||||
|
|
||||||
|
private static Vector<SuperDB> connections=new Vector<SuperDB>(); |
||||||
|
private Date connectedDate=null; |
||||||
|
private String callStack=null; |
||||||
|
|
||||||
|
public static String MY_SQL_DRIVER="com.mysql.jdbc.Driver"; |
||||||
|
|
||||||
|
private String tablename=null; |
||||||
|
|
||||||
|
private Logger log=LogManager.getLogger(SuperDB.class.getName()); |
||||||
|
//private Logger log = LogManager.getLogger(ExecuteRMgmt.class.getName());
|
||||||
|
|
||||||
|
private static long count=0; |
||||||
|
private static long delays=0; |
||||||
|
|
||||||
|
|
||||||
|
//private static JCS cache=null;
|
||||||
|
private static CacheAccess<String, String> cache=null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get DB close timeout |
||||||
|
* @return timeout |
||||||
|
*/ |
||||||
|
public static int getDbCloseTimeout() { |
||||||
|
if(Config.getString("db_close_timeout") != null) { |
||||||
|
db_close_timeout = Integer.parseInt(Config.getString("db_close_timeout")); |
||||||
|
} |
||||||
|
return db_close_timeout; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get connected date |
||||||
|
* @return connected date |
||||||
|
*/ |
||||||
|
public Date getConnectedDate() { |
||||||
|
return connectedDate; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set connected date |
||||||
|
* @param connectedDate connected date |
||||||
|
*/ |
||||||
|
public void setConnectedDate(Date connectedDate) { |
||||||
|
this.connectedDate = connectedDate; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get call stack |
||||||
|
* @return call stack |
||||||
|
*/ |
||||||
|
public String getCallStack() { |
||||||
|
return callStack; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set call stack |
||||||
|
* @param callStack call stack |
||||||
|
*/ |
||||||
|
public void setCallStack(String callStack) { |
||||||
|
this.callStack = callStack; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Connect to specific database |
||||||
|
* @param db database |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void connectDB(String db) throws Exception { |
||||||
|
|
||||||
|
// Establish the connection.
|
||||||
|
this.db=db; |
||||||
|
|
||||||
|
Date start=new Date(); |
||||||
|
|
||||||
|
String marketConnectionURL = Utils.getConfig4E(".CONFIG4E_JDBC_CONNECTIONSTRING_" + db.toUpperCase()); // throw exception
|
||||||
|
|
||||||
|
// add parameter to prevent timestamp converting error
|
||||||
|
marketConnectionURL += "&useUnicode=true&useFastDateParsing=false&characterEncoding=UTF-8"; |
||||||
|
|
||||||
|
// replace driver if marketConnectionURL contains 'sqlserver'. i.e. 'jdbc:sqlserver://10.153.64.3:1433;databaseName=infrastructure;integratedSecurity=false;user=dbuser;password=dbuser'
|
||||||
|
if (marketConnectionURL.contains("sqlserver")) { |
||||||
|
this.driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if(CONNECTION_POOL_ACTIVE){ |
||||||
|
if(connPools.get(db)==null){ |
||||||
|
setupConnectionPool(marketConnectionURL); |
||||||
|
} |
||||||
|
|
||||||
|
if(this.con!=null && !this.con.isClosed()) { |
||||||
|
//don't assing new
|
||||||
|
printOrphanConns(); |
||||||
|
}else{ |
||||||
|
this.con=connPools.get(db).getAsyncConnection().get(); |
||||||
|
this.setCallStack(collectErrorStack(new Exception().getStackTrace())); |
||||||
|
this.setConnectedDate(new Date()); |
||||||
|
//connPools.get(db).getAsyncConnection()
|
||||||
|
connections.add(this); |
||||||
|
} |
||||||
|
|
||||||
|
}else{ |
||||||
|
Class.forName(this.driver); |
||||||
|
log.debug("marketConnectionURL:"+marketConnectionURL); |
||||||
|
if(this.con!=null && !this.con.isClosed()) { |
||||||
|
//don't assing new
|
||||||
|
//System.out.println("~~~SuperDB.connectDB(): Reuse connection, Already connection is active");
|
||||||
|
printOrphanConns(); |
||||||
|
}else{ |
||||||
|
this.con = DriverManager.getConnection(marketConnectionURL); |
||||||
|
connections.add(this); |
||||||
|
this.setCallStack(collectErrorStack(new Exception().getStackTrace())); |
||||||
|
this.setConnectedDate(new Date()); |
||||||
|
|
||||||
|
//DatabaseMetaData md=this.con.getMetaData();
|
||||||
|
//md.get
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//log.debug("conn opened in "+diff+" ms" +" counter:"+count);
|
||||||
|
if(CONNECTION_POOL_CONN_COUNT) { |
||||||
|
Date end=new Date(); |
||||||
|
long diff=end.getTime()-start.getTime(); |
||||||
|
delays+=diff; |
||||||
|
count++; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get cache |
||||||
|
* @return cache |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static CacheAccess getCache() throws Exception { |
||||||
|
if(cache==null) cache=JCS.getInstance("SuperDB-cache"); |
||||||
|
return cache; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Print orphan connections |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private void printOrphanConns() throws Exception { |
||||||
|
|
||||||
|
if(getCache().get("delayPrint")!=null){ |
||||||
|
System.out.println("~~~SuperDB.connectDB(): Reuse connection, Already connection is active"); |
||||||
|
}else{ |
||||||
|
IElementAttributes att= getCache().getDefaultElementAttributes(); |
||||||
|
att.setMaxLife(600); |
||||||
|
getCache().put("delayPrint","delay",att); |
||||||
|
try{ |
||||||
|
System.out.println("=====SuperDB.connectDB(): Reuse connection, Already connection is active====\n"+collectErrorStack(new Exception().getStackTrace())); |
||||||
|
//Thread.dumpStack();
|
||||||
|
}catch(Exception e){ |
||||||
|
//e.printStackTrace();
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Setup connection pool |
||||||
|
* @param marketConnectionURL market connection URL |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private synchronized void setupConnectionPool(String marketConnectionURL) throws Exception { |
||||||
|
Class.forName(this.driver); // load the DB driver
|
||||||
|
BoneCPConfig config = new BoneCPConfig(); // create a new configuration object
|
||||||
|
config.setJdbcUrl(marketConnectionURL); // set the JDBC url
|
||||||
|
config.setMinConnectionsPerPartition(1); |
||||||
|
config.setMaxConnectionsPerPartition(25); |
||||||
|
config.setPartitionCount(2); //set connectinos returned to pool lives very short
|
||||||
|
//config.setAcquireIncrement(1);
|
||||||
|
config.setMaxConnectionAgeInSeconds(10); |
||||||
|
config.setLogStatementsEnabled(true); |
||||||
|
|
||||||
|
|
||||||
|
connPools.put(db, new BoneCP(config)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Close all connections |
||||||
|
*/ |
||||||
|
public static void closeAllConnections(){ |
||||||
|
for(Iterator it=connPools.keySet().iterator();it.hasNext();) { |
||||||
|
String key=(String)it.next(); |
||||||
|
BoneCP bcp=(BoneCP)connPools.get(key); |
||||||
|
bcp.shutdown(); |
||||||
|
connPools.remove(key); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get connection count |
||||||
|
* @return connection count |
||||||
|
*/ |
||||||
|
public static String getConnectionCount() { |
||||||
|
|
||||||
|
String t="Total Conn:"+count+" total delay:"+delays+" average:"+(delays/count)+" ms"; |
||||||
|
return t; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get connection objects |
||||||
|
* @return connection objects |
||||||
|
*/ |
||||||
|
public static List<SuperDB> getConnectionObjs() { |
||||||
|
return connections; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Reset connection count |
||||||
|
*/ |
||||||
|
public static void connectionCountReset() { |
||||||
|
count=0; |
||||||
|
delays=0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get connection status |
||||||
|
* @return connection status |
||||||
|
*/ |
||||||
|
public static String getConnStatus(){ |
||||||
|
String t="\n"; |
||||||
|
for(Iterator it=connPools.keySet().iterator();it.hasNext();) { |
||||||
|
String key=(String)it.next(); |
||||||
|
BoneCP bcp=(BoneCP)connPools.get(key); |
||||||
|
|
||||||
|
Statistics st=bcp.getStatistics(); |
||||||
|
t+="Db:"+key+" --->"; |
||||||
|
t+=" Total Conn:"+st.getTotalCreatedConnections()+" Free:"+st.getTotalFree()+" Cached hits:"+st.getCacheHits()+" Cached miss:"+st.getCacheMiss()+" Req Conn:"+st.getConnectionsRequested()+" Leased:"+st.getTotalLeased(); |
||||||
|
t+="\n"; |
||||||
|
|
||||||
|
|
||||||
|
//bcp.shutdown();
|
||||||
|
//connPools.remove(key);
|
||||||
|
} |
||||||
|
return t; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get opened connections |
||||||
|
* @return connection count |
||||||
|
*/ |
||||||
|
public static String getOpenedConnections() { |
||||||
|
return "Size:"+connections.size(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Collect error stack |
||||||
|
* @return error stack |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String collectStack() throws Exception { |
||||||
|
return collectErrorStack(new Exception().getStackTrace()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Kill connections |
||||||
|
* @param minsbefore minutes before |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static void killConnections(int minsbefore) throws Exception { |
||||||
|
|
||||||
|
Logger log=LogManager.getLogger(SuperDB.class.getName()); |
||||||
|
Vector<SuperDB> v=new Vector(); |
||||||
|
synchronized(connections) { |
||||||
|
//System.out.println("------" );
|
||||||
|
|
||||||
|
for(SuperDB sdb: connections) { |
||||||
|
|
||||||
|
Calendar opened=Calendar.getInstance(); opened.setTime(sdb.getConnectedDate()); |
||||||
|
Calendar now=Calendar.getInstance(); now.setTime(new Date()); |
||||||
|
now.add(Calendar.MINUTE, -minsbefore); |
||||||
|
|
||||||
|
long diff=new Date().getTime()-sdb.getConnectedDate().getTime(); |
||||||
|
diff=diff/1000; |
||||||
|
|
||||||
|
SimpleDateFormat sdf=new SimpleDateFormat("dd-MMM HH:mm:ss"); |
||||||
|
//System.out.println("Opened at:"+sdf.format(sdb.getConnectedDate())+" now:"+sdf.format(new Date())+"con id: is expired:"+now.after(opened)+" diff:"+diff+" seconds" );
|
||||||
|
|
||||||
|
if(now.after(opened)){ |
||||||
|
//System.out.println("closing connection: as it is expired");
|
||||||
|
//sdb.closeDB();
|
||||||
|
v.add(sdb); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
if(v.size()>0){ |
||||||
|
log.error("~~~~~~Closing "+v.size()+" connections after "+minsbefore+" minutes"); |
||||||
|
} |
||||||
|
for(SuperDB sdb: v) { |
||||||
|
sdb.closeDB(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Collect error stack |
||||||
|
* @return error stack |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static String collectErrorStack(StackTraceElement[] sts) throws Exception { |
||||||
|
String rtn=""; |
||||||
|
|
||||||
|
SimpleDateFormat sdf=new SimpleDateFormat("dd-MMM HH:mm:ss.SSS "); |
||||||
|
rtn+="\n-- "+sdf.format(new Date())+" Thread:"+Thread.currentThread().getId()+" - "+Thread.currentThread().getName()+" --\n"; |
||||||
|
for(int loop=0;loop<sts.length;loop++){ |
||||||
|
if(sts[loop].getClassName().contains("com.fourelementscapital.")){ |
||||||
|
rtn+=" " +sts[loop].getClassName()+"."+sts[loop].getMethodName()+"\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Collect all stack |
||||||
|
* @return stack |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String collectStack4All() throws Exception { |
||||||
|
String rtn=""; |
||||||
|
for(SuperDB sdb: connections){ |
||||||
|
rtn+=sdb.getCallStack()+"\n"; |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
//public BoneCP getConnectionPool(){
|
||||||
|
// return connPools.get(this.db);
|
||||||
|
//}
|
||||||
|
|
||||||
|
/** |
||||||
|
* Set database |
||||||
|
* @param db database |
||||||
|
*/ |
||||||
|
public void setDb(String db){ |
||||||
|
this.db=db; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get database |
||||||
|
* @return database |
||||||
|
*/ |
||||||
|
public String getDb(){ |
||||||
|
return this.db; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get driver |
||||||
|
* @param db database |
||||||
|
* @return driver |
||||||
|
*/ |
||||||
|
public String getDriver(String db) { |
||||||
|
return Config.getValue(db+".db_driver"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get connection |
||||||
|
* @return connection |
||||||
|
*/ |
||||||
|
public Connection connection(){ |
||||||
|
return this.con; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set read only |
||||||
|
* @param flag flag |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void setReadOnly(boolean flag) throws Exception { |
||||||
|
this.con.setReadOnly(flag); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether read only |
||||||
|
* @return true if read only |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public boolean isReadOnly() throws Exception { |
||||||
|
return this.con.isReadOnly(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Close database |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void closeDB() throws Exception { |
||||||
|
if(this.con!=null){ |
||||||
|
//if(CONNECTION_POOL_ACTIVE){
|
||||||
|
|
||||||
|
//}else{
|
||||||
|
|
||||||
|
connections.remove(this); |
||||||
|
this.con.close(); |
||||||
|
this.con=null; |
||||||
|
//}
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether driver is MySQL |
||||||
|
* @return true if driver is MySQL |
||||||
|
*/ |
||||||
|
public boolean isMySQLDriver(){ |
||||||
|
if(this.db!=null && getDriver(this.db)!=null && getDriver(this.db).equals(MY_SQL_DRIVER)){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get contract database class
|
||||||
|
* @param tablename table name |
||||||
|
* @param db database |
||||||
|
* @return contract database class
|
||||||
|
*/ |
||||||
|
public final ContractDB getContractDB(String tablename, String db) { |
||||||
|
this.tablename=tablename; |
||||||
|
this.db=db; |
||||||
|
//if(this.db!=null && getDriver(this.db)!=null && getDriver(this.db).equals(MY_SQL_DRIVER)){
|
||||||
|
ContractDBMariaDB cdb=new ContractDBMariaDB(this.tablename); |
||||||
|
cdb.setDb(db); |
||||||
|
return cdb; |
||||||
|
/* |
||||||
|
}else{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
//public final ContractDB getContractDB(String tablename) {
|
||||||
|
// return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get utility database class
|
||||||
|
* @param db database |
||||||
|
* @return utility database class
|
||||||
|
*/ |
||||||
|
public final UtilDB getUtilDB(String db) { |
||||||
|
|
||||||
|
//return this.utilDB;
|
||||||
|
this.db=db; |
||||||
|
//if(this.db!=null && getDriver(this.db)!=null && getDriver(this.db).equals(MY_SQL_DRIVER)){
|
||||||
|
UtilDBMariaDB udsql=new UtilDBMariaDB(); |
||||||
|
udsql.setDb(db); |
||||||
|
|
||||||
|
return udsql; |
||||||
|
/* |
||||||
|
}else{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get BBSync database class
|
||||||
|
* @return BBSync database class
|
||||||
|
*/ |
||||||
|
public static BBSyncDB getBBSyncDB() { |
||||||
|
return new BBSyncDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get Flexi Field database class
|
||||||
|
* @return Flexi Field database class
|
||||||
|
*/ |
||||||
|
public static FlexiFieldDB getFlexiFieldDB() { |
||||||
|
return new FlexiFieldDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get Reference database class
|
||||||
|
* @return Reference database class
|
||||||
|
*/ |
||||||
|
public static ReferenceDB getReferenceDB() { |
||||||
|
return new ReferenceDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get Scheduler database class
|
||||||
|
* @return Scheduler database class
|
||||||
|
*/ |
||||||
|
public static SchedulerDB getSchedulerDB() { |
||||||
|
return new SchedulerDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get RFunction database class
|
||||||
|
* @return RFunction database class
|
||||||
|
*/ |
||||||
|
public static RFunctionDB getRFunctionDB() { |
||||||
|
return new RFunctionDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get IExec database class
|
||||||
|
* @return IExec database class
|
||||||
|
*/ |
||||||
|
public static IExecDB getIExcecDB() { |
||||||
|
return new IExecDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get DBManager database class
|
||||||
|
* @return DBManager database class
|
||||||
|
*/ |
||||||
|
public static DBManagerDB getDBManagerDB(){ |
||||||
|
return new DBManagerDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get Util database class
|
||||||
|
* @return Util database class
|
||||||
|
*/ |
||||||
|
public static UtilDB getUtilDB4SQLServer() { |
||||||
|
return new UtilDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get ConstructQuery database class
|
||||||
|
* @return ConstructQuery database class
|
||||||
|
*/ |
||||||
|
public static ConstructQueryDB getConstructQueryDB() { |
||||||
|
return new ConstructQueryDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get Infrastructure database class
|
||||||
|
* @return Infrastructure database class
|
||||||
|
*/ |
||||||
|
public static InfrastructureDB getInfrastructureDB() { |
||||||
|
return new InfrastructureDBMariaDB(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,376 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.TreeMap; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.vo.ValueObject; |
||||||
|
|
||||||
|
/** |
||||||
|
* Abstract class implements methods related to utility |
||||||
|
*/ |
||||||
|
public abstract class UtilDB extends SuperDB { |
||||||
|
|
||||||
|
/** |
||||||
|
* List commodities |
||||||
|
* @param con connection |
||||||
|
* @return commodities |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listCommodities(Connection con) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* List commodities with filter |
||||||
|
* @param con connection |
||||||
|
* @param filter filter |
||||||
|
* @return commodities |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listCommoditiesWithFilter(Connection con,String filter) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List first letters of commodities |
||||||
|
* @param con connection |
||||||
|
* @return commodities |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listCommoditiesFirstLetters(Connection con) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get unique fields of commodity field original |
||||||
|
* @param con connection |
||||||
|
* @return commodity field original |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List uniqueFields(Connection con) throws Exception ; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all tables by commodity field original & commodity |
||||||
|
* @param con connection |
||||||
|
* @param field_arr field arr |
||||||
|
* @param commodity_arr commodity arr |
||||||
|
* @return tables |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<Map> listAllTables4Fields(Connection con, String field_arr, String commodity_arr ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all orphaned assets |
||||||
|
* @param con connection |
||||||
|
* @return tables |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<Map> listAllOrphanedAssets(Connection con ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove all orphaned assets |
||||||
|
* @param con connection |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void removeAllOrphanedAssets(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all table strings by commodities |
||||||
|
* @param con connection |
||||||
|
* @param fieldtype field type |
||||||
|
* @param commodities commodities |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<String> listAllTables4Commodities(Connection con, String fieldtype,Vector<String> commodities) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field original |
||||||
|
* @param con connection |
||||||
|
* @param tablename table name |
||||||
|
* @return commodity field original |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract String getFieldOriginal(Connection con,String tablename) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all table value objects by commodities |
||||||
|
* @param con connection |
||||||
|
* @param fieldtype field type |
||||||
|
* @param commodities commodities |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector<ValueObject> listAllTables4Commodities2(Connection con, String fieldtype,Vector<String> commodities) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all contract titles |
||||||
|
* @param con connection |
||||||
|
* @param jointables join tables |
||||||
|
* @return contract titles |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract TreeMap<String,Vector> listAllContractTitles(Connection con, String jointables) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all contract titles |
||||||
|
* @param con connection |
||||||
|
* @param jointables join tables |
||||||
|
* @return contract titles |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract TreeMap<String,Vector> listAllContractTitles2(Connection con, String jointables) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all contract titles in lower case |
||||||
|
* @param con connection |
||||||
|
* @param jointables join tables |
||||||
|
* @return contract titles |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List<String> listAllContractTitles2LCase(Connection con, String jointables) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove commodity and fields |
||||||
|
* @param con connection |
||||||
|
* @param commodity commodity |
||||||
|
* @return true |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean removeCommodityAndFields(Connection con,String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get raw data by table name, contract & date query |
||||||
|
* @param datequery date query |
||||||
|
* @param con connection |
||||||
|
* @param tablename table name |
||||||
|
* @param commodity commodity |
||||||
|
* @return raw data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getRawData(String datequery,Connection con,String tablename, String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get record count by contract & commodity |
||||||
|
* @param con connection |
||||||
|
* @param commodity commodity |
||||||
|
* @param contract contract |
||||||
|
* @return record count |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List getRecordCount4Contracts(Connection con, String commodity, String contract ) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get raw data |
||||||
|
* @param datequery date query |
||||||
|
* @param con connection |
||||||
|
* @param tablename table name |
||||||
|
* @param commodity commodity |
||||||
|
* @return raw data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getRawData3(String datequery,Connection con,String tablename, String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get raw data by contract |
||||||
|
* @param datequery date query |
||||||
|
* @param con connection |
||||||
|
* @param fieldname field name |
||||||
|
* @param contrat contrat |
||||||
|
* @param commodity commodity |
||||||
|
* @return raw data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getRawData2Contract(String datequery,Connection con,String fieldname, String contrat,String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete raw data |
||||||
|
* @param con connection |
||||||
|
* @param tablename table name |
||||||
|
* @param data data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteRawData(Connection con,String tablename,Map<String,String> data) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update raw data |
||||||
|
* @param con connection |
||||||
|
* @param tablename table name |
||||||
|
* @param olddata old data |
||||||
|
* @param newdata new data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void updateRawData(Connection con,String tablename,Map<String,String> olddata,Map<String,String> newdata) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove field table |
||||||
|
* @param con connection |
||||||
|
* @param ftable field table |
||||||
|
* @return true |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean removeFieldTable(Connection con,String ftable) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename field table |
||||||
|
* @param con connection |
||||||
|
* @param ftable field table |
||||||
|
* @param fieldoriginal field original |
||||||
|
* @return true if success |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract boolean renameFieldTable(Connection con,String ftable, String fieldoriginal) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List field tables for admin |
||||||
|
* @param con connection |
||||||
|
* @param mtable commodity |
||||||
|
* @return field tables |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listFieldTables4Admin(Connection con,String mtable) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List field tables |
||||||
|
* @param con connection |
||||||
|
* @param mtable commodity |
||||||
|
* @return field tables |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listFieldTables(Connection con,String mtable) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all unique fields |
||||||
|
* @param con connection |
||||||
|
* @return unique fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listAllUniqueFields(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all unique fields by commodity |
||||||
|
* @param con connection |
||||||
|
* @param commodity commodity |
||||||
|
* @return all unique fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract List listAllUniqueFields(Connection con, String commodity) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete contracts |
||||||
|
* @param con connection |
||||||
|
* @param field_tablename field table name |
||||||
|
* @param contract contract |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteContracts(Connection con, String field_tablename, String contract) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get unique contracts |
||||||
|
* @param con connection |
||||||
|
* @param field_tablename field table name |
||||||
|
* @return contracts |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Vector getUniqueContracts(Connection con, String field_tablename) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List all commodities and fields |
||||||
|
* @param con connection |
||||||
|
* @return commodities and fields |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map listAllCommoditiesAndFields(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Last sync update |
||||||
|
* @param con connection |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void LastSyncUpdate(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Last sync days |
||||||
|
* @param con connection |
||||||
|
* @param today date |
||||||
|
* @return sync date |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract int lastSyncDays(Connection con,Date today) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Last sync date |
||||||
|
* @param con connection |
||||||
|
* @return sync date |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Date lastSyncDate(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get daily strategy data |
||||||
|
* @param con connection |
||||||
|
* @param date date |
||||||
|
* @param contractname contract name |
||||||
|
* @param fields fields |
||||||
|
* @return strategy data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract TreeMap dailyStrategyData(Connection con,String date, String contractname, String fields) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* List saved chart |
||||||
|
* @param con connection |
||||||
|
* @return saved charts |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract TreeMap listSavedChart(Connection con) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete saved chart |
||||||
|
* @param con connection |
||||||
|
* @param id id |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void deleteSavedChart(Connection con, int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get saved chart item |
||||||
|
* @param con connection |
||||||
|
* @param id id |
||||||
|
* @return saved chart |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract Map getSavedChartItem(Connection con, int id) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Add saved chart |
||||||
|
* @param con connection |
||||||
|
* @param data data |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void savedChart(Connection con,Map data) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Show old connections |
||||||
|
* @param minutesbefore minutes before |
||||||
|
* @param computername computer name |
||||||
|
* @return SPID |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract ArrayList showOldConnections(int minutesbefore, String computername) throws Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Kill connections |
||||||
|
* @param conids connection ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public abstract void killConnections(List<Integer> conids) throws Exception ; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,74 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* This class contains Static Utility functions |
||||||
|
* @author manas |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
public class Utils { |
||||||
|
|
||||||
|
private static HashMap<String,String> _config4E; |
||||||
|
|
||||||
|
/** |
||||||
|
* Accepts an ArrayList of strings and then returns a delimiter separated string |
||||||
|
* @param al The arraylist of strings |
||||||
|
* @param delimiter The delimiter |
||||||
|
* @return The delimiter separated string |
||||||
|
*/ |
||||||
|
public static String Join(ArrayList<String> al,String delimiter) |
||||||
|
{ |
||||||
|
return al.toString().replaceAll("\\[|\\]", "").replaceAll(", ",delimiter); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the variables defined in the global config located at /mnt/public/Libs/.4E.config |
||||||
|
* @param variable |
||||||
|
* @return |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
public static String getConfig4E(String variable) throws IOException |
||||||
|
{ |
||||||
|
|
||||||
|
if(_config4E==null) _config4E = new HashMap<String, String>(); |
||||||
|
if((_config4E.size()==0)) |
||||||
|
{ |
||||||
|
|
||||||
|
//FileReader fr = new FileReader("/mnt/public/Libs/.4E.config");
|
||||||
|
FileReader fr = new FileReader(Config.getValue("db_config_path")); |
||||||
|
BufferedReader br = new BufferedReader(fr); |
||||||
|
String s = br.readLine(); |
||||||
|
while(s!=null) |
||||||
|
{ |
||||||
|
if(s.startsWith("#") || s.trim().equals("")){ |
||||||
|
s = br.readLine(); |
||||||
|
continue; |
||||||
|
} |
||||||
|
String[] splits = s.split("=",2); |
||||||
|
_config4E.put(splits[0].trim(), splits[1].trim().replaceAll("\"", "")); |
||||||
|
s = br.readLine(); |
||||||
|
} |
||||||
|
} |
||||||
|
if(_config4E.containsKey(variable.trim())) |
||||||
|
return _config4E.get(variable.trim()); |
||||||
|
else return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,691 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.Date; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.StringTokenizer; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.BBSyncDB; |
||||||
|
import com.fourelementscapital.db.GeneralUtilDB; |
||||||
|
import com.fourelementscapital.db.vo.BBSyncTrigger; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* BBSync MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class BBSyncDBMariaDB extends BBSyncDB { |
||||||
|
private Logger log=LogManager.getLogger(BBSyncDB.class.getName()); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector listAll() throws Exception { |
||||||
|
|
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
ResultSet rs=st.executeQuery("Select * from bbsync order by name"); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//Map record=new BasicRowProcessor().toMap(rs);
|
||||||
|
Map record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
int id=(Integer)record.get("id"); |
||||||
|
record.put("fieldsids",getFieldIds(id)); |
||||||
|
record.put("tickers", getContracts(id)); |
||||||
|
rtn.add(record); |
||||||
|
|
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public ArrayList fieldMapping4BBSync(int bbsyncid) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select * from field_mapping where id in (select field_id from bbsync_fields where bbsync_id=?)"); |
||||||
|
ps.setLong(1, bbsyncid); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
while(rs.next()){ |
||||||
|
//Map record=new BasicRowProcessor().toMap(rs);
|
||||||
|
Map record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
rtn.add(record); |
||||||
|
|
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getDownloadQuery(long id) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from bbsync where id=?"); |
||||||
|
ps.setLong(1, id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Map record=null; |
||||||
|
if(rs.next()){ |
||||||
|
//record=new BasicRowProcessor().toMap(rs);
|
||||||
|
record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
if(record!=null){ |
||||||
|
record.put("fieldsids",getFieldIds(id)); |
||||||
|
record.put("tickers", getContracts(id)); |
||||||
|
} |
||||||
|
return record; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get field id |
||||||
|
* @param bbsyncid bbsync id |
||||||
|
* @return field ids |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private Vector getFieldIds(long bbsyncid) throws Exception { |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("Select field_id from bbsync_fields where bbsync_id=?"); |
||||||
|
ps1.setLong(1, bbsyncid); |
||||||
|
ResultSet rs1=ps1.executeQuery(); |
||||||
|
Vector v=new Vector(); |
||||||
|
while(rs1.next()){ |
||||||
|
v.add((Integer)rs1.getInt("field_id")+""); //convert to string
|
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
rs1.clearWarnings(); |
||||||
|
return v; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get contracts |
||||||
|
* @param bbsyncid bbsync id |
||||||
|
* @return contract |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private String getContracts(long bbsyncid) throws Exception { |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("Select contract from bbsync_contracts where bbsync_id=?"); |
||||||
|
ps1.setLong(1, bbsyncid); |
||||||
|
ResultSet rs1=ps1.executeQuery(); |
||||||
|
String tickers=""; |
||||||
|
while(rs1.next()){ |
||||||
|
tickers+=(tickers.equals(""))?rs1.getString("contract"):","+rs1.getString("contract"); |
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
rs1.clearWarnings(); |
||||||
|
return tickers; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getFieldMapping() throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from field_mapping"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(GeneralUtilDB.resultsetToMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateTriggeredDate(int id, Timestamp start, Timestamp end) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE bbsync SET trigger_startedat=?, trigger_endedat=?,last_executed=? WHERE id=?"); |
||||||
|
ps.setTimestamp(1, start); |
||||||
|
ps.setTimestamp(2, end); |
||||||
|
ps.setTimestamp(3, end); |
||||||
|
ps.setInt(4, id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void deleteFieldMapping(int id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM field_mapping where id=?"); |
||||||
|
ps.setInt(1, id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addFieldMapping(String dbfield, String bbfield) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO field_mapping(db_field, bb_field) VALUES (?,?)"); |
||||||
|
ps.setString(1, dbfield); |
||||||
|
ps.setString(2, bbfield); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateContractLogs(Vector<String> contract,String marketsector,Timestamp lastsync, Map<String,String> scommodities, Collection fields) throws Exception { |
||||||
|
|
||||||
|
for(Iterator it=fields.iterator();it.hasNext();){ |
||||||
|
String field=(String)it.next(); |
||||||
|
PreparedStatement ps3=this.connection().prepareStatement("SELECT * FROM reference.contractSync WHERE contract_name=? AND contract_field=?"); |
||||||
|
PreparedStatement ps4=this.connection().prepareStatement("INSERT INTO reference.contractSync(last_sync,contract_name,contract_field) VALUES(?,?,?)"); |
||||||
|
PreparedStatement ps5=this.connection().prepareStatement("UPDATE reference.contractSync SET last_sync=? WHERE contract_name=? AND contract_field=?"); |
||||||
|
for(Iterator<String> i=contract.iterator();i.hasNext();){ |
||||||
|
String cont=i.next(); |
||||||
|
cont=cont.trim()+" "+marketsector; |
||||||
|
ps3.setString(1, cont); |
||||||
|
ps3.setString(2, field); |
||||||
|
ResultSet rs=ps3.executeQuery(); |
||||||
|
if(rs.next()){ |
||||||
|
ps5.setTimestamp(1, lastsync); |
||||||
|
ps5.setString(2, cont.trim()); |
||||||
|
ps5.setString(3, field); |
||||||
|
ps5.execute(); |
||||||
|
}else{ |
||||||
|
ps4.setTimestamp(1, lastsync); |
||||||
|
ps4.setString(2, cont.trim()); |
||||||
|
ps4.setString(3, field); |
||||||
|
ps4.execute(); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
} |
||||||
|
ps3.close(); |
||||||
|
ps4.close(); |
||||||
|
ps5.close(); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateSecuritiesLogs(Vector<String> contract,String marketsector,Timestamp lastsync,Collection fields) throws Exception { |
||||||
|
|
||||||
|
for(Iterator it=fields.iterator();it.hasNext();){ |
||||||
|
String field=(String)it.next(); |
||||||
|
PreparedStatement ps3=this.connection().prepareStatement("SELECT * FROM reference.SecuritySync WHERE security_name=? AND security_field=?"); |
||||||
|
PreparedStatement ps4=this.connection().prepareStatement("INSERT INTO reference.SecuritySync(last_sync,security_name,security_field) VALUES(?,?,?)"); |
||||||
|
PreparedStatement ps5=this.connection().prepareStatement("UPDATE reference.SecuritySync SET last_sync=? WHERE security_name=? AND security_field=?"); |
||||||
|
for(Iterator<String> i=contract.iterator();i.hasNext();){ |
||||||
|
String cont=i.next(); |
||||||
|
cont=cont.trim()+" "+marketsector; |
||||||
|
ps3.setString(1, cont); |
||||||
|
ps3.setString(2, field); |
||||||
|
ResultSet rs=ps3.executeQuery(); |
||||||
|
if(rs.next()){ |
||||||
|
ps5.setTimestamp(1, lastsync); |
||||||
|
ps5.setString(2, cont.trim()); |
||||||
|
ps5.setString(3, field); |
||||||
|
ps5.execute(); |
||||||
|
}else{ |
||||||
|
ps4.setTimestamp(1, lastsync); |
||||||
|
ps4.setString(2, cont.trim()); |
||||||
|
ps4.setString(3, field); |
||||||
|
ps4.execute(); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
} |
||||||
|
ps3.close(); |
||||||
|
ps4.close(); |
||||||
|
ps5.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector<String> getContractNames2RefSync(boolean pendingonly) throws Exception { |
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
ResultSet rs=null; |
||||||
|
if(pendingonly){ |
||||||
|
rs=st.executeQuery("select * from contract_info WHERE ref_synchronized<=0 OR ref_synchronized is NULL"); |
||||||
|
}else{ |
||||||
|
rs=st.executeQuery("select * from contract_info"); |
||||||
|
} |
||||||
|
Vector<String> v=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
v.add(rs.getString("name")); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return v; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map<String,String> getSecurityNames2RefSync(boolean pendingonly) throws Exception { |
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
ResultSet rs=null; |
||||||
|
if(pendingonly){ |
||||||
|
rs=st.executeQuery("select * from security_info WHERE ref_synchronized<=0 OR ref_synchronized is NULL"); |
||||||
|
}else{ |
||||||
|
rs=st.executeQuery("select * from security_info"); |
||||||
|
} |
||||||
|
LinkedHashMap<String,String> rtn=new LinkedHashMap(); |
||||||
|
while(rs.next()){ |
||||||
|
String name=rs.getString("name"); |
||||||
|
String marketsector=rs.getString("marketsector"); |
||||||
|
rtn.put( name+" "+marketsector,name); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map<String,String> getSecurityName2RefSync(String ticker) throws Exception { |
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
ResultSet rs=null; |
||||||
|
rs=st.executeQuery("select * from security_info where name='"+ticker+"'"); |
||||||
|
|
||||||
|
LinkedHashMap<String,String> rtn=new LinkedHashMap(); |
||||||
|
while(rs.next()){ |
||||||
|
String name=rs.getString("name"); |
||||||
|
String marketsector=rs.getString("marketsector"); |
||||||
|
rtn.put( name+" "+marketsector,name); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateContractReference(String contractname, Map<String,String> fielddata ) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("SELECT * FROM contract_info WHERE name=?"); |
||||||
|
//PreparedStatement ps1=this.connection().prepareStatement("INSERT INTO contract_info(ref_synchronized,first_notice_date,last_trade_date,name) VALUES(?,?,?,?)");
|
||||||
|
|
||||||
|
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd"); |
||||||
|
|
||||||
|
Date fndate=null; |
||||||
|
Date ltdate=null; |
||||||
|
if(fielddata.get("FUT_LAST_TRADE_DT")!=null){ |
||||||
|
ltdate=new Date(sf.parse(fielddata.get("FUT_LAST_TRADE_DT")).getTime()); |
||||||
|
} |
||||||
|
if(fielddata.get("FUT_NOTICE_FIRST")!=null){ |
||||||
|
fndate=new Date(sf.parse(fielddata.get("FUT_NOTICE_FIRST")).getTime()); |
||||||
|
} |
||||||
|
ps.setString(1, contractname); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
PreparedStatement ps1=null; |
||||||
|
int thisid=0; |
||||||
|
boolean updatemode=true; |
||||||
|
if(rs.next()){ |
||||||
|
ps1=this.connection().prepareStatement("UPDATE contract_info SET ref_synchronized=?,first_notice_date=?,last_trade_date=? WHERE name=?"); |
||||||
|
PreparedStatement ps11=this.connection().prepareStatement("DELETE FROM contract_info_fields WHERE contract_id=(select id from contract_info where name=? limit 1)" ); |
||||||
|
ps11.setString(1, contractname); |
||||||
|
ps11.execute(); |
||||||
|
ps11.close(); |
||||||
|
|
||||||
|
PreparedStatement st12=this.connection().prepareStatement("select id from contract_info where name=?"); |
||||||
|
st12.setString(1,contractname); |
||||||
|
ResultSet rs12=st12.executeQuery(); |
||||||
|
if(rs12.next()){ |
||||||
|
thisid=rs12.getInt("id"); |
||||||
|
} |
||||||
|
rs12.close(); |
||||||
|
st12.close(); |
||||||
|
|
||||||
|
}else{ |
||||||
|
ps1=this.connection().prepareStatement("INSERT INTO contract_info(ref_synchronized,first_notice_date,last_trade_date,name) VALUES(?,?,?,?)",Statement.RETURN_GENERATED_KEYS); |
||||||
|
updatemode=false; |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
|
||||||
|
ps1.setInt(1, 1); |
||||||
|
ps1.setDate(2, fndate); |
||||||
|
ps1.setDate(3, ltdate); |
||||||
|
ps1.setString(4, contractname); |
||||||
|
ps1.executeUpdate(); |
||||||
|
if(!updatemode){ |
||||||
|
ResultSet rs1 = ps1.getGeneratedKeys(); |
||||||
|
if(rs1.next()){ |
||||||
|
thisid=rs1.getInt(1); |
||||||
|
} |
||||||
|
rs1.close(); |
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
|
||||||
|
|
||||||
|
if(thisid>0){ |
||||||
|
PreparedStatement ps3=this.connection().prepareStatement("INSERT INTO contract_info_fields(bb_fieldname,value,contract_id) VALUES(?,?,?)"); |
||||||
|
for(Iterator<String> it=fielddata.keySet().iterator();it.hasNext();){ |
||||||
|
String bbfield=it.next(); |
||||||
|
ps3.setString(1,bbfield); |
||||||
|
ps3.setString(2,fielddata.get(bbfield)); |
||||||
|
ps3.setInt(3, thisid); |
||||||
|
ps3.executeUpdate(); |
||||||
|
} |
||||||
|
ps3.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateSecurityReference(String securityname, String marketsector, Map<String,String> fielddata ) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("SELECT * FROM security_info WHERE name=?"); |
||||||
|
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd"); |
||||||
|
Date fndate=null; |
||||||
|
Date ltdate=null; |
||||||
|
|
||||||
|
ps.setString(1, securityname); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
PreparedStatement ps1=null; |
||||||
|
int thisid=0; |
||||||
|
boolean updatemode=true; |
||||||
|
if(rs.next()){ |
||||||
|
ps1=this.connection().prepareStatement("UPDATE security_info SET ref_synchronized=? WHERE name=?"); |
||||||
|
PreparedStatement ps11=this.connection().prepareStatement("DELETE FROM security_info_fields WHERE security_id=(select id from security_info where name=? limit 1)" ); |
||||||
|
ps11.setString(1, securityname); |
||||||
|
ps11.execute(); |
||||||
|
ps11.close(); |
||||||
|
|
||||||
|
PreparedStatement st12=this.connection().prepareStatement("select id from security_info where name=?"); |
||||||
|
st12.setString(1,securityname); |
||||||
|
ResultSet rs12=st12.executeQuery(); |
||||||
|
if(rs12.next()){ |
||||||
|
thisid=rs12.getInt("id"); |
||||||
|
} |
||||||
|
rs12.close(); |
||||||
|
st12.close(); |
||||||
|
|
||||||
|
}else{ |
||||||
|
ps1=this.connection().prepareStatement("INSERT INTO security_info(ref_synchronized, name,marketsector) VALUES(?,?,?)",Statement.RETURN_GENERATED_KEYS); |
||||||
|
updatemode=false; |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
|
||||||
|
ps1.setInt(1, 1); |
||||||
|
ps1.setString(2, securityname); |
||||||
|
if(!updatemode){ |
||||||
|
|
||||||
|
ps1.setString(3, marketsector); |
||||||
|
} |
||||||
|
|
||||||
|
ps1.executeUpdate(); |
||||||
|
if(!updatemode){ |
||||||
|
ResultSet rs1 = ps1.getGeneratedKeys(); |
||||||
|
if(rs1.next()){ |
||||||
|
thisid=rs1.getInt(1); |
||||||
|
} |
||||||
|
rs1.close(); |
||||||
|
} |
||||||
|
ps1.close(); |
||||||
|
|
||||||
|
|
||||||
|
if(thisid>0){ |
||||||
|
PreparedStatement ps3=this.connection().prepareStatement("INSERT INTO security_info_fields(bb_fieldname,value,security_id) VALUES(?,?,?)"); |
||||||
|
for(Iterator<String> it=fielddata.keySet().iterator();it.hasNext();){ |
||||||
|
String bbfield=it.next(); |
||||||
|
ps3.setString(1,bbfield); |
||||||
|
ps3.setString(2,fielddata.get(bbfield)); |
||||||
|
ps3.setInt(3, thisid); |
||||||
|
ps3.executeUpdate(); |
||||||
|
} |
||||||
|
ps3.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addSyncLogs(int bbsyncid, Timestamp start, Timestamp end, String message, String status, String manual_scheduler) throws Exception { |
||||||
|
String dquery="DELETE FROM bbsync_logs WHERE bbsync_id=? AND id NOT IN (select id from (select id from bbsync_logs WHERE bbsync_id=? ORDER BY start_time DESC limit 11) temp_table)"; |
||||||
|
PreparedStatement st=this.connection().prepareStatement(dquery); |
||||||
|
st.setInt(1, bbsyncid); |
||||||
|
st.setInt(2, bbsyncid); |
||||||
|
st.executeUpdate(); |
||||||
|
st.close(); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO bbsync_logs(bbsync_id,start_time,end_time,message,status,manual_scheduler) VALUES(?,?,?,?,?,?)"); |
||||||
|
ps.setInt(1, bbsyncid); |
||||||
|
ps.setTimestamp(2, start); |
||||||
|
ps.setTimestamp(3, end); |
||||||
|
ps.setString(4,message); |
||||||
|
ps.setString(5,status); |
||||||
|
ps.setString(6,manual_scheduler); |
||||||
|
|
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void removeScheduleTicker(int bbsync_id, String ticker) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM bbsync_contracts WHERE bbsync_id=? AND contract=?" ); |
||||||
|
ps.setInt(1, bbsync_id); |
||||||
|
ps.setString(2, ticker.trim()); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int saveSchedule( |
||||||
|
int id, |
||||||
|
String name, |
||||||
|
String mkt_secdb, |
||||||
|
String dateoption, |
||||||
|
Date datefrom, |
||||||
|
Date dateto, |
||||||
|
int datenumber, |
||||||
|
Vector fields, |
||||||
|
String contracts, |
||||||
|
BBSyncTrigger t, |
||||||
|
String marketsector, |
||||||
|
String timezone |
||||||
|
) throws Exception { |
||||||
|
|
||||||
|
log.debug("saveSchedule() called:"); |
||||||
|
String query1; |
||||||
|
PreparedStatement ps; |
||||||
|
if(id>0){ |
||||||
|
query1="UPDATE bbsync SET name=?,is_mkt_securitydb=?,date_option=?,date_recentnumber=?,date_from=?,date_to=?,tickers=?,trigger_type=?,fields=?,trigger_time=?,trigger_days=?,trigger_day=?,marketsector=?,trigger_week=?,trigger_dailyhour=?,timezone=? WHERE id=?"; |
||||||
|
ps=this.connection().prepareStatement(query1); |
||||||
|
}else{ |
||||||
|
query1="INSERT INTO bbsync(name,is_mkt_securitydb,date_option,date_recentnumber,date_from,date_to,tickers,trigger_type,fields,trigger_time,trigger_days,trigger_day,marketsector,trigger_week,trigger_dailyhour,timezone) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; |
||||||
|
ps=this.connection().prepareStatement(query1,Statement.RETURN_GENERATED_KEYS); |
||||||
|
} |
||||||
|
|
||||||
|
log.debug("connection:"+connection()); |
||||||
|
|
||||||
|
log.debug("ps:"+ps); |
||||||
|
log.debug("t:"+t); |
||||||
|
log.debug("query:"+query1); |
||||||
|
log.debug("id:"+id); |
||||||
|
ps.setString(1, name); |
||||||
|
ps.setString(2, mkt_secdb); |
||||||
|
ps.setString(3, dateoption); |
||||||
|
ps.setInt(4, datenumber); |
||||||
|
|
||||||
|
ps.setDate(5, datefrom); |
||||||
|
ps.setDate(6, dateto); |
||||||
|
|
||||||
|
//ps.setString(7, contracts);
|
||||||
|
ps.setString(7, ""); |
||||||
|
|
||||||
|
ps.setInt(8, t.getSynctype()); |
||||||
|
ps.setString(9, ""); // to be removed later.
|
||||||
|
ps.setString(10, t.getTime()); |
||||||
|
ps.setString(11, t.getDays()); |
||||||
|
//ps.setString(13, t.getMonths());
|
||||||
|
|
||||||
|
ps.setInt(12, t.getDay()); |
||||||
|
ps.setString(13, marketsector); |
||||||
|
ps.setInt(14, (t.getWeek()!=null)?t.getWeek():0 ); |
||||||
|
ps.setInt(15, (t.getDailyhour()!=null)?t.getDailyhour():0); |
||||||
|
ps.setString(16, timezone); |
||||||
|
if(id>0){ |
||||||
|
ps.setInt(17, id); |
||||||
|
ps.executeUpdate(); |
||||||
|
}else{ |
||||||
|
ps.executeUpdate(); |
||||||
|
ResultSet rs = ps.getGeneratedKeys(); |
||||||
|
if(rs.next()){ |
||||||
|
id=rs.getInt(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
} |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
if(id>0){ |
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
st.execute("DELETE FROM bbsync_fields WHERE bbsync_id="+id); |
||||||
|
st.close(); |
||||||
|
PreparedStatement ps2=this.connection().prepareStatement("INSERT into bbsync_fields(bbsync_id,field_id) values(?,?)"); |
||||||
|
for(int a=0;a<fields.size();a++){ |
||||||
|
ps2.setInt(1, id); |
||||||
|
ps2.setInt(2, Integer.parseInt((String)fields.get(a))); |
||||||
|
ps2.executeUpdate(); |
||||||
|
} |
||||||
|
ps2.close(); |
||||||
|
|
||||||
|
|
||||||
|
ArrayList tickers= parseFreeTextTokens(contracts); |
||||||
|
Statement st1=this.connection().createStatement(); |
||||||
|
st1.execute("DELETE FROM bbsync_contracts WHERE bbsync_id="+id); |
||||||
|
st1.close(); |
||||||
|
PreparedStatement ps3=this.connection().prepareStatement("INSERT into bbsync_contracts(bbsync_id,contract) values(?,?)"); |
||||||
|
for(int a=0;a<tickers.size();a++){ |
||||||
|
ps3.setInt(1, id); |
||||||
|
ps3.setString(2, ((String)tickers.get(a)).trim()); |
||||||
|
ps3.executeUpdate(); |
||||||
|
} |
||||||
|
ps3.close(); |
||||||
|
|
||||||
|
} |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void deleteQuery(int id) throws Exception { |
||||||
|
|
||||||
|
if(id>0){ |
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
st.execute("DELETE FROM bbsync_fields WHERE bbsync_id="+id); |
||||||
|
st.close(); |
||||||
|
|
||||||
|
Statement st1=this.connection().createStatement(); |
||||||
|
st1.execute("DELETE FROM bbsync_contracts WHERE bbsync_id="+id); |
||||||
|
st1.close(); |
||||||
|
|
||||||
|
Statement st2=this.connection().createStatement(); |
||||||
|
st2.execute("DELETE FROM bbsync WHERE id="+id); |
||||||
|
st2.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void peerStarted(String peername, long sessionid, java.util.Date time) throws Exception { |
||||||
|
Timestamp ts=new Timestamp(time.getTime()); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO peer_sessions(peername, sessionid,started_time) VALUES (?,?,?)"); |
||||||
|
ps.setString(1, peername); |
||||||
|
ps.setLong(2, sessionid); |
||||||
|
ps.setTimestamp(3,ts ); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void peerStopped(String peername,long sessionid, java.util.Date time) throws Exception { |
||||||
|
Timestamp ts=new Timestamp(time.getTime()); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE peer_sessions SET stopped_time=? WHERE peername=? AND sessionid=?"); |
||||||
|
ps.setTimestamp(1,ts ); |
||||||
|
ps.setString(2, peername); |
||||||
|
ps.setLong(3, sessionid); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse free text to list by token |
||||||
|
* @param stringToken string token |
||||||
|
* @return text separated by token in list |
||||||
|
*/ |
||||||
|
private ArrayList parseFreeTextTokens(String stringToken){ |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
if(stringToken!=null && !stringToken.equals("")){ |
||||||
|
String pline=fieldSeparator4FreeText(stringToken); |
||||||
|
StringTokenizer st=new StringTokenizer(stringToken,pline); |
||||||
|
while(st.hasMoreTokens()){ |
||||||
|
rtn.add(st.nextToken()); |
||||||
|
} |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field separator from free text |
||||||
|
* @param stringToken string token |
||||||
|
* @return field separator |
||||||
|
*/ |
||||||
|
private String fieldSeparator4FreeText(String stringToken){ |
||||||
|
return (stringToken.indexOf(",")>=0)?",":"\r\n"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,216 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.ConstructQueryDB; |
||||||
|
|
||||||
|
/** |
||||||
|
* Construct Query MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class ConstructQueryDBMariaDB extends ConstructQueryDB { |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String constructDateInputQuery(Map rtnobj) { |
||||||
|
|
||||||
|
if (rtnobj == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String q = null; |
||||||
|
|
||||||
|
String filtertype = rtnobj.get("filtertype") == null ? "" : rtnobj.get("filtertype").toString(); |
||||||
|
if ("daterange".equals(filtertype)) { |
||||||
|
String dobj1Success = rtnobj.get("dobj1Success").toString(); |
||||||
|
String dobj2Success = rtnobj.get("dobj2Success").toString(); |
||||||
|
String cdatefield = rtnobj.get("cdatefield").toString(); |
||||||
|
String dobj1Sqldate = rtnobj.get("dobj1Sqldate").toString(); |
||||||
|
String dobj2Sqldate = rtnobj.get("dobj2Sqldate").toString(); |
||||||
|
if ("true".equals(dobj1Success) && "true".equals(dobj2Success)) { |
||||||
|
q = cdatefield+" BETWEEN '"+ dobj1Sqldate +"' AND '"+ dobj2Sqldate +"'"; |
||||||
|
} |
||||||
|
} |
||||||
|
else if ("datefrom".equals(filtertype)) { |
||||||
|
String dobj1Success = rtnobj.get("dobj1Success").toString(); |
||||||
|
String cdatefield = rtnobj.get("cdatefield").toString(); |
||||||
|
String dobj1Sqldate = rtnobj.get("dobj1Sqldate").toString(); |
||||||
|
if ("true".equals(dobj1Success)) { |
||||||
|
q = cdatefield+" BETWEEN '"+ dobj1Sqldate +"' AND now() "; |
||||||
|
} |
||||||
|
} |
||||||
|
else if ("number".equals(filtertype)) { |
||||||
|
String filtervalue = rtnobj.get("filtervalue").toString(); |
||||||
|
String numbr = rtnobj.get("number").toString(); |
||||||
|
String cdatefield = rtnobj.get("cdatefield").toString(); |
||||||
|
if ("ndays".equals(filtervalue)) { |
||||||
|
q = cdatefield+">=DATE_ADD(NOW(), interval -"+numbr+" day)"; |
||||||
|
} |
||||||
|
else if ("nweeks".equals(filtervalue)) { |
||||||
|
q = cdatefield+">=DATE_ADD(NOW(), interval -"+numbr+" week)"; |
||||||
|
} |
||||||
|
else if ("nmonths".equals(filtervalue)) { |
||||||
|
q = cdatefield+">=DATE_ADD(NOW(), interval -"+numbr+" month)"; |
||||||
|
} |
||||||
|
else if ("nyears".equals(filtervalue)) { |
||||||
|
q = cdatefield+">=DATE_ADD(NOW(), interval -"+numbr+" year)"; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
Object filtervalue = rtnobj.get("filtervalue"); |
||||||
|
String cdatefield = rtnobj.get("cdatefield").toString(); |
||||||
|
if (filtervalue!=null && !"".equals(filtervalue.toString()) && cdatefield!=null && !"".equals(cdatefield.toString())) { |
||||||
|
q = constructRecentQuery(cdatefield, filtervalue.toString()); |
||||||
|
} |
||||||
|
else { |
||||||
|
q = null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return q; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String constructRecentQuery(String field, String dateQuery) { |
||||||
|
|
||||||
|
if (field == null || "".equals(field)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (dateQuery == null || "".equals(dateQuery)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String q = null; |
||||||
|
if ("last1Hour".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -1 hour)"; |
||||||
|
} |
||||||
|
else if ("last2Hour".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -2 hour)"; |
||||||
|
} |
||||||
|
else if ("last5Hour".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -5 hour)"; |
||||||
|
} |
||||||
|
else if ("last10Hour".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -10 hour)"; |
||||||
|
} |
||||||
|
else if ("last1Day".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -1 day)"; |
||||||
|
} |
||||||
|
else if ("last2Day".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -2 day)"; |
||||||
|
} |
||||||
|
else if ("last3Day".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -3 day)"; |
||||||
|
} |
||||||
|
else if ("last1Week".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -1 week)"; |
||||||
|
} |
||||||
|
else if ("last10Week".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -10 week)"; |
||||||
|
} |
||||||
|
else if ("last1Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -1 month)"; |
||||||
|
} |
||||||
|
else if ("last2Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -2 month)"; |
||||||
|
} |
||||||
|
else if ("last3Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -3 month)"; |
||||||
|
} |
||||||
|
else if ("last6Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -6 month)"; |
||||||
|
} |
||||||
|
else if ("last12Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -12 month)"; |
||||||
|
} |
||||||
|
else if ("last18Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -18 month)"; |
||||||
|
} |
||||||
|
else if ("last24Month".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -24 month)"; |
||||||
|
} |
||||||
|
else if ("last3Year".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -3 year)"; |
||||||
|
} |
||||||
|
else if ("last4Year".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -4 year)"; |
||||||
|
} |
||||||
|
else if ("last5Year".equals(dateQuery)) { |
||||||
|
q = field + ">=DATE_ADD(NOW(), interval -5 year)"; |
||||||
|
} |
||||||
|
else if ("last10Year".equals(dateQuery)) { |
||||||
|
q = "trigger_datetime>=DATE_ADD(NOW(), interval -10 year)"; |
||||||
|
} |
||||||
|
return q; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String constructQueueHistoryQuery(Map rtnobj) { |
||||||
|
|
||||||
|
if (rtnobj == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String q = null; |
||||||
|
|
||||||
|
//q = rtnobj.get("query") == null ? "null" : rtnobj.get("query").toString();
|
||||||
|
q = constructDateInputQuery(rtnobj); |
||||||
|
String statfilter = rtnobj.get("statfilter") == null ? "" : rtnobj.get("statfilter").toString(); |
||||||
|
String scd_typefilter = rtnobj.get("scd_typefilter") == null ? "" : rtnobj.get("scd_typefilter").toString(); |
||||||
|
|
||||||
|
if ("true".equals(rtnobj.get("queryCheck").toString())) { |
||||||
|
|
||||||
|
if(!"".equals(statfilter)){ |
||||||
|
if("{null}".equals(statfilter)){ |
||||||
|
q+=" AND a.status IS NULL"; |
||||||
|
}else if("#success".equals(statfilter)){ |
||||||
|
q+=" AND (a.status<>'success' OR a.status IS NULL )"; |
||||||
|
}else { |
||||||
|
q+=" AND a.status='"+statfilter+"'"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
q += (!"".equals(scd_typefilter)) ? " AND b.taskuid='"+ scd_typefilter +"'" : ""; |
||||||
|
|
||||||
|
String fld1 = rtnobj.get("fld1") == null ? "" : rtnobj.get("fld1").toString(); |
||||||
|
String scd_filterfieldval = rtnobj.get("scd_filterfieldval") == null ? "" : rtnobj.get("scd_filterfieldval").toString(); |
||||||
|
|
||||||
|
String q1 = ""; |
||||||
|
if(!"".equals(fld1) && !"tag".equals(fld1) && !"".equals(scd_filterfieldval)){ |
||||||
|
String val1=scd_filterfieldval; |
||||||
|
if("name".equals(fld1)){q1=" b.name LIKE '%"+val1+"%' ";} |
||||||
|
if("scheduler_id".equals(fld1)){q1=" a.scheduler_id="+val1+"";} |
||||||
|
q += ("".equals(q1)) ? "" : " AND "+ q1 +" "; |
||||||
|
} |
||||||
|
|
||||||
|
String scd_filterddval = rtnobj.get("scd_filterddval") == null ? "" : rtnobj.get("scd_filterddval").toString(); |
||||||
|
if("host".equals(fld1) && !"".equals(scd_filterddval)) { |
||||||
|
q1 = " a.host='"+ scd_filterddval +"'"; |
||||||
|
q += ("".equals(q1)) ? "" : " AND "+ q1 +" "; |
||||||
|
} |
||||||
|
|
||||||
|
if("tag".equals(fld1) && !"".equals(scd_filterddval)) { |
||||||
|
String val1 = rtnobj.get("scd_filterddval") == null ? "" : rtnobj.get("scd_filterddval").toString(); |
||||||
|
q1=" a.scheduler_id IN(SELECT scheduler_id from scheduler_tags where tag_id="+val1+") "; |
||||||
|
q += ("".equals(q1)) ? "" : " AND "+ q1 +" "; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return q; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,382 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.ContractDB; |
||||||
|
import com.fourelementscapital.db.GeneralUtilDB; |
||||||
|
import com.fourelementscapital.db.vo.Contract; |
||||||
|
import com.fourelementscapital.db.vo.Strategy; |
||||||
|
|
||||||
|
/** |
||||||
|
* Contract MySQL DAO implementation |
||||||
|
*/ |
||||||
|
public class ContractDBMariaDB extends ContractDB { |
||||||
|
|
||||||
|
private Logger log=LogManager.getLogger(ContractDB.class.getName()); |
||||||
|
|
||||||
|
private String tablename; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor |
||||||
|
* @param tablename table name |
||||||
|
*/ |
||||||
|
public ContractDBMariaDB(String tablename){ |
||||||
|
this.tablename=tablename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor |
||||||
|
*/ |
||||||
|
public ContractDBMariaDB(){ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateRecords(Connection con,Vector records) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement st=con.prepareStatement("INSERT into "+this.tablename+" (cdate,contract,val) VALUES(?,?,?) "); |
||||||
|
PreparedStatement st1=con.prepareStatement("SELECT cdate FROM "+this.tablename+" WHERE cdate=? AND contract=?"); |
||||||
|
PreparedStatement st2=con.prepareStatement("UPDATE "+this.tablename+" SET val=? WHERE cdate=? AND contract=?"); |
||||||
|
|
||||||
|
log.debug("records: size:"+records.size()); |
||||||
|
for(Iterator<Contract> i=records.iterator();i.hasNext();){ |
||||||
|
|
||||||
|
Contract contract=i.next(); |
||||||
|
log.debug("contract: date():"+contract.getCdate()); |
||||||
|
|
||||||
|
st1.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st1.setString(2, contract.getName()); |
||||||
|
if(!st1.executeQuery().next()){ |
||||||
|
st.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st.setString(2, contract.getName()); |
||||||
|
st.setDouble(3, contract.getValue()); |
||||||
|
st.executeUpdate(); |
||||||
|
}else{ |
||||||
|
st2.setDouble(1, contract.getValue()); |
||||||
|
st2.setDate(2, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st2.setString(3, contract.getName()); |
||||||
|
st2.executeUpdate(); |
||||||
|
} |
||||||
|
} |
||||||
|
st1.close(); |
||||||
|
st2.close(); |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addRecords(Connection con,Vector records) throws Exception { |
||||||
|
log.debug("records: size:"+records.size()); |
||||||
|
PreparedStatement st=con.prepareStatement("INSERT into "+this.tablename+"(cdate,contract,val) VALUES(?,?,?) "); |
||||||
|
for(Iterator<Contract> i=records.iterator();i.hasNext();){ |
||||||
|
Contract contract=i.next(); |
||||||
|
log.debug("contract: date():"+contract.getCdate()); |
||||||
|
log.debug("contract: sqldbs():"+new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
log.debug("contract: this.tablename():"+this.tablename); |
||||||
|
|
||||||
|
st.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st.setString(2, contract.getName()); |
||||||
|
st.setDouble(3, contract.getValue()); |
||||||
|
st.executeUpdate(); |
||||||
|
} |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void createTable(Connection con, int decimalpoint) throws Exception { |
||||||
|
|
||||||
|
String query="CREATE TABLE IF NOT EXISTS "+this.tablename +" ( "; |
||||||
|
query+="cdate datetime NOT NULL ,"; |
||||||
|
query+="contract varchar(50), "; |
||||||
|
query+="val numeric(20,"+decimalpoint+") "; |
||||||
|
query+=") "; |
||||||
|
|
||||||
|
//System.out.println("ContractDB.class: query:"+query);
|
||||||
|
|
||||||
|
Statement st=con.createStatement(); |
||||||
|
st.execute(query); |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/* |
||||||
|
* implemented but that of changing to different field. |
||||||
|
public void createNewContract(Connection con,String subtablename, String contract) throws Exception { |
||||||
|
|
||||||
|
String query="IF NOT EXISTS (select * from sysobjects where id = object_id('asset_contracts') and OBJECTPROPERTY(id, 'IsUserTable') = 1) "; |
||||||
|
query+="BEGIN "; |
||||||
|
query+="CREATE TABLE asset_contracts ( "; |
||||||
|
query+="tablename varchar(50) ,"; |
||||||
|
query+="contract varchar(50) "; |
||||||
|
query+=") "; |
||||||
|
query+="END "; |
||||||
|
|
||||||
|
Statement st=con.createStatement(); |
||||||
|
st.execute(query); |
||||||
|
st.close(); |
||||||
|
|
||||||
|
PreparedStatement st1=con.prepareStatement("INSERT into asset_contracts(tablename,contract) VALUES(?,?) "); |
||||||
|
st1.setString(1,subtablename); |
||||||
|
st1.setString(2, contract); |
||||||
|
st1.executeUpdate(); |
||||||
|
st1.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public List getCustomContracts(Connection con,String subtablename) throws Exception { |
||||||
|
|
||||||
|
String query="select * from sysobjects where id = object_id('asset_contracts') and OBJECTPROPERTY(id, 'IsUserTable') = 1 "; |
||||||
|
|
||||||
|
Vector rtn=new Vector(); |
||||||
|
Statement st=con.createStatement(); |
||||||
|
ResultSet rs=st.executeQuery(query); |
||||||
|
if(rs.next()){ |
||||||
|
Statement st1=con.createStatement(); |
||||||
|
ResultSet rs1=st1.executeQuery("select contract from asset_contracts WHERE tablename='"+subtablename+"'"); |
||||||
|
while(rs1.next()){ |
||||||
|
rtn.add(rs.getString("contract")); |
||||||
|
} |
||||||
|
rs1.close(); |
||||||
|
st1.close(); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateSValRecords(Connection con,Vector records) throws Exception { |
||||||
|
PreparedStatement st=con.prepareStatement("INSERT into "+this.tablename+"(cdate,contract,val,sval) VALUES(?,?,?,?) "); |
||||||
|
PreparedStatement st1=con.prepareStatement("SELECT cdate FROM "+this.tablename+" WHERE cdate=? AND contract=?"); |
||||||
|
PreparedStatement st2=con.prepareStatement("UPDATE "+this.tablename+" SET val=?,sval=? WHERE cdate=? AND contract=?"); |
||||||
|
for(Iterator<Strategy> i=records.iterator();i.hasNext();){ |
||||||
|
|
||||||
|
Strategy contract=i.next(); |
||||||
|
st1.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st1.setString(2, contract.getName()); |
||||||
|
if(!st1.executeQuery().next()){ |
||||||
|
st.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st.setString(2, contract.getName()); |
||||||
|
if(contract.getSvalue()!=null){ |
||||||
|
st.setObject(3, null); |
||||||
|
}else{ |
||||||
|
st.setDouble(3, contract.getValue()); |
||||||
|
} |
||||||
|
st.setString(4, contract.getSvalue()); |
||||||
|
st.executeUpdate(); |
||||||
|
}else{ |
||||||
|
if(contract.getSvalue()!=null){ |
||||||
|
st2.setObject(1, null); |
||||||
|
}else{ |
||||||
|
st2.setDouble(1, contract.getValue()); |
||||||
|
} |
||||||
|
st2.setString(2, contract.getSvalue()); |
||||||
|
st2.setDate(3, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st2.setString(4, contract.getName()); |
||||||
|
st2.executeUpdate(); |
||||||
|
} |
||||||
|
} |
||||||
|
st1.close(); |
||||||
|
st2.close(); |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addSValRecords(Connection con,Vector records) throws Exception { |
||||||
|
PreparedStatement st=con.prepareStatement("INSERT into "+this.tablename+"(cdate,contract,sval) VALUES(?,?,?) "); |
||||||
|
for(Iterator<Strategy> i=records.iterator();i.hasNext();){ |
||||||
|
Strategy contract=i.next(); |
||||||
|
st.setDate(1, new java.sql.Date(contract.getCdate().getTime())); |
||||||
|
st.setString(2, contract.getName()); |
||||||
|
//st.setDouble(3, contract.getValue());
|
||||||
|
st.setString(3, contract.getSvalue()); |
||||||
|
st.executeUpdate(); |
||||||
|
} |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void createSValTable(Connection con, int decimalpoint) throws Exception { |
||||||
|
|
||||||
|
String query="CREATE TABLE IF NOT EXISTS "+this.tablename +" ( "; |
||||||
|
query+="cdate datetime NOT NULL ,"; |
||||||
|
query+="contract varchar(50), "; |
||||||
|
query+="sval varchar(50), "; |
||||||
|
query+="val numeric(20,"+decimalpoint+") "; |
||||||
|
query+=") "; |
||||||
|
|
||||||
|
//System.out.println("ContractDB.class: query:"+query);
|
||||||
|
|
||||||
|
Statement st=con.createStatement(); |
||||||
|
st.execute(query); |
||||||
|
st.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int checkSValueField(Connection con) throws Exception { |
||||||
|
String query="select count(*) as cnum from "+this.tablename+" where val is not null"; |
||||||
|
Statement st=con.createStatement(); |
||||||
|
ResultSet rs=st.executeQuery(query); |
||||||
|
int valcount=1; |
||||||
|
if(rs.next()){ |
||||||
|
valcount=rs.getInt("cnum"); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return valcount; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int countRecords(Connection con) throws Exception { |
||||||
|
String query="select count(*) as cnum from "+this.tablename+" "; |
||||||
|
Statement st=con.createStatement(); |
||||||
|
ResultSet rs=st.executeQuery(query); |
||||||
|
int valcount=1; |
||||||
|
if(rs.next()){ |
||||||
|
valcount=rs.getInt("cnum"); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return valcount; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public boolean checkSValueFieldTypeExist(Connection con) throws Exception { |
||||||
|
String query="SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '"+this.tablename+"' AND COLUMN_NAME = 'sval' AND table_schema = '"+getDb()+"'"; |
||||||
|
Statement st=con.createStatement(); |
||||||
|
ResultSet rs=st.executeQuery(query); |
||||||
|
boolean exist=false; |
||||||
|
if(rs.next()){ |
||||||
|
exist=true; |
||||||
|
} |
||||||
|
return exist; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List getContractTitles(Connection con) throws Exception { |
||||||
|
Vector rtn=new Vector(); |
||||||
|
Statement st=con.createStatement(); |
||||||
|
ResultSet rs=st.executeQuery("SELECT distinct contract FROM "+this.tablename); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getString("contract")); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List getContractTitles(Connection con, String datequery) throws Exception { |
||||||
|
Vector rtn=new Vector(); |
||||||
|
Statement st=con.createStatement(); |
||||||
|
datequery=GeneralUtilDB.convertFromSQL(datequery); |
||||||
|
ResultSet rs=st.executeQuery("SELECT distinct contract FROM "+this.tablename+((datequery!=null && !datequery.equals(""))? " WHERE "+datequery:"")); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getString("contract")); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateMasterTable(Connection con,String mtable,String fieldname) throws Exception { |
||||||
|
|
||||||
|
String query="CREATE TABLE IF NOT EXISTS asset_master ( "; |
||||||
|
query+="commodity varchar(50) NOT NULL ,"; |
||||||
|
query+="commodity_field varchar(100), "; |
||||||
|
query+="commodity_fieldoriginal varchar(100) "; |
||||||
|
query+=") "; |
||||||
|
|
||||||
|
|
||||||
|
Statement st=con.createStatement(); |
||||||
|
st.execute(query); |
||||||
|
st.close(); |
||||||
|
|
||||||
|
PreparedStatement st1=con.prepareStatement("SELECT commodity FROM asset_master WHERE commodity=? AND commodity_field=?"); |
||||||
|
PreparedStatement st2=con.prepareStatement("INSERT into asset_master(commodity,commodity_field,commodity_fieldoriginal) VALUES(?,?,?) "); |
||||||
|
|
||||||
|
st1.setString(1, mtable); |
||||||
|
st1.setString(2, this.tablename); |
||||||
|
if(!st1.executeQuery().next()){ |
||||||
|
st2.setString(1, mtable); |
||||||
|
st2.setString(2, this.tablename); |
||||||
|
st2.setString(3, fieldname); |
||||||
|
st2.executeUpdate(); |
||||||
|
} |
||||||
|
st1.close(); |
||||||
|
st2.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String generateSQLXLQueryPlainQuery(String fieldtable, int nmonths, List contractTitleList) { |
||||||
|
|
||||||
|
String rtn="SELECT cdate "; |
||||||
|
for(Iterator<String> it=contractTitleList.iterator();it.hasNext();){ |
||||||
|
String contract=it.next(); |
||||||
|
rtn+=",\r\nMAX(CASE WHEN contract='"+contract+"' THEN val END) AS "+contract+" "; |
||||||
|
} |
||||||
|
rtn+="\r\nFROM "+fieldtable+" WHERE cdate>=DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -" + nmonths + " month) GROUP BY cdate ORDER BY cdate DESC"; |
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.DBManagerDB; |
||||||
|
import com.fourelementscapital.db.GeneralUtilDB; |
||||||
|
|
||||||
|
/** |
||||||
|
* DBManager MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class DBManagerDBMariaDB extends DBManagerDB{ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List listDBGroups() throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from dbman_group ORDER BY disp_order"); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(GeneralUtilDB.resultsetToMap(rs)); |
||||||
|
|
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,152 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.commons.dbutils.BasicRowProcessor; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.FlexiFieldDB; |
||||||
|
import com.fourelementscapital.db.GeneralUtilDB; |
||||||
|
import com.fourelementscapital.db.vo.FlexiField; |
||||||
|
|
||||||
|
/** |
||||||
|
* FlexiField MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class FlexiFieldDBMariaDB extends FlexiFieldDB { |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List getFlexiFields(String tablename) throws Exception { |
||||||
|
PreparedStatement pst=this.connection().prepareStatement("select * from flexi_field WHERE tablename=? ORDER BY displayorder"); |
||||||
|
pst.setString(1, tablename); |
||||||
|
ResultSet rs=pst.executeQuery(); |
||||||
|
List<FlexiField> list= new BasicRowProcessor().toBeanList(rs, FlexiField.class); |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addFlexiField(FlexiField ffield) throws Exception { |
||||||
|
PreparedStatement pst=this.connection().prepareStatement("insert into flexi_field(fieldlabel,fieldtype,fieldoptions,tablename) values(?,?,?,?)"); |
||||||
|
pst.setString(1, ffield.getFieldlabel()); |
||||||
|
pst.setString(2, ffield.getFieldtype()); |
||||||
|
pst.setString(3, ffield.getFieldoptions()); |
||||||
|
pst.setString(4, ffield.getTablename()); |
||||||
|
pst.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateFlexiField(long id,FlexiField ffield) throws Exception { |
||||||
|
PreparedStatement pst=this.connection().prepareStatement("UPDATE flexi_field SET fieldlabel=?,fieldoptions=? WHERE id=?"); |
||||||
|
pst.setString(1, ffield.getFieldlabel()); |
||||||
|
pst.setString(2, ffield.getFieldoptions()); |
||||||
|
pst.setLong(3, id); |
||||||
|
pst.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateFlexiFieldOrder(long id,int order) throws Exception { |
||||||
|
PreparedStatement pst=this.connection().prepareStatement("UPDATE flexi_field SET displayorder=? WHERE id=?"); |
||||||
|
pst.setInt(1, order); |
||||||
|
pst.setLong(2,id); |
||||||
|
pst.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void deleteFlexiField(long id) throws Exception { |
||||||
|
PreparedStatement pst=this.connection().prepareStatement("DELETE FROM flexi_field WHERE id=?"); |
||||||
|
pst.setLong(1, id); |
||||||
|
pst.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getFlexiFieldData (String tablename, String idfield, String idvalue) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement pst=this.connection().prepareStatement("select * from "+tablename+" WHERE "+idfield+"=?"); |
||||||
|
pst.setString(1, idvalue); |
||||||
|
ResultSet rs=pst.executeQuery(); |
||||||
|
|
||||||
|
HashMap data=new HashMap(); |
||||||
|
while(rs.next()){ |
||||||
|
long flexid= rs.getLong("flexi_field_id"); |
||||||
|
String val=rs.getString("val"); |
||||||
|
data.put(flexid, val); |
||||||
|
} |
||||||
|
return data; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector<Map> getFlexiFieldData4LuceneToken (String tablename, String idfield, String idvalue) throws Exception { |
||||||
|
|
||||||
|
String query="select a.*,b.fieldlabel from "+tablename+" as a left outer join flexi_field as b on b.id=a.flexi_field_id WHERE a."+idfield+"=?"; |
||||||
|
PreparedStatement pst=this.connection().prepareStatement(query); |
||||||
|
//Log.debug("getFlexiFieldData4LuceneToken() query:"+query);
|
||||||
|
pst.setString(1, idvalue); |
||||||
|
ResultSet rs=pst.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//Map rdata= new BasicRowProcessor().toMap(rs);
|
||||||
|
Map rdata = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
rtn.add(rdata); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void saveFlexiFieldData (String tablename, String idfield, String idvalue, Map data) throws Exception { |
||||||
|
|
||||||
|
|
||||||
|
PreparedStatement pst1=this.connection().prepareStatement("DELETE FROM "+tablename+" WHERE "+idfield+"=?" ); |
||||||
|
pst1.setString(1, idvalue); |
||||||
|
pst1.executeUpdate(); |
||||||
|
pst1.close(); |
||||||
|
|
||||||
|
PreparedStatement pst=this.connection().prepareStatement("insert into "+tablename+"(flexi_field_id,"+idfield+",val) values (?,?,?)"); |
||||||
|
for(Iterator i=data.keySet().iterator();i.hasNext();){ |
||||||
|
Object ky=i.next(); |
||||||
|
Object val=data.get(ky); |
||||||
|
Long fid=Long.parseLong(ky+""); |
||||||
|
pst.setLong(1, fid); |
||||||
|
pst.setString(2, idvalue); |
||||||
|
pst.setString(3, val+""); |
||||||
|
pst.execute(); |
||||||
|
} |
||||||
|
pst1.close(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,497 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.commons.dbutils.BasicRowProcessor; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.IExecDB; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* IExec MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class IExecDBMariaDB extends IExecDB{ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List listGroups() throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps=this.connection().prepareStatement("Select * from `ie_group` ORDER BY disp_order");
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from ie_group ORDER BY disp_order"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void setGroupOrder( Vector groupids) throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps1=this.connection().prepareStatement("UPDATE `ie_group` SET disp_order=? WHERE group_uid=?");
|
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("UPDATE ie_group SET disp_order=? WHERE group_uid=?"); |
||||||
|
int count=0; |
||||||
|
for(Iterator<String> i=groupids.iterator();i.hasNext();){ |
||||||
|
ps1.setInt(1, count++); |
||||||
|
ps1.setString(2, i.next()); |
||||||
|
ps1.executeUpdate(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List listFolders( ) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=null; |
||||||
|
ps=this.connection().prepareStatement("Select * FROM ie_folder ORDER BY folder_name"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String getFolderName(int folder_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select folder_name FROM ie_folder WHERE id=?"); |
||||||
|
ps.setInt(1,folder_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
String rtn=null; |
||||||
|
while(rs.next()){ |
||||||
|
rtn=rs.getString(1); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void renameStrategy(int strategy_id, String strategy_name, String file_name) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE ie_strategy SET strategy_name=?,file_name=? WHERE id=?"); |
||||||
|
|
||||||
|
ps.setString(1, strategy_name); |
||||||
|
ps.setString(2, file_name); |
||||||
|
ps.setInt(3,strategy_id); |
||||||
|
|
||||||
|
ps.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void renameParentStrategy(int strategy_id, String strategy_name, String file_name, String old_strategy_name) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE ie_strategy SET strategy_name=?,file_name=? WHERE id=?"); |
||||||
|
ps.setString(1, strategy_name); |
||||||
|
ps.setString(2, file_name); |
||||||
|
ps.setInt(3,strategy_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
|
||||||
|
PreparedStatement ps2=this.connection().prepareStatement("UPDATE ie_strategy SET parent_strategy=? WHERE parent_strategy=?"); |
||||||
|
ps2.setString(1, strategy_name); |
||||||
|
ps2.setString(2, old_strategy_name); |
||||||
|
ps2.executeUpdate(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void moveFolder(int folder_id, String new_group_id) throws Exception{ |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE ie_folder SET group_uid = ? WHERE id=?"); |
||||||
|
ps.setString(1, new_group_id); |
||||||
|
ps.setInt(2,folder_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateStrategyFolder(int strategy_id,int new_folder_id) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("UPDATE ie_strategy SET folder_id=? WHERE id=?"); |
||||||
|
ps.setInt(1,new_folder_id); |
||||||
|
ps.setInt(2, strategy_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List listStrategies() throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select a.*,b.folder_name FROM ie_strategy as a left outer join ie_folder as b on a.folder_id=b.id order by a.parent_strategy, a.strategy_name"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getStrategy(int strategy_id) throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps=this.connection().prepareStatement("Select * FROM r_function WHERE id=?");
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select a.*,b.folder_name FROM ie_strategy as a left outer join ie_folder as b on a.folder_id=b.id WHERE a.id=? ORDER BY a.strategy_name "); |
||||||
|
|
||||||
|
|
||||||
|
ps.setInt(1, strategy_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
|
||||||
|
Map rtn=null; |
||||||
|
if(rs.next()){ |
||||||
|
rtn=new BasicRowProcessor().toMap(rs); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getUniqueContracts(String strategy_name) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select DISTINCT contract FROM ie_parameter WHERE strategy_name=? "); |
||||||
|
ps.setString(1,strategy_name); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
|
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(rs.getString("contract")); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addParameters(ArrayList<Map> data,String strategy_name) throws Exception { |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("DELETE FROM ie_parameter WHERE strategy_name=?"); |
||||||
|
ps1.setString(1,strategy_name); |
||||||
|
ps1.executeUpdate(); |
||||||
|
|
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO ie_parameter(strategy_name,contract,placeholder,value) VALUES(?,?,?,?)"); |
||||||
|
for(Iterator i=data.iterator();i.hasNext();){ |
||||||
|
Map row=(Map)i.next(); |
||||||
|
ps.setString(1, (String)row.get("strategy_name")); |
||||||
|
ps.setString(2, (String)row.get("contract")); |
||||||
|
ps.setString(3, (String)row.get("placeholder")); |
||||||
|
ps.setString(4, (String)row.get("value")); |
||||||
|
ps.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void removeContract(String strategy_name, String contract) throws Exception { |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement("DELETE FROM ie_parameter WHERE strategy_name=? AND contract=?"); |
||||||
|
ps1.setString(1,strategy_name); |
||||||
|
ps1.setString(2,contract); |
||||||
|
ps1.executeUpdate(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getParameterValues(String strategy_name, String contract) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select placeholder,value FROM ie_parameter WHERE strategy_name=? AND contract=?"); |
||||||
|
ps.setString(1, strategy_name); |
||||||
|
ps.setString(2, contract); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
HashMap h=new HashMap(); |
||||||
|
while(rs.next()){ |
||||||
|
h.put(rs.getString("placeholder"), rs.getString("value")); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
return h; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getStrategy(String strategy_name) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * FROM ie_strategy WHERE strategy_name=?"); |
||||||
|
ps.setString(1, strategy_name); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Map rtn=null; |
||||||
|
if(rs.next()){ |
||||||
|
rtn=new BasicRowProcessor().toMap(rs); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getStrategies(Vector strategy_names) throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps=this.connection().prepareStatement("Select * FROM r_function WHERE id=?");
|
||||||
|
|
||||||
|
String sfunc="''"; |
||||||
|
for(Iterator i=strategy_names.iterator();i.hasNext();){ |
||||||
|
sfunc+=",'"+i.next()+"'"; |
||||||
|
} |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * FROM ie_strategy WHERE strategy_name IN ("+sfunc+") ORDER BY strategy_name "); |
||||||
|
|
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
|
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int createStrategy(int folder_id,String strategy_name, String path) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO ie_strategy(folder_id,strategy_name,file_name) VALUES(?,?,?)",Statement.RETURN_GENERATED_KEYS); |
||||||
|
ps.setInt(1,folder_id); |
||||||
|
ps.setString(2, strategy_name); |
||||||
|
ps.setString(3, path); |
||||||
|
ps.executeUpdate(); |
||||||
|
int id=0; |
||||||
|
ResultSet generatedKeys = ps.getGeneratedKeys(); |
||||||
|
|
||||||
|
if (generatedKeys.next()) { |
||||||
|
id=generatedKeys.getInt(1); |
||||||
|
} |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
return id; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int createChildStrategy(String parent_name,String strategy_name) throws Exception { |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO ie_strategy(parent_strategy,strategy_name) VALUES(?,?)",Statement.RETURN_GENERATED_KEYS); |
||||||
|
ps.setString(1,parent_name); |
||||||
|
ps.setString(2, strategy_name); |
||||||
|
|
||||||
|
ps.executeUpdate(); |
||||||
|
int id=0; |
||||||
|
ResultSet generatedKeys = ps.getGeneratedKeys(); |
||||||
|
|
||||||
|
if (generatedKeys.next()) { |
||||||
|
id=generatedKeys.getInt(1); |
||||||
|
} |
||||||
|
ps.close(); |
||||||
|
|
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int getFolderID(String folder_name) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=null; |
||||||
|
ps=this.connection().prepareStatement("Select * FROM ie_folder WHERE folder_name=?"); |
||||||
|
ps.setString(1, folder_name); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
int rtn=0; |
||||||
|
if(rs.next()){ |
||||||
|
rtn=rs.getInt("id"); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public int createFolder(String folder, String new_group_id) throws Exception{ |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO ie_folder(folder_name,group_uid) VALUES(?,?)",Statement.RETURN_GENERATED_KEYS); |
||||||
|
ps.setString(1, folder); |
||||||
|
ps.setString(2, new_group_id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ResultSet generatedKeys = ps.getGeneratedKeys(); |
||||||
|
int id=0; |
||||||
|
if (generatedKeys.next()) { |
||||||
|
id=generatedKeys.getInt(1); |
||||||
|
} |
||||||
|
ps.close(); |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List listOfFolders(String group_id) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=null; |
||||||
|
ps=this.connection().prepareStatement("Select * FROM ie_folder WHERE group_uid=? ORDER BY folder_name"); |
||||||
|
ps.setString(1, group_id); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/* |
||||||
|
public Vector getContractTree() throws Exception { |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
sb.append("SELECT contract,commodity as commodity FROM trading.tblContractAllocation WHERE commodity in (SELECT commodity from tradingRef.commodityRef) "); |
||||||
|
sb.append("AND date= "); |
||||||
|
sb.append("CASE DAYOFWEEK(SUBDATE(CURRENT_DATE, 1)) "); |
||||||
|
sb.append(" WHEN 1 THEN SUBDATE(CURRENT_DATE, 3) "); |
||||||
|
sb.append(" WHEN 7 THEN SUBDATE(CURRENT_DATE, 2) "); |
||||||
|
sb.append(" ELSE SUBDATE(CURRENT_DATE, 1) "); |
||||||
|
sb.append("END "); |
||||||
|
sb.append("ORDER BY commodity, year ASC, month ASC "); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(sb.toString()); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getContractTree() throws Exception { |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
/*sb.append("SELECT contract,commodity as commodity FROM " + DB_NAME_TRADING + ".dbo.tblContractAllocation WHERE commodity in (SELECT commodity from " + DB_NAME_TRADINGREF + ".dbo.commodityRef) "); |
||||||
|
sb.append("AND date= "); |
||||||
|
sb.append("CASE DAYOFWEEK(SUBDATE(CURRENT_DATE, 1)) "); |
||||||
|
sb.append(" WHEN 1 THEN SUBDATE(CURRENT_DATE, 3) "); |
||||||
|
sb.append(" WHEN 7 THEN SUBDATE(CURRENT_DATE, 2) "); |
||||||
|
sb.append(" ELSE SUBDATE(CURRENT_DATE, 1) "); |
||||||
|
sb.append("END "); |
||||||
|
sb.append("ORDER BY commodity, year ASC, month ASC ");*/ |
||||||
|
|
||||||
|
sb.append("SELECT contract,commodity as commodity "); |
||||||
|
sb.append("FROM trading.dbo.tblContractAllocation "); |
||||||
|
sb.append("WHERE commodity in (SELECT commodity from tradingRef.dbo.commodityRef) "); |
||||||
|
sb.append("AND date= CASE DATEPART(w,DATEADD(DAY,1,CONVERT(date, GETDATE()))) "); |
||||||
|
sb.append("WHEN 1 THEN DATEADD(DAY,-3,CONVERT(date, GETDATE())) "); |
||||||
|
sb.append("WHEN 7 THEN DATEADD(DAY,-2,CONVERT(date, GETDATE())) "); |
||||||
|
sb.append("ELSE DATEADD(DAY,-1,CONVERT(date, GETDATE())) END "); |
||||||
|
sb.append("ORDER BY commodity, year ASC, month ASC"); |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement(sb.toString()); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/* |
||||||
|
public Vector<String> getCommodityTree() throws Exception { |
||||||
|
String query="SELECT commodity from tradingRef.commodityRef ORDER BY orderNo"; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(rs.getString("commodity")); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector<String> getCommodityTree() throws Exception { |
||||||
|
String query="SELECT commodity from " + DB_NAME_TRADINGREF + ".dbo.commodityRef ORDER BY orderNo"; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(rs.getString("commodity")); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public boolean isParent(String strategy_name) throws Exception { |
||||||
|
boolean rtn=false; |
||||||
|
|
||||||
|
String query="select * from ie_strategy where parent_strategy=?"; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ps.setString(1, strategy_name); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
|
||||||
|
if(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn=true; |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,140 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.ResultSetMetaData; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.TreeMap; |
||||||
|
|
||||||
|
import org.apache.commons.dbutils.BasicRowProcessor; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.InfrastructureDB; |
||||||
|
|
||||||
|
/** |
||||||
|
* Infrastructure MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class InfrastructureDBMariaDB extends InfrastructureDB { |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getThemes4Users(String user) throws Exception { |
||||||
|
//String query="select * from tblTeamOrganization where theme in ('bb','port','itools')";
|
||||||
|
|
||||||
|
String query="select * from tblTeamOrganization "; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ResultSetMetaData rm= rs.getMetaData(); |
||||||
|
ArrayList<String> columns=new ArrayList(); |
||||||
|
for(int i=0;i<rm.getColumnCount();i++){ |
||||||
|
String column=rm.getColumnName(i+1); |
||||||
|
columns.add(column); |
||||||
|
} |
||||||
|
TreeMap<String, String> themes=new TreeMap(); |
||||||
|
while(rs.next()){ |
||||||
|
|
||||||
|
String leter=rs.getString(user); |
||||||
|
String theme=rs.getString("theme"); |
||||||
|
if(leter!=null && !leter.trim().equals("")){ |
||||||
|
themes.put(theme, leter); |
||||||
|
} |
||||||
|
} |
||||||
|
return themes; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getTeamOrg(String themes, List hierarchy) throws Exception { |
||||||
|
//String query="select * from tblTeamOrganization where theme in ('bb','port','itools')";
|
||||||
|
|
||||||
|
String query="select * from tblTeamOrganization where theme in ("+themes+")"; |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ResultSetMetaData rm= rs.getMetaData(); |
||||||
|
ArrayList<String> columns=new ArrayList(); |
||||||
|
for(int i=0;i<rm.getColumnCount();i++){ |
||||||
|
String column=rm.getColumnName(i+1); |
||||||
|
columns.add(column); |
||||||
|
} |
||||||
|
TreeMap<String, String> usrs=new TreeMap(); |
||||||
|
while(rs.next()){ |
||||||
|
for(String user:columns){ |
||||||
|
String val=rs.getString(user); |
||||||
|
if(val!=null && !val.trim().equals("") ){ |
||||||
|
if(usrs.get(user)!=null){ |
||||||
|
String old=usrs.get(user); |
||||||
|
int oldorder=hierarchy.indexOf(old); |
||||||
|
int neworder=hierarchy.indexOf(val); |
||||||
|
if(neworder<oldorder){ |
||||||
|
usrs.put(user,val); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
usrs.put(user,val); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return usrs; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateBloomberDailyCounter(String date, int count) throws Exception { |
||||||
|
String query="INSERT INTO tblInfrastructureInfo (date, BBGDailyCounter) VALUES ("+ date +","+ count +") ON DUPLICATE KEY UPDATE BBGDailyCounter=BBGDailyCounter+" + count; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ps.execute(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List<String> getThemeByUsernameAccess(String username) throws Exception { |
||||||
|
String query="select 'thm-'+theme from tblTeamOrganization where "+username+" IN ('X','B','C'))"; |
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
ArrayList rtn=new ArrayList(); |
||||||
|
while(rs.next()){ |
||||||
|
rtn.add(new BasicRowProcessor().toMap(rs)); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public List getAccessByAppAndUsername(String application, String username) throws Exception { |
||||||
|
|
||||||
|
List al=new ArrayList(); |
||||||
|
|
||||||
|
String query="SELECT access FROM ApplicationUserAccess WHERE application=? and username=?"; |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement(query); |
||||||
|
ps.setString(1, application); |
||||||
|
ps.setString(2, username); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
while(rs.next()){ |
||||||
|
al.add(rs.getString(1)); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
ps.close(); |
||||||
|
return al; |
||||||
|
} |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,307 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.mariadb; |
||||||
|
|
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.TreeMap; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
|
||||||
|
import com.fourelementscapital.db.GeneralUtilDB; |
||||||
|
import com.fourelementscapital.db.ReferenceDB; |
||||||
|
import com.fourelementscapital.db.vo.CommodityInfo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Reference MariaDB DAO implementation |
||||||
|
*/ |
||||||
|
public class ReferenceDBMariaDB extends ReferenceDB { |
||||||
|
|
||||||
|
private Logger log=LogManager.getLogger(ReferenceDB.class.getName()); |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getComContracts() throws Exception { |
||||||
|
|
||||||
|
Statement st=this.connection().createStatement(); |
||||||
|
//ResultSet rs=st.executeQuery("select left(ltrim(name),2) as com,name from contract_info order by name,last_trade_date");
|
||||||
|
ResultSet rs=st.executeQuery("select ifnull(commodity_specify, left(ltrim(name),2)) as com,name from contract_info order by name,last_trade_date"); |
||||||
|
|
||||||
|
Vector commodity=new Vector(); |
||||||
|
TreeMap contract=new TreeMap(); |
||||||
|
while(rs.next()){ |
||||||
|
String com=rs.getString("com"); |
||||||
|
String cname=rs.getString("name"); |
||||||
|
Vector t=null; |
||||||
|
if(commodity.contains(com)){ |
||||||
|
t=(Vector)contract.get(com); |
||||||
|
}else{ |
||||||
|
t=new Vector(); |
||||||
|
contract.put(com,t); |
||||||
|
commodity.add(com); |
||||||
|
} |
||||||
|
t.add(cname); |
||||||
|
} |
||||||
|
st.close(); |
||||||
|
rs.close(); |
||||||
|
TreeMap rtn=new TreeMap(); |
||||||
|
rtn.put("commodity", commodity); |
||||||
|
rtn.put("contract", contract); |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void deleteFieldMapping(int id) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM static_field_mapping WHERE id=?"); |
||||||
|
ps.setInt(1, id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addFieldMapping(String dbfield, String bbfield) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO static_field_mapping(friendly_name, bb_fieldname) VALUES (?,?)"); |
||||||
|
ps.setString(1, dbfield); |
||||||
|
ps.setString(2, bbfield); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getFieldMapping() throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from static_field_mapping"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(GeneralUtilDB.resultsetToMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void deleteSecFieldMapping(int id) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("DELETE FROM security_static_fieldmapping WHERE id=?"); |
||||||
|
ps.setInt(1, id); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void addSecFieldMapping(String dbfield, String bbfield) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("INSERT INTO security_static_fieldmapping(friendly_name, bb_fieldname) VALUES (?,?)"); |
||||||
|
ps.setString(1, dbfield); |
||||||
|
ps.setString(2, bbfield); |
||||||
|
ps.executeUpdate(); |
||||||
|
ps.close(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getSecFieldMapping() throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from security_static_fieldmapping"); |
||||||
|
|
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//rtn.add(new BasicRowProcessor().toMap(rs));
|
||||||
|
rtn.add(GeneralUtilDB.resultsetToMap(rs)); |
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public void updateCommodity(CommodityInfo comm) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("SELECT * from commodity_info WHERE commodity=?"); |
||||||
|
ps.setString(1, comm.getCommodity()); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
String query="INSERT INTO commodity_info(bbticker,fepricesample,fetradeunit,glsample,glticker,multiplefactorbn,name,nepricesample,netradeunit,nename,sector,units,multiplefactor,commodity) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
||||||
|
if(rs.next()){ |
||||||
|
query="UPDATE commodity_info SET bbticker=?,fepricesample=?,fetradeunit=?,glsample=?,glticker=?,multiplefactorbn=?,name=?,nepricesample=?,netradeunit=?,nename=?,sector=?,units=?,multiplefactor=? WHERE commodity=?"; |
||||||
|
} |
||||||
|
ps.close(); |
||||||
|
PreparedStatement ps1=this.connection().prepareStatement(query); |
||||||
|
ps1.setString(1,comm.getBbticker()); |
||||||
|
ps1.setString(2,comm.getFepricesample()); |
||||||
|
ps1.setString(3,comm.getFetradeunit()); |
||||||
|
ps1.setString(4,comm.getGlsample()); |
||||||
|
ps1.setString(5,comm.getGlticker()); |
||||||
|
ps1.setString(6,comm.getMultiplefactorbn()); |
||||||
|
ps1.setString(7,comm.getName()); |
||||||
|
ps1.setString(8,comm.getNepricesample()); |
||||||
|
ps1.setString(9,comm.getNetradeunit()); |
||||||
|
ps1.setString(10,comm.getNename()); |
||||||
|
ps1.setString(11,comm.getSector()); |
||||||
|
ps1.setString(12,comm.getUnits()); |
||||||
|
ps1.setString(13,comm.getMultiplefactor()); |
||||||
|
ps1.setString(14,comm.getCommodity()); |
||||||
|
ps1.executeUpdate(); |
||||||
|
ps1.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getCommodityInfo(String commodity) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from commodity_info WHERE commodity=?"); |
||||||
|
ps.setString(1, commodity); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Map record=null; |
||||||
|
while(rs.next()){ |
||||||
|
//record=new BasicRowProcessor().toMap(rs);
|
||||||
|
record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
} |
||||||
|
return record; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getContractInfo(String contract) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from contract_info WHERE ltrim(name)=?"); |
||||||
|
ps.setString(1, contract.trim()); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Map record=null; |
||||||
|
while(rs.next()){ |
||||||
|
//record=new BasicRowProcessor().toMap(rs);
|
||||||
|
record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
} |
||||||
|
return record; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getSecurityInfo(String security) throws Exception { |
||||||
|
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("Select * from security_info WHERE ltrim(name)=?"); |
||||||
|
ps.setString(1, security.trim()); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Map record=null; |
||||||
|
while(rs.next()){ |
||||||
|
//record=new BasicRowProcessor().toMap(rs);
|
||||||
|
record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
} |
||||||
|
return record; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getContractBBInfo(String contract) throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps=this.connection().prepareStatement("select bb_fieldname,value from contract_info_fields where contract_id in (select id from contract_info where name=?)");
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select b.friendly_name,value from contract_info_fields as a left outer join static_field_mapping as b on a.bb_fieldname=b.bb_fieldname where a.contract_id in (select id from contract_info where name=?)"); |
||||||
|
ps.setString(1, contract); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//Map record=new BasicRowProcessor().toMap(rs);
|
||||||
|
Map record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
rtn.add(record); |
||||||
|
|
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Vector getSecurityBBInfo(String security) throws Exception { |
||||||
|
|
||||||
|
//PreparedStatement ps=this.connection().prepareStatement("select bb_fieldname,value from contract_info_fields where contract_id in (select id from contract_info where name=?)");
|
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select b.friendly_name,value,b.bb_fieldname from security_info_fields as a left outer join security_static_fieldmapping as b on a.bb_fieldname=b.bb_fieldname where a.security_id in (select id from security_info where name=?)"); |
||||||
|
ps.setString(1, security); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
Vector rtn=new Vector(); |
||||||
|
while(rs.next()){ |
||||||
|
//Map record=new BasicRowProcessor().toMap(rs);
|
||||||
|
Map record = GeneralUtilDB.resultsetToMap(rs); |
||||||
|
rtn.add(record); |
||||||
|
|
||||||
|
} |
||||||
|
return rtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Map getAllSecFieldValues(String friendlyname) throws Exception { |
||||||
|
|
||||||
|
log.debug("getAllSecFieldValue() called"); |
||||||
|
PreparedStatement ps=this.connection().prepareStatement("select a.name,b.value from security_info as a left outer join security_info_fields as b on a.id=b.security_id left outer join security_static_fieldmapping as c on c.bb_fieldname=b.bb_fieldname where c.friendly_name=?"); |
||||||
|
ps.setString(1, friendlyname); |
||||||
|
ResultSet rs=ps.executeQuery(); |
||||||
|
LinkedHashMap<String,String> rtn=new LinkedHashMap(); |
||||||
|
while(rs.next()){ |
||||||
|
String sec=rs.getString("name"); |
||||||
|
//String fname=rs.getString("friendly_name");
|
||||||
|
String fval=rs.getString("value"); |
||||||
|
rtn.put(sec, fval); |
||||||
|
/* |
||||||
|
if(fname!=null ){ |
||||||
|
Map<String,String> record=null; |
||||||
|
if(rtn.containsKey(sec)){ |
||||||
|
record=rtn.get(sec); |
||||||
|
}else{ |
||||||
|
record=new LinkedHashMap(); |
||||||
|
rtn.put(sec, record); |
||||||
|
} |
||||||
|
record.put(fname, fval); |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
//log.debug("record:"+rtn);
|
||||||
|
return rtn; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,125 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Trigger POJO (Bean) |
||||||
|
*/ |
||||||
|
public class BBSyncTrigger { |
||||||
|
|
||||||
|
public static final int HOURLY=1; |
||||||
|
public static final int WEEKLY=2; |
||||||
|
public static final int MONTHLY=3; |
||||||
|
|
||||||
|
private int synctype; |
||||||
|
|
||||||
|
private String time; |
||||||
|
private String days; |
||||||
|
private int day; |
||||||
|
private Integer week; |
||||||
|
private Integer dailyhour; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Get daily hour |
||||||
|
* @return daily hour |
||||||
|
*/ |
||||||
|
public Integer getDailyhour() { |
||||||
|
return dailyhour; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set daily hour |
||||||
|
* @param dailyhour daily hour |
||||||
|
*/ |
||||||
|
public void setDailyhour(Integer dailyhour) { |
||||||
|
this.dailyhour = dailyhour; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get week |
||||||
|
* @return week |
||||||
|
*/ |
||||||
|
public Integer getWeek() { |
||||||
|
return week; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set week |
||||||
|
* @param week week |
||||||
|
*/ |
||||||
|
public void setWeek(Integer week) { |
||||||
|
this.week = week; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get days |
||||||
|
* @return days |
||||||
|
*/ |
||||||
|
public String getDays() { |
||||||
|
return days; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set days |
||||||
|
* @param days days |
||||||
|
*/ |
||||||
|
public void setDays(String days) { |
||||||
|
this.days = days; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get sync type |
||||||
|
* @return sync type |
||||||
|
*/ |
||||||
|
public int getSynctype() { |
||||||
|
return synctype; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set sync type |
||||||
|
* @param synctype sync type |
||||||
|
*/ |
||||||
|
public void setSynctype(int synctype) { |
||||||
|
this.synctype = synctype; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get time |
||||||
|
* @return time |
||||||
|
*/ |
||||||
|
public String getTime() { |
||||||
|
return time; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set time |
||||||
|
* @param time time |
||||||
|
*/ |
||||||
|
public void setTime(String time) { |
||||||
|
this.time = time; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get day |
||||||
|
* @return day |
||||||
|
*/ |
||||||
|
public int getDay() { |
||||||
|
return day; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set day |
||||||
|
* @param day day |
||||||
|
*/ |
||||||
|
public void setDay(int day) { |
||||||
|
this.day = day; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,276 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* Commodity POJO (Bean) |
||||||
|
*/ |
||||||
|
public class CommodityInfo implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private Long id; |
||||||
|
private String bbticker; |
||||||
|
private String fepricesample; |
||||||
|
private String fetradeunit; |
||||||
|
private String glsample; |
||||||
|
private String glticker; |
||||||
|
private String multiplefactor; |
||||||
|
private String multiplefactorbn; |
||||||
|
private String name; |
||||||
|
private String nepricesample; |
||||||
|
private String netradeunit; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get multiple factor |
||||||
|
* @return multiple factor |
||||||
|
*/ |
||||||
|
public String getMultiplefactor() { |
||||||
|
return multiplefactor; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set multiple factor |
||||||
|
* @param multiplefactor multiple factor |
||||||
|
*/ |
||||||
|
public void setMultiplefactor(String multiplefactor) { |
||||||
|
this.multiplefactor = multiplefactor; |
||||||
|
} |
||||||
|
|
||||||
|
private String nename; |
||||||
|
private String sector; |
||||||
|
private String units; |
||||||
|
private String commodity; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get commodity |
||||||
|
* @return commodity |
||||||
|
*/ |
||||||
|
public String getCommodity() { |
||||||
|
return commodity; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set commodity |
||||||
|
* @param commodity commodity |
||||||
|
*/ |
||||||
|
public void setCommodity(String commodity) { |
||||||
|
this.commodity = commodity; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get id |
||||||
|
* @return id |
||||||
|
*/ |
||||||
|
public Long getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set id |
||||||
|
* @param id id |
||||||
|
*/ |
||||||
|
public void setId(Long id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get bb ticker |
||||||
|
* @return bb ticker |
||||||
|
*/ |
||||||
|
public String getBbticker() { |
||||||
|
return bbticker; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set bb ticker |
||||||
|
* @param bbticker bb ticker |
||||||
|
*/ |
||||||
|
public void setBbticker(String bbticker) { |
||||||
|
this.bbticker = bbticker; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get fe price sample |
||||||
|
* @return fe price sample |
||||||
|
*/ |
||||||
|
public String getFepricesample() { |
||||||
|
return fepricesample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set fe price sample |
||||||
|
* @param fepricesample fe price sample |
||||||
|
*/ |
||||||
|
public void setFepricesample(String fepricesample) { |
||||||
|
this.fepricesample = fepricesample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get fe trade unit |
||||||
|
* @return fe trade unit |
||||||
|
*/ |
||||||
|
public String getFetradeunit() { |
||||||
|
return fetradeunit; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set fe trade unit |
||||||
|
* @param fetradeunit fe trade unit |
||||||
|
*/ |
||||||
|
public void setFetradeunit(String fetradeunit) { |
||||||
|
this.fetradeunit = fetradeunit; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get gl sample |
||||||
|
* @return gl sample |
||||||
|
*/ |
||||||
|
public String getGlsample() { |
||||||
|
return glsample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set gl sample |
||||||
|
* @param glsample gl sample |
||||||
|
*/ |
||||||
|
public void setGlsample(String glsample) { |
||||||
|
this.glsample = glsample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get gl ticker |
||||||
|
* @return gl ticker |
||||||
|
*/ |
||||||
|
public String getGlticker() { |
||||||
|
return glticker; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set gl ticker |
||||||
|
* @param glticker gl ticker |
||||||
|
*/ |
||||||
|
public void setGlticker(String glticker) { |
||||||
|
this.glticker = glticker; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get multiple factor bn |
||||||
|
* @return multiple factor bn |
||||||
|
*/ |
||||||
|
public String getMultiplefactorbn() { |
||||||
|
return multiplefactorbn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set multiple factor bn |
||||||
|
* @param multiplefactorbn multiple factor bn |
||||||
|
*/ |
||||||
|
public void setMultiplefactorbn(String multiplefactorbn) { |
||||||
|
this.multiplefactorbn = multiplefactorbn; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get name |
||||||
|
* @return name |
||||||
|
*/ |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set name |
||||||
|
* @param name name |
||||||
|
*/ |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get ne price sample |
||||||
|
* @return ne price sample |
||||||
|
*/ |
||||||
|
public String getNepricesample() { |
||||||
|
return nepricesample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set ne price sample |
||||||
|
* @param nepricesample ne price sample |
||||||
|
*/ |
||||||
|
public void setNepricesample(String nepricesample) { |
||||||
|
this.nepricesample = nepricesample; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get ne trade unit |
||||||
|
* @return ne trade unit |
||||||
|
*/ |
||||||
|
public String getNetradeunit() { |
||||||
|
return netradeunit; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set ne trade unit |
||||||
|
* @param netradeunit ne trade unit |
||||||
|
*/ |
||||||
|
public void setNetradeunit(String netradeunit) { |
||||||
|
this.netradeunit = netradeunit; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get ne name |
||||||
|
* @return ne name |
||||||
|
*/ |
||||||
|
public String getNename() { |
||||||
|
return nename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set ne name |
||||||
|
* @param nename ne name |
||||||
|
*/ |
||||||
|
public void setNename(String nename) { |
||||||
|
this.nename = nename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get sector |
||||||
|
* @return sector |
||||||
|
*/ |
||||||
|
public String getSector() { |
||||||
|
return sector; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set sector |
||||||
|
* @param sector sector |
||||||
|
*/ |
||||||
|
public void setSector(String sector) { |
||||||
|
this.sector = sector; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get units |
||||||
|
* @return units |
||||||
|
*/ |
||||||
|
public String getUnits() { |
||||||
|
return units; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set units |
||||||
|
* @param units units |
||||||
|
*/ |
||||||
|
public void setUnits(String units) { |
||||||
|
this.units = units; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,78 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* Contract POJO (Bean) |
||||||
|
*/ |
||||||
|
public class Contract { |
||||||
|
|
||||||
|
private String name; |
||||||
|
private double value; |
||||||
|
private Date cdate; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get name |
||||||
|
* @return name |
||||||
|
*/ |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set name |
||||||
|
* @param name name |
||||||
|
*/ |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get value |
||||||
|
* @return value |
||||||
|
*/ |
||||||
|
public double getValue() { |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set value |
||||||
|
* @param value value |
||||||
|
*/ |
||||||
|
public void setValue(double value) { |
||||||
|
this.value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get cdate |
||||||
|
* @return cdate |
||||||
|
*/ |
||||||
|
public Date getCdate() { |
||||||
|
return cdate; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set cdate |
||||||
|
* @param cdate cdate |
||||||
|
*/ |
||||||
|
public void setCdate(Date cdate) { |
||||||
|
this.cdate = cdate; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Overriding toString() method |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public String toString(){ |
||||||
|
return "Name:"+this.name+", CDate:"+this.cdate+", Value:"+this.value; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,130 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Flexible field POJO (Bean) |
||||||
|
*/ |
||||||
|
public class FlexiField { |
||||||
|
|
||||||
|
public final static String TYPE_TEXTBOX ="textbox"; |
||||||
|
public final static String TYPE_DROP_DOWNLIST ="dropdown"; |
||||||
|
public final static String TYPE_CHECKBOX ="checkbox"; |
||||||
|
public final static String TYPE_RADIO ="radio"; |
||||||
|
public final static String TYPE_FREETEXT ="textarea"; |
||||||
|
public final static String TYPE_HIDDENFIED ="hidden"; |
||||||
|
|
||||||
|
public final static String TYPE_RSCRIPTEDITOR ="rscript"; |
||||||
|
public final static String TYPE_RSCRIPTEDITOR_PARAM ="rscript_param"; |
||||||
|
public final static String TYPE_RHINOSCRIPTEDITOR ="rhinoscript"; |
||||||
|
|
||||||
|
public final static String TYPE_BLOOMBERG_PLUGGIN="bloomberg_pluggin"; |
||||||
|
|
||||||
|
private long id; |
||||||
|
private String fieldlabel; |
||||||
|
private String fieldtype; |
||||||
|
private String fieldoptions; |
||||||
|
private String tablename; |
||||||
|
private String dropdowninitial; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get dropdown initial |
||||||
|
* @return dropdown initial |
||||||
|
*/ |
||||||
|
public String getDropdowninitial() { |
||||||
|
return dropdowninitial; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set dropdown initial |
||||||
|
* @param dropdowninitial dropdown initial |
||||||
|
*/ |
||||||
|
public void setDropdowninitial(String dropdowninitial) { |
||||||
|
this.dropdowninitial = dropdowninitial; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get id |
||||||
|
* @return id |
||||||
|
*/ |
||||||
|
public long getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set id |
||||||
|
* @param id id |
||||||
|
*/ |
||||||
|
public void setId(long id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field label |
||||||
|
* @return field label |
||||||
|
*/ |
||||||
|
public String getFieldlabel() { |
||||||
|
return fieldlabel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set field label |
||||||
|
* @param fieldlabel field label |
||||||
|
*/ |
||||||
|
public void setFieldlabel(String fieldlabel) { |
||||||
|
this.fieldlabel = fieldlabel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field type |
||||||
|
* @return field type |
||||||
|
*/ |
||||||
|
public String getFieldtype() { |
||||||
|
return fieldtype; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set field type |
||||||
|
* @param fieldtype field type |
||||||
|
*/ |
||||||
|
public void setFieldtype(String fieldtype) { |
||||||
|
this.fieldtype = fieldtype; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get field options |
||||||
|
* @return field options |
||||||
|
*/ |
||||||
|
public String getFieldoptions() { |
||||||
|
return fieldoptions; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set field options |
||||||
|
* @param fieldoptions field options |
||||||
|
*/ |
||||||
|
public void setFieldoptions(String fieldoptions) { |
||||||
|
this.fieldoptions = fieldoptions; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get table name |
||||||
|
* @return table name |
||||||
|
*/ |
||||||
|
public String getTablename() { |
||||||
|
return tablename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set table name |
||||||
|
* @param tablename table name |
||||||
|
*/ |
||||||
|
public void setTablename(String tablename) { |
||||||
|
this.tablename = tablename; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,87 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* Peer package POJO (Bean) |
||||||
|
*/ |
||||||
|
public class PeerPackage { |
||||||
|
|
||||||
|
private String peername; |
||||||
|
private String packagename; |
||||||
|
private String version; |
||||||
|
private Date lastchecked; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get peer name |
||||||
|
* @return peer name |
||||||
|
*/ |
||||||
|
public String getPeername() { |
||||||
|
return peername; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set peer name |
||||||
|
* @param peername peer name |
||||||
|
*/ |
||||||
|
public void setPeername(String peername) { |
||||||
|
this.peername = peername; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get package name |
||||||
|
* @return package name |
||||||
|
*/ |
||||||
|
public String getPackagename() { |
||||||
|
return packagename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set package name |
||||||
|
* @param packagename package name |
||||||
|
*/ |
||||||
|
public void setPackagename(String packagename) { |
||||||
|
this.packagename = packagename; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get version |
||||||
|
* @return version |
||||||
|
*/ |
||||||
|
public String getVersion() { |
||||||
|
return version; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set version |
||||||
|
* @param version version |
||||||
|
*/ |
||||||
|
public void setVersion(String version) { |
||||||
|
this.version = version; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get last checked |
||||||
|
* @return last checked |
||||||
|
*/ |
||||||
|
public Date getLastchecked() { |
||||||
|
return lastchecked; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set last checked |
||||||
|
* @param lastchecked last checked |
||||||
|
*/ |
||||||
|
public void setLastchecked(Date lastchecked) { |
||||||
|
this.lastchecked = lastchecked; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,136 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Trigger POJO (Bean) |
||||||
|
*/ |
||||||
|
public class SchedulerTrigger { |
||||||
|
|
||||||
|
private String exp_second; |
||||||
|
private String exp_minute; |
||||||
|
private String exp_hour; |
||||||
|
private String exp_week; |
||||||
|
private String exp_day; |
||||||
|
private String exp_month; |
||||||
|
private String inject_code; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get inject code |
||||||
|
* @return inject code |
||||||
|
*/ |
||||||
|
public String getInject_code() { |
||||||
|
return inject_code; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set inject code |
||||||
|
* @param inject_code inject code |
||||||
|
*/ |
||||||
|
public void setInject_code(String inject_code) { |
||||||
|
this.inject_code = inject_code; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp second |
||||||
|
* @return exp second |
||||||
|
*/ |
||||||
|
public String getExp_second() { |
||||||
|
return exp_second; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp second |
||||||
|
* @param exp_second exp second |
||||||
|
*/ |
||||||
|
public void setExp_second(String exp_second) { |
||||||
|
this.exp_second = exp_second; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp minute |
||||||
|
* @return exp minute |
||||||
|
*/ |
||||||
|
public String getExp_minute() { |
||||||
|
return exp_minute; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp minute |
||||||
|
* @param exp_minute exp minute |
||||||
|
*/ |
||||||
|
public void setExp_minute(String exp_minute) { |
||||||
|
this.exp_minute = exp_minute; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp hour |
||||||
|
* @return exp hour |
||||||
|
*/ |
||||||
|
public String getExp_hour() { |
||||||
|
return exp_hour; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp hour |
||||||
|
* @param exp_hour exp hour |
||||||
|
*/ |
||||||
|
public void setExp_hour(String exp_hour) { |
||||||
|
this.exp_hour = exp_hour; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp week |
||||||
|
* @return exp week |
||||||
|
*/ |
||||||
|
public String getExp_week() { |
||||||
|
return exp_week; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp week |
||||||
|
* @param exp_week exp week |
||||||
|
*/ |
||||||
|
public void setExp_week(String exp_week) { |
||||||
|
this.exp_week = exp_week; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp day |
||||||
|
* @return exp day |
||||||
|
*/ |
||||||
|
public String getExp_day() { |
||||||
|
return exp_day; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp day |
||||||
|
* @param exp_day exp day |
||||||
|
*/ |
||||||
|
public void setExp_day(String exp_day) { |
||||||
|
this.exp_day = exp_day; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get exp month |
||||||
|
* @return exp month |
||||||
|
*/ |
||||||
|
public String getExp_month() { |
||||||
|
return exp_month; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set exp month |
||||||
|
* @param exp_month exp month |
||||||
|
*/ |
||||||
|
public void setExp_month(String exp_month) { |
||||||
|
this.exp_month = exp_month; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
/** |
||||||
|
* Strategy extended from Contract POJO |
||||||
|
*/ |
||||||
|
public class Strategy extends Contract { |
||||||
|
|
||||||
|
private String svalue=null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get svalue |
||||||
|
* @return svalue |
||||||
|
*/ |
||||||
|
public String getSvalue() { |
||||||
|
return svalue; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set svalue |
||||||
|
* @param svalue svalue |
||||||
|
*/ |
||||||
|
public void setSvalue(String svalue) { |
||||||
|
this.svalue = svalue; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
/****************************************************************************** |
||||||
|
* |
||||||
|
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
******************************************************************************/ |
||||||
|
|
||||||
|
package com.fourelementscapital.db.vo; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Value object used for various purposes to handle key value peer operations |
||||||
|
*/ |
||||||
|
public class ValueObject implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private String key; |
||||||
|
private String value; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get key |
||||||
|
* @return key |
||||||
|
*/ |
||||||
|
public String getKey() { |
||||||
|
return this.key; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set key |
||||||
|
* @param key key |
||||||
|
*/ |
||||||
|
public void setKey(String key) { |
||||||
|
this.key = key; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get value |
||||||
|
* @return value |
||||||
|
*/ |
||||||
|
public String getValue() { |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set value |
||||||
|
* @param value value |
||||||
|
*/ |
||||||
|
public void setValue(String value) { |
||||||
|
this.value = value; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Overriding equals method to get uniqueness based on the key |
||||||
|
*/ |
||||||
|
public boolean equals(Object old){ |
||||||
|
ValueObject oldvo=(ValueObject)old; |
||||||
|
if(this.key!=null && oldvo.key!=null && this.key.trim().equals(oldvo.key.trim())){ |
||||||
|
return true; |
||||||
|
}else{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Overriding toString() method |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public String toString(){ |
||||||
|
return this.key; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,2 @@ |
|||||||
|
db_close_timeout=20 |
||||||
|
db_config_path=/mnt/public/Libs/.4E.config |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue