com.enterprisemath.dao.relational.MyBatisRelationDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of em-dao Show documentation
Show all versions of em-dao Show documentation
Simple and powerful data access layer.
package com.enterprisemath.dao.relational;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.enterprisemath.dao.filter.Criterium;
import com.enterprisemath.dao.filter.Filter;
import com.enterprisemath.dao.filter.Order;
import com.enterprisemath.utils.DomainUtils;
import com.enterprisemath.utils.ValidationUtils;
/**
* Implementation of relation dao which is using my batis framework.
*
* @author radek.hecl
*
*/
public class MyBatisRelationDao implements RelationDao {
/**
* Factory for sql sessions.
*/
private SqlSessionFactory sqlSessionFactory;
/**
* Creates new instance.
*/
private MyBatisRelationDao() {
}
/**
* Guards this object to be consistent. Throws exception if this is not the case.
*/
private void guardInvariants() {
ValidationUtils.guardNotNull(sqlSessionFactory, "sqlSessionFactory cannot be null");
}
@Override
public void insertRelation(String code, String subjectCode, String objectCode, String type) {
SqlSession session = sqlSessionFactory.openSession();
try {
MyBatisRelationMapper mapper = session.getMapper(MyBatisRelationMapper.class);
mapper.insertRelation(code, subjectCode, objectCode, type);
} finally {
session.close();
}
}
@Override
public void deleteRelation(String code) {
SqlSession session = sqlSessionFactory.openSession();
try {
MyBatisRelationMapper mapper = session.getMapper(MyBatisRelationMapper.class);
mapper.deleteRelation(code);
} finally {
session.close();
}
}
@Override
public List selectRelations(Set joinsData, Filter filter) {
SqlSession session = sqlSessionFactory.openSession();
try {
MyBatisRelationMapper mapper = session.getMapper(MyBatisRelationMapper.class);
// fetch data
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy