Skip to content

Commit 0784552

Browse files
committed
prepare for jfinal-1.8-SNAPSHOT
1 parent 958f2f7 commit 0784552

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/com/jfinal/core/ModelInjector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
*/
3232
final class ModelInjector {
3333

34+
@SuppressWarnings("unchecked")
3435
public static <T> T inject(Class<?> modelClass, HttpServletRequest request, boolean skipConvertError) {
3536
String modelName = modelClass.getSimpleName();
36-
return inject(modelClass, StringKit.firstCharToLowerCase(modelName), request, skipConvertError);
37+
return (T)inject(modelClass, StringKit.firstCharToLowerCase(modelName), request, skipConvertError);
3738
}
3839

3940
@SuppressWarnings({ "rawtypes", "unchecked" })

src/com/jfinal/plugin/activerecord/Db.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static <T> T queryColumn(String sql, Object... paras) {
122122
}
123123

124124
public static <T> T queryColumn(String sql) {
125-
return queryColumn(sql, NULL_PARA_ARRAY);
125+
return (T)queryColumn(sql, NULL_PARA_ARRAY);
126126
}
127127

128128
public static String queryStr(String sql, Object... paras) {

src/com/jfinal/plugin/activerecord/Model.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.sql.SQLException;
2424
import java.sql.Statement;
2525
import java.util.ArrayList;
26-
import java.util.HashMap;
27-
import java.util.HashSet;
2826
import java.util.Iterator;
2927
import java.util.List;
3028
import java.util.Map;
@@ -359,8 +357,7 @@ else if (colType == Long.class || colType == long.class)
359357
*/
360358
public boolean delete() {
361359
Table table = getTable();
362-
String pKey = table.getPrimaryKey();
363-
Object id = attrs.get(pKey);
360+
Object id = attrs.get(table.getPrimaryKey());
364361
if (id == null)
365362
throw new ActiveRecordException("You can't delete model without id.");
366363
return deleteById(table, id);
@@ -378,8 +375,17 @@ public boolean deleteById(Object id) {
378375
}
379376

380377
private boolean deleteById(Table table, Object id) {
381-
String sql = getConfig().dialect.forModelDeleteById(table);
382-
return Db.update(sql, id) >= 1;
378+
Config config = getConfig();
379+
Connection conn = null;
380+
try {
381+
conn = config.getConnection();
382+
String sql = config.dialect.forModelDeleteById(table);
383+
return Db.update(config, conn, sql, id) >= 1;
384+
} catch (Exception e) {
385+
throw new ActiveRecordException(e);
386+
} finally {
387+
config.close(conn);
388+
}
383389
}
384390

385391
/**
@@ -581,8 +587,9 @@ public M removeNullValueAttrs() {
581587
*/
582588
public M keep(String... attrs) {
583589
if (attrs != null && attrs.length > 0) {
584-
Map<String, Object> newAttrs = new HashMap<String, Object>(attrs.length);
585-
Set<String> newModifyFlag = new HashSet<String>();
590+
Config config = getConfig();
591+
Map<String, Object> newAttrs = config.containerFactory.getAttrsMap(); // new HashMap<String, Object>(attrs.length);
592+
Set<String> newModifyFlag = config.containerFactory.getModifyFlagSet(); // new HashSet<String>();
586593
for (String a : attrs) {
587594
if (this.attrs.containsKey(a)) // prevent put null value to the newColumns
588595
newAttrs.put(a, this.attrs.get(a));

src/com/jfinal/plugin/activerecord/Record.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.jfinal.plugin.activerecord;
1818

1919
import java.io.Serializable;
20-
import java.util.HashMap;
2120
import java.util.Map;
2221
import java.util.Set;
2322
import java.util.Map.Entry;
@@ -142,9 +141,10 @@ public Record removeNullValueColumns() {
142141
* Keep columns of this record and remove other columns.
143142
* @param columns the column names of the record
144143
*/
144+
@SuppressWarnings("unchecked")
145145
public Record keep(String... columns) {
146146
if (columns != null && columns.length > 0) {
147-
Map<String, Object> newColumns = new HashMap<String, Object>(columns.length);
147+
Map<String, Object> newColumns = getConfig().containerFactory.getColumnsMap(); // new HashMap<String, Object>(columns.length);
148148
for (String c : columns)
149149
if (this.columns.containsKey(c)) // prevent put null value to the newColumns
150150
newColumns.put(c, this.columns.get(c));

0 commit comments

Comments
 (0)