use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class JFinalJson method otherToJson.
protected String otherToJson(Object value, int depth) {
if (value instanceof Character) {
return "\"" + escape(value.toString()) + "\"";
}
if (value instanceof Model) {
Map map = com.jfinal.plugin.activerecord.CPI.getAttrs((Model) value);
return mapToJson(map, depth);
}
if (value instanceof Record) {
Map map = ((Record) value).getColumns();
return mapToJson(map, depth);
}
if (value.getClass().isArray()) {
int len = Array.getLength(value);
List<Object> list = new ArrayList<Object>(len);
for (int i = 0; i < len; i++) {
list.add(Array.get(value, i));
}
return iteratorToJson(list.iterator(), depth);
}
if (value instanceof Iterator) {
return iteratorToJson((Iterator) value, depth);
}
if (value instanceof Enumeration) {
ArrayList<?> list = Collections.list((Enumeration<?>) value);
return iteratorToJson(list.iterator(), depth);
}
if (value instanceof Enum) {
return "\"" + ((Enum) value).toString() + "\"";
}
return beanToJson(value, depth);
}
use of com.jfinal.plugin.activerecord.Record in project my_curd by qinyou.
the class SysOrgController method deleteAction.
/**
* 1: 删除当前结构和子组织机构
* 2: 当前机构和子组织机构的 人员 orgId 设置为null
*/
@Before(Tx.class)
public void deleteAction() {
Integer id = getParaToInt("id");
try {
Record record = Db.findFirst("select getChildLst(?,'sys_org') as childrenIds ", id);
// 子、孙 id
String childrenIds = record.getStr("childrenIds");
String deleteSql = "delete from sys_org where id in (" + childrenIds + ")";
Db.update(deleteSql);
String updateSql = "update sys_user set org_id = null where org_id in (" + childrenIds + ")";
Db.update(updateSql);
renderText(Constant.DELETE_SUCCESS);
} catch (ActiveRecordException e) {
renderText(Constant.DELETE_FAIL);
}
}
use of com.jfinal.plugin.activerecord.Record in project my_curd by qinyou.
the class PoiKit method processAsRecord.
private static void processAsRecord(String[] columns, HSSFRow row, Object obj) {
HSSFCell cell;
Record record = (Record) obj;
Map<String, Object> map = record.getColumns();
if (columns.length == 0) {
// 未设置显示列,默认全部
record.getColumns();
Set<String> keys = map.keySet();
int columnIndex = 0;
for (String key : keys) {
cell = row.createCell(columnIndex);
String value = "";
if (record.get(key) == null) {
value = "";
} else {
value = record.get(key).toString();
}
cell.setCellValue(value + "");
columnIndex++;
}
} else {
for (int j = 0, lenJ = columns.length; j < lenJ; j++) {
cell = row.createCell(j);
String value = "";
int values;
if (map.get(columns[j]) == null) {
value = "";
} else {
value = map.get(columns[j]).toString();
}
if (isNumeric(value)) {
// HSSFWorkbook ewb = new HSSFWorkbook();
// HSSFCellStyle cellNumStyle = ewb.createCellStyle();
// cellNumStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
// cellNumStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
}
cell.setCellValue(value);
}
}
}
use of com.jfinal.plugin.activerecord.Record in project fruit-manage by liuzhaozhao.
the class Common method recordListToSqlIn.
/**
* 将list转换为sql的in查询字符串
*
* @param resData
* @param columnName
* @return '1','2','' 没有数据时返回''
*/
public static String recordListToSqlIn(List<Record> resData, String columnName) {
StringBuffer sqlIn = new StringBuffer("'");
Iterator<Record> ite = resData.iterator();
while (ite.hasNext()) {
Record rowData = ite.next();
sqlIn.append(rowData.get(columnName) + "','");
}
sqlIn.append("'");
return sqlIn.toString();
}
use of com.jfinal.plugin.activerecord.Record in project jfinal by jfinal.
the class KeepByteAndShortRecordBuilder 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;
int t = types[i];
if (t < Types.DATE) {
if (t == Types.TINYINT) {
value = BuilderKit.getByte(rs, i);
} else if (t == Types.SMALLINT) {
value = BuilderKit.getShort(rs, i);
} else {
value = rs.getObject(i);
}
} else {
if (t == Types.TIMESTAMP) {
value = rs.getTimestamp(i);
} else if (t == Types.DATE) {
value = rs.getDate(i);
} else if (t == Types.CLOB) {
value = ModelBuilder.me.handleClob(rs.getClob(i));
} else if (t == Types.NCLOB) {
value = ModelBuilder.me.handleClob(rs.getNClob(i));
} else if (t == 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;
}
Aggregations