use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class TimestampProcessedRecordBuilder method build.
@Override
@SuppressWarnings("unchecked")
public List<Record> build(Config config, ResultSet rs, Function<Record, Boolean> func) throws SQLException {
List<Record> result = new ArrayList<Record>();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String[] labelNames = new String[columnCount + 1];
int[] types = new int[columnCount + 1];
buildLabelNamesAndTypes(rsmd, labelNames, types);
while (rs.next()) {
Record record = new Record();
CPI.setColumnsMap(record, config.getContainerFactory().getColumnsMap());
Map<String, Object> columns = record.getColumns();
for (int i = 1; i <= columnCount; i++) {
Object value;
if (types[i] < Types.DATE) {
value = rs.getObject(i);
} else {
if (types[i] == Types.TIMESTAMP) {
value = rs.getTimestamp(i);
} else if (types[i] == Types.DATE) {
value = rs.getDate(i);
} else if (types[i] == Types.CLOB) {
value = ModelBuilder.me.handleClob(rs.getClob(i));
} else if (types[i] == Types.NCLOB) {
value = ModelBuilder.me.handleClob(rs.getNClob(i));
} else if (types[i] == Types.BLOB) {
value = ModelBuilder.me.handleBlob(rs.getBlob(i));
} else {
value = rs.getObject(i);
}
}
columns.put(labelNames[i], value);
}
if (func == null) {
result.add(record);
} else {
if (!func.apply(record)) {
break;
}
}
}
return result;
}
use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class AnsiSqlDialect method takeOverDbPaginate.
@SuppressWarnings("rawtypes")
public Page<Record> takeOverDbPaginate(Connection conn, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, Object... paras) throws SQLException {
// String totalRowSql = "select count(*) " + replaceOrderBy(sqlExceptSelect);
List result = CPI.query(conn, totalRowSql, paras);
int size = result.size();
if (isGroupBySql == null) {
isGroupBySql = size > 1;
}
long totalRow;
if (isGroupBySql) {
totalRow = size;
} else {
totalRow = (size > 0) ? ((Number) result.get(0)).longValue() : 0;
}
if (totalRow == 0) {
return new Page<Record>(new ArrayList<Record>(0), pageNumber, pageSize, 0, 0);
}
int totalPage = (int) (totalRow / pageSize);
if (totalRow % pageSize != 0) {
totalPage++;
}
if (pageNumber > totalPage) {
return new Page<Record>(new ArrayList<Record>(0), pageNumber, pageSize, totalPage, (int) totalRow);
}
// StringBuilder sql = new StringBuilder();
// sql.append(select).append(" ").append(sqlExceptSelect);
PreparedStatement pst = conn.prepareStatement(findSql.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
for (int i = 0; i < paras.length; i++) {
pst.setObject(i + 1, paras[i]);
}
ResultSet rs = pst.executeQuery();
// move the cursor to the start
int offset = pageSize * (pageNumber - 1);
for (int i = 0; i < offset; i++) {
if (!rs.next()) {
break;
}
}
List<Record> list = buildRecord(rs, pageSize);
if (rs != null)
rs.close();
if (pst != null)
pst.close();
return new Page<Record>(list, pageNumber, pageSize, totalPage, (int) totalRow);
}
use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class AnsiSqlDialect method buildRecord.
private List<Record> buildRecord(ResultSet rs, int pageSize) throws SQLException {
List<Record> result = new ArrayList<Record>();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String[] labelNames = new String[columnCount + 1];
int[] types = new int[columnCount + 1];
buildLabelNamesAndTypes(rsmd, labelNames, types);
for (int k = 0; k < pageSize && rs.next(); k++) {
Record record = new Record();
Map<String, Object> columns = record.getColumns();
for (int i = 1; i <= columnCount; i++) {
Object value;
if (types[i] < Types.BLOB) {
value = rs.getObject(i);
} else if (types[i] == Types.CLOB) {
value = ModelBuilder.me.handleClob(rs.getClob(i));
} else if (types[i] == Types.NCLOB) {
value = ModelBuilder.me.handleClob(rs.getNClob(i));
} else if (types[i] == Types.BLOB) {
value = ModelBuilder.me.handleBlob(rs.getBlob(i));
} else {
value = rs.getObject(i);
}
columns.put(labelNames[i], value);
}
result.add(record);
}
return result;
}
use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class FastJsonRecordSerializer method write.
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
if (object != null) {
Record record = (Record) object;
serializer.write(record.getColumns());
}
}
Aggregations