<%@ page trimDirectiveWhitespaces="true" %>
Problem solved!
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
<%@ page trimDirectiveWhitespaces="true" %>
package org.inewsnet.ldap;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ResourceBundle;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class LdapJndi{
@SuppressWarnings("rawtypes")
Hashtable env;
DirContext ctx;
@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean connect(){
boolean bRes = true;
ResourceBundle rsBun = ResourceBundle.getBundle("LDAP");
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://" + rsBun.getString("server") + ":" +
rsBun.getString("port") + rsBun.getString("root"));
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=" + rsBun.getString("principal"));
env.put(Context.SECURITY_CREDENTIALS, rsBun.getString("credentials"));
try {
ctx = new InitialDirContext(env);
} catch (NamingException e) {
e.printStackTrace();
bRes = false;
}
return bRes;
}
public static String getCN(String cnName) {
if (cnName != null && cnName.toUpperCase().startsWith("CN=")) {
cnName = cnName.substring(3);
}
int position = cnName.indexOf(',');
if (position == -1) {
return cnName;
} else {
return cnName.substring(0, position);
}
}
public static String getUserName(String upn) {
int position = upn.indexOf('@');
return upn.substring(0, position);
}
@SuppressWarnings("rawtypes")
public boolean testNetworkRead() {
boolean bRes = false;
String firstName;
String lastName;
String userName;
ResourceBundle rsBun = ResourceBundle.getBundle("LDAP");
String bsaeOU = "ou=" + rsBun.getString("baseOU");
SearchControls sc = new SearchControls();
String[] attributeFilter = {"memberOf", "userPrincipalName", "sn", "givenName", "cn", "mail" };
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(&(sn=*)(l=*))";
try {
NamingEnumeration results = ctx.search(bsaeOU, filter, sc);
Integer iCx = 0;
while (results.hasMore()) {
SearchResult sr = (SearchResult) results.next();
Attributes attrs = sr.getAttributes();
iCx = iCx + 1;
System.out.print(iCx + ")");
Attribute attr = attrs.get("sn");
lastName = attr.get().toString();
System.out.print("ln= " + lastName);
attr = attrs.get("givenName");
if (attr != null) {
firstName = attr.get().toString();
System.out.print(" fn= " + firstName);
}
System.out.print("-");
Attribute aupn = attrs.get("userPrincipalName");
userName = getUserName(aupn.get().toString());
Attribute mattr = attrs.get("memberOf");
System.out.println(" un= " + userName + ": ");
if(mattr != null) {
//loop through the memberof attribute to get each group
for ( Enumeration e1 = mattr.getAll() ; e1.hasMoreElements() ; ) {
System.out.println(getCN(e1.nextElement().toString()));
}
}
}//end while
bRes = true;
} catch (Exception e) {
e.printStackTrace();
}
try {
ctx.close();
} catch (NamingException e) {
e.printStackTrace();
}
return bRes;
}
}
public String testLdapNetworkRead() throws Exception {
LdapJndi myCon = new LdapJndi();
try {
if(myCon.connect()) myCon.testNetworkRead();
} catch (Exception e) {
this.errorMsg = e.getMessage();
return ERROR;
}
successMsg = "Test Connect OK";
return SUCCESS;
}
#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:1111; overflow:hidden;}
#cboxOverlay{position:fixed; width:100%; height:100%;}
#cboxMiddleLeft, #cboxBottomLeft{clear:left;}
#cboxContent{position:relative;}
#cboxLoadedContent{overflow:auto;}
#cboxTitle{margin:0;}
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
.cboxPhoto{float:left; margin:auto; border:0; display:block;}
.cboxIframe{width:100%; height:100%; display:block; border:0;}
#cboxOverlay{background:#222;}
#colorbox{}
#cboxTopLeft{width:8px; height:8px; background:url(images/mborder.png) no-repeat 0 0;}
#cboxTopCenter{height:8px; background:url(images/mborder.png) repeat-x top left;}
#cboxTopRight{width:8px; height:8px; background:url(images/mborder.png) no-repeat 0 0;}
#cboxBottomLeft{width:8px; height:8px; background:url(images/mborder.png) no-repeat 0 0;}
#cboxBottomCenter{height:8px; background-color:black; background:url(images/mborder.png) repeat-x bottom left;}
#cboxBottomRight{width:8px; height:8px; background:url(images/mborder.png) no-repeat 0 0;}
#cboxMiddleLeft{width:8px; background:url(images/mborder.png) repeat-y 0 0;}
#cboxMiddleRight{width:8px; background:url(images/mborder.png) repeat-y 0 0;}
#cboxContent{background:#fff; overflow:visible;}
#cboxError{padding:50px; border:1px solid #ccc;}
#cboxLoadedContent{margin-bottom:5px;}
#cboxLoadingOverlay{background:url(images/loading_background.png) no-repeat center center;}
#cboxLoadingGraphic{background:url(images/loading.gif) no-repeat center center;}
#cboxTitle{position:absolute; bottom:-25px; left:0; text-align:center; width:100%; font-weight:bold; color:#7C7C7C;}
#cboxCurrent{position:absolute; bottom:-25px; left:58px; font-weight:bold; color:#7C7C7C;}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="KeyValueDescriptionMapper" >
<!--
author: Richard Golebiowski
Generic mapper used to return key/value information
-->
<resultMap id="ExtKeyValueMap" type="com.utilSpace.util.ExtKeyValuePair" >
<result column="ID" property="intKey" jdbcType="INTEGER" />
<result column="Value" property="value" jdbcType="VARCHAR" />
<result column="DescValue" property="descValue" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
ID, Value, DescValue
</sql>
<select id="selectByExample" resultMap="ExtKeyValueMap" parameterType="com.interbase.model.BaseExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from ${table}
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ExtKeyValueMap" parameterType="com.interbase.model.BaseExample" >
select
<include refid="Base_Column_List" />
from ${table}
where ID = #{ID,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="com.interbase.model.BaseExample" >
delete from ${table}
where ID = #{ID,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.interbase.model.BaseExample" >
delete from ${table}
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.utilSpace.util.ExtKeyValuePair" >
insert into ${table} (ID, Value, DescValue
)
values (#{ID,jdbcType=INTEGER}, #{value,jdbcType=VARCHAR}, #{descValue,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.utilSpace.util.ExtKeyValuePair" >
insert into ${table}
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="ID != null" >
ID,
</if>
<if test="value != null" >
Value,
</if>
<if test="descValue != null" >
DescValue,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="ID != null" >
#{ID,jdbcType=INTEGER},
</if>
<if test="value != null" >
#{value,jdbcType=VARCHAR},
</if>
<if test="descValue != null" >
#{descValue,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.utilSpace.util.ExtKeyValuePair" >
update ${table}
<set >
<if test="value != null" >
Value = #{value,jdbcType=VARCHAR},
</if>
<if test="descValue != null" >
DescValue = #{descValue,jdbcType=VARCHAR},
</if>
</set>
where ID = #{ID,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.utilSpace.util.ExtKeyValuePair" >
update ${table}
set Value = #{value,jdbcType=VARCHAR},
DescValue = #{descValue,jdbcType=VARCHAR}
where ID = #{ID,jdbcType=INTEGER}
</update>
<!--
Select records from the database table specified by the string parameter
-->
<select id="selectAllKeyValue" resultMap="ExtKeyValueMap" parameterType="java.lang.String">
select ID, Value from ${value}
</select>
<!--
Select records from the database table specified by the string parameter
-->
<select id="loadDescSelectList" resultMap="ExtKeyValueMap" parameterType="java.lang.String">
select ID, Value, DescValue from ${value} order by DescValue
</select>
<!--
Select records from the database table specified by the string parameter and the "Value" field returned as "DescValue"
-->
<select id="loadValueDescSelectList" resultMap="ExtKeyValueMap" parameterType="java.lang.String">
select ID, Value as DescValue from ${value} order by DescValue
</select>
<!--
Select records from the database with the field specified by the "field" property returned as "Value"
-->
<select id="loadFieldAsValue" resultMap="ExtKeyValueMap" parameterType="com.interbase.model.BaseExample">
select ID, ${field} as Value from ${table}
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<!--
Select records from the database with the field specified by the "field" property returned as "DescValue"
-->
<select id="loadFieldAsDescValue" resultMap="ExtKeyValueMap" parameterType="com.interbase.model.BaseExample">
select ID, ${field} as DescValue from ${table}
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
</mapper>
GenericDataService lstServiceTest = new GenericDataService("KeyValueDescriptionMapper");
List <ExtKeyValuePair> tstList = (List<ExtKeyValuePair>) lstServiceTest.selectAllKeyValue("luMediaType");
GenericDataService genService = new GenericDataService("KeyValueDescriptionMapper");
BaseExample baseExample = new BaseExample();
baseExample.setTable("Funder");
baseExample.setField("FunderShortName");
baseExample.setOrderByClause("FunderShortName");
List keyList = (List) genService.getFieldAsValue(baseExample);
public List getFieldAsValue(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List list = session.selectList(this.dataMapper + ".loadFieldAsValue", baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
package com.interbase.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* Basic database example class
* @author Richard Golebiowski
*
*/
public class BaseExample {
protected List oredCriteria;
protected boolean distinct;
protected String orderByClause;
protected String table;//table name
protected String field;//field name
protected String queryName;//name of the query
protected BaseCriteria baseCriteria = new BaseCriteria();
public BaseExample() {
this.oredCriteria = new ArrayList();
}
/**
* Used to clear out current criteria
*/
public void reset(){
oredCriteria = new ArrayList();
this.distinct = false;
this.orderByClause = null;
this.baseCriteria = new BaseCriteria();
}
public void resetBase() {
this.baseCriteria = new BaseCriteria();
}
public void orCriteria() {
oredCriteria.add(this.baseCriteria);
}
public void andCriterion(String condition, Object value) {
baseCriteria.addCriterion(condition, value, condition);
}
public void andCommonCriterion(String fieldName, String condition, Object value) {
if(condition.equals("begins with")) {
condition = "like";
value = value + "%";
}
else if(condition.equals("contains")){
condition = "like";
value = "%" + value + "%";
}
else if(condition.equals("ends with")){
condition = "like";
value = "%" + value;
}
else if(condition.equals("equals")){
condition = "=";
}
condition = fieldName + " " + condition;
baseCriteria.addCriterion(condition, value, condition);
}
public void andCriterion(DataViewCriteria dataViewCriteria) {
if(dataViewCriteria.getValue1() == null) {
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition());
}
else if(dataViewCriteria.getValue2() == null){
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition(), dataViewCriteria.getValue1(), dataViewCriteria.getFieldName());
}
else{
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition(), dataViewCriteria.getValue1(), dataViewCriteria.getValue2(), dataViewCriteria.getFieldName());
}
}
public void addCriterion(DataViewCriteria dataViewCriteria) {
this.baseCriteria = new BaseCriteria();
if(dataViewCriteria.getValue1() == null) {
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition());
oredCriteria.add(baseCriteria);
}
else if(dataViewCriteria.getValue2() == null){
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition(), dataViewCriteria.getValue1(), dataViewCriteria.getFieldName());
oredCriteria.add(baseCriteria);
}
else{
baseCriteria.addCriterion(dataViewCriteria.getFieldName() + " " + dataViewCriteria.getCondition(), dataViewCriteria.getValue1(), dataViewCriteria.getValue2(), dataViewCriteria.getFieldName());
oredCriteria.add(baseCriteria);
}
}
public void addCriterion(String condition, Object value) {
this.baseCriteria = new BaseCriteria();
baseCriteria.addCriterion(condition, value, condition);
oredCriteria.add(baseCriteria);
}
public void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
this.baseCriteria = new BaseCriteria();
baseCriteria.addCriterion(condition);
}
public void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
this.baseCriteria = new BaseCriteria();
baseCriteria.addCriterion(condition, value, property);
}
public void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
this.baseCriteria = new BaseCriteria();
baseCriteria.addCriterion(condition, value1, value2,property);
}
public void addCriterionForJDBCDate(String condition, Date value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value.getTime()), property);
}
public void addCriterionForJDBCDate(String condition, List values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
List dateList = new ArrayList();
Iterator iter = values.iterator();
while (iter.hasNext()) {
dateList.add(new java.sql.Date(iter.next().getTime()));
}
addCriterion(condition, dateList, property);
}
public void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);
}
public List getOredCriteria() {
return oredCriteria;
}
public void setOredCriteria(List oredCriteria) {
this.oredCriteria = oredCriteria;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getQueryName() {
return queryName;
}
public void setQueryName(String queryName) {
this.queryName = queryName;
}
public BaseCriteria getBaseCriteria() {
return baseCriteria;
}
public void setBaseCriteria(BaseCriteria baseCriteria) {
this.baseCriteria = baseCriteria;
}
}
package com.interbase.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* Basic criteria class
* @author Richard Golebiowski
*
*/
public class BaseCriteria {
protected List criteria;
public BaseCriteria() {
this.criteria = new ArrayList();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List getAllCriteria() {
return criteria;
}
public List getCriteria() {
return criteria;
}
public void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
public void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
public void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public void addCriterionForJDBCDate(String condition, Date value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value.getTime()), property);
}
public void addCriterionForJDBCDate(String condition, List values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
List dateList = new ArrayList();
Iterator iter = values.iterator();
while (iter.hasNext()) {
dateList.add(new java.sql.Date(iter.next().getTime()));
}
addCriterion(condition, dateList, property);
}
public void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);
}
}
GenericDataService genService = new GenericDataService("DataViewCriteriaMapper");
BaseExample baseExample = new BaseExample();
baseExample.addCriterion("DataViewID =", this.viewID);
//get the criteria for the view
this.lstDataViewCriteria = (List) genService.getListByExample(baseExample);
package com.dataSpace.service;
public class GenericDataService extends DataService {
public GenericDataService(String dataMapper){
this.dataMapper = dataMapper;
}
public GenericDataService() {
}
public void switchDataMapper(String dataMapper){
this.dataMapper = dataMapper;
}
}
DataService Class:
package com.dataSpace.service;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import com.interbase.mapper.MyBatisConnectionFactory_INform;
import com.interbase.model.BaseExample;
import com.utilSpace.util.ExtKeyValuePair;
import com.utilSpace.util.KeyValuePair;
public abstract class DataService {
private static final Logger logger = Logger.getLogger(DataService.class);
protected SqlSessionFactory sqlSessionFactoryINform = MyBatisConnectionFactory_INform.getSqlSessionFactory();
protected String dataMapper;
protected boolean errorFlag;
protected String errorMsg;
public List<Object> getAll(){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<Object> list = session.selectList(this.dataMapper + ".selectAll");
return list;
} finally {
session.close();
}
}
public List<KeyValuePair> getByMethod(String method){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<KeyValuePair> list = session.selectList(this.dataMapper + "." + method);
return list;
} finally {
session.close();
}
}
public List<ExtKeyValuePair> getExtByMethod(String method){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<ExtKeyValuePair> list = session.selectList(this.dataMapper + "." + method);
return list;
} finally {
session.close();
}
}
public List<?> getListByExample(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<Object> list = session.selectList(this.dataMapper + ".selectByExample", baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
this.errorFlag = true;
this.errorMsg = e.getMessage();
return null;
} finally {
session.close();
}
}
public List<?> getListFromTableByExample(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<Object> list = session.selectList(this.dataMapper + ".selectFromTableByExample", baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public List<?> getListByMethodAndExample(String method, BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<Object> list = session.selectList(this.dataMapper + "." + method, baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public Object getRecordByMethodAndExample(String method, BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
Object obj = session.selectOne(this.dataMapper + "." + method, baseExample);
return obj;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public Object getByMethodWithID(String method, Integer id){
SqlSession session = sqlSessionFactoryINform.openSession();
try {
Object obj = session.selectOne(this.dataMapper + "." + method, id);
return obj;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public Object getRecordByExample(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
this.errorFlag = false;
Object obj = session.selectOne(this.dataMapper + ".selectByExample", baseExample);
return obj;
}catch(Exception e){
this.errorFlag = true;
return null;
} finally {
session.close();
}
}
public Object getRecordByQueryExample(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
Object obj = session.selectOne(this.dataMapper + "." + baseExample.getQueryName(), baseExample);
return obj;
} finally {
session.close();
}
}
public Object getByID(Integer id){
SqlSession session = sqlSessionFactoryINform.openSession();
try {
Object obj = session.selectOne(this.dataMapper + ".selectByPrimaryKey", id);
return obj;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public void updateByID(Object obj){
SqlSession session = sqlSessionFactoryINform.openSession();
try {
session.update(this.dataMapper + ".updateByPrimaryKey", obj);
session.commit();
}catch(Exception e){
System.out.println(e.getMessage());
} finally {
session.close();
}
}
public Object insert(Object obj){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
session.insert(this.dataMapper + ".insert", obj);
session.commit();
} catch(Exception e){
System.out.println(e.getMessage());
}finally {
session.close();
}
return obj;
}
public void deleteByID(Integer id){
SqlSession session = sqlSessionFactoryINform.openSession();
try {
this.errorFlag = false;
session.delete(this.dataMapper + ".deleteByPrimaryKey", id);
session.commit();
}catch(Exception e){
this.errorFlag = true;
logger.error(e.getMessage());
} finally {
session.close();
}
}
public void deleteByExample(BaseExample baseExample){
SqlSession session = sqlSessionFactoryINform.openSession();
try {
this.errorFlag = false;
session.delete(this.dataMapper + ".deleteByExample", baseExample);
session.commit();
}catch(Exception e){
this.errorFlag = true;
logger.error(e.getMessage());
} finally {
session.close();
}
}
public List<ExtKeyValuePair> selectAllKeyValue(String source){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<ExtKeyValuePair> list = session.selectList(this.dataMapper + ".selectAllKeyValue", source);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public List<ExtKeyValuePair> getFRomTableByMethod(String source, String method){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<ExtKeyValuePair> list = session.selectList(this.dataMapper + "." + method, source);
return list;
} finally {
session.close();
}
}
/**
* Select records from the database with the field specified by the "field" property returned as "Value"
* @param baseExample
* @return
*/
public ExtKeyValuePair loadFieldAsValue(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
Object kvp = session.selectOne(this.dataMapper + ".loadFieldAsValue", baseExample);
return (ExtKeyValuePair) kvp;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
/**
* Select records from the database with the field specified by the "field" property returned as "Value"
* @param baseExample
* @return
*/
public List<ExtKeyValuePair> getFieldAsValue(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<ExtKeyValuePair> list = session.selectList(this.dataMapper + ".loadFieldAsValue", baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
/**
* Select records from the database with the field specified by the "field" property returned as "Value"
* @param baseExample
* @return
*/
public List<ExtKeyValuePair> getFieldAsDescValue(BaseExample baseExample){
SqlSession session = this.sqlSessionFactoryINform.openSession();
try {
@SuppressWarnings("unchecked")
List<ExtKeyValuePair> list = session.selectList(this.dataMapper + ".loadFieldAsDescValue", baseExample);
return list;
}catch(Exception e){
System.out.println(e.getMessage());
return null;
} finally {
session.close();
}
}
public boolean isErrorFlag() {
return errorFlag;
}
public void setErrorFlag(boolean errorFlag) {
this.errorFlag = errorFlag;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
}