com.centit.support.database.jsonmaptable.SqlSvrJsonObjectDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centit-database Show documentation
Show all versions of centit-database Show documentation
数据库操作通用方法和函数,从以前的util包中分离出来,并且整合了部分sys-module中的函数
package com.centit.support.database.jsonmaptable;
import com.alibaba.fastjson.JSONArray;
import com.centit.support.database.metadata.TableInfo;
import com.centit.support.database.utils.DatabaseAccess;
import com.centit.support.database.utils.QueryUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public class SqlSvrJsonObjectDao extends GeneralJsonObjectDao {
public SqlSvrJsonObjectDao(){
}
public SqlSvrJsonObjectDao(Connection conn) {
super(conn);
}
public SqlSvrJsonObjectDao(TableInfo tableInfo) {
super(tableInfo);
}
public SqlSvrJsonObjectDao(Connection conn,TableInfo tableInfo) {
super(conn,tableInfo);
}
@Override
public JSONArray listObjectsByProperties(final Map properties,
final int startPos,final int maxSize)
throws SQLException, IOException {
TableInfo tableInfo = this.getTableInfo();
Pair q = buildFieldSqlWithFieldName(tableInfo,null);
String filter = buildFilterSql(tableInfo,null,properties.keySet());
String sql = "select " + q.getLeft() +" from " +tableInfo.getTableName();
if(StringUtils.isNotBlank(filter))
sql = sql + " where " + filter;
if(StringUtils.isNotBlank(tableInfo.getOrderBy()))
sql = sql + " order by " + tableInfo.getOrderBy();
return DatabaseAccess.findObjectsByNamedSqlAsJSON(
getConnect(),
QueryUtils.buildSqlServerLimitQuerySQL(
sql,
startPos, maxSize),
properties,
q.getRight());
}
/** 用表来模拟sequence
* create table simulate_sequence (seqname varchar(100) not null primary key,
* currvalue integer, increment integer);
*
* @param sequenceName sequenceName
* @return Long
* @throws SQLException SQLException
* @throws IOException IOException
*/
@Override
public Long getSequenceNextValue(final String sequenceName) throws SQLException, IOException {
return getSimulateSequenceNextValue(sequenceName);
}
@Override
public List