浏览代码

prepare for jfinal-1.8-SNAPSHOT

James 11 年之前
父节点
当前提交
0784552da1

+ 2 - 1
src/com/jfinal/core/ModelInjector.java

@@ -31,9 +31,10 @@ import com.jfinal.plugin.activerecord.TableMapping;
  */
 final class ModelInjector {
 	
+	@SuppressWarnings("unchecked")
 	public static <T> T inject(Class<?> modelClass, HttpServletRequest request, boolean skipConvertError) {
 		String modelName = modelClass.getSimpleName();
-		return inject(modelClass, StringKit.firstCharToLowerCase(modelName), request, skipConvertError);
+		return (T)inject(modelClass, StringKit.firstCharToLowerCase(modelName), request, skipConvertError);
 	}
 	
 	@SuppressWarnings({ "rawtypes", "unchecked" })

+ 1 - 1
src/com/jfinal/plugin/activerecord/Db.java

@@ -122,7 +122,7 @@ public class Db {
 	}
 	
 	public static <T> T queryColumn(String sql) {
-		return queryColumn(sql, NULL_PARA_ARRAY);
+		return (T)queryColumn(sql, NULL_PARA_ARRAY);
 	}
 	
 	public static String queryStr(String sql, Object... paras) {

+ 15 - 8
src/com/jfinal/plugin/activerecord/Model.java

@@ -23,8 +23,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -359,8 +357,7 @@ public abstract class Model<M extends Model> implements Serializable {
 	 */
 	public boolean delete() {
 		Table table = getTable();
-		String pKey = table.getPrimaryKey();
-		Object id = attrs.get(pKey);
+		Object id = attrs.get(table.getPrimaryKey());
 		if (id == null)
 			throw new ActiveRecordException("You can't delete model without id.");
 		return deleteById(table, id);
@@ -378,8 +375,17 @@ public abstract class Model<M extends Model> implements Serializable {
 	}
 	
 	private boolean deleteById(Table table, Object id) {
-		String sql = getConfig().dialect.forModelDeleteById(table);
-		return Db.update(sql, id) >= 1;
+		Config config = getConfig();
+		Connection conn = null;
+		try {
+			conn = config.getConnection();
+			String sql = config.dialect.forModelDeleteById(table);
+			return Db.update(config, conn, sql, id) >= 1;
+		} catch (Exception e) {
+			throw new ActiveRecordException(e);
+		} finally {
+			config.close(conn);
+		}
 	}
 	
 	/**
@@ -581,8 +587,9 @@ public abstract class Model<M extends Model> implements Serializable {
 	 */
 	public M keep(String... attrs) {
 		if (attrs != null && attrs.length > 0) {
-			Map<String, Object> newAttrs = new HashMap<String, Object>(attrs.length);
-			Set<String> newModifyFlag = new HashSet<String>();
+			Config config = getConfig();
+			Map<String, Object> newAttrs = config.containerFactory.getAttrsMap();	// new HashMap<String, Object>(attrs.length);
+			Set<String> newModifyFlag = config.containerFactory.getModifyFlagSet();	// new HashSet<String>();
 			for (String a : attrs) {
 				if (this.attrs.containsKey(a))	// prevent put null value to the newColumns
 					newAttrs.put(a, this.attrs.get(a));

+ 2 - 2
src/com/jfinal/plugin/activerecord/Record.java

@@ -17,7 +17,6 @@
 package com.jfinal.plugin.activerecord;
 
 import java.io.Serializable;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
@@ -142,9 +141,10 @@ public class Record implements Serializable {
 	 * Keep columns of this record and remove other columns.
 	 * @param columns the column names of the record
 	 */
+	@SuppressWarnings("unchecked")
 	public Record keep(String... columns) {
 		if (columns != null && columns.length > 0) {
-			Map<String, Object> newColumns = new HashMap<String, Object>(columns.length);
+			Map<String, Object> newColumns = getConfig().containerFactory.getColumnsMap();	// new HashMap<String, Object>(columns.length);
 			for (String c : columns)
 				if (this.columns.containsKey(c))	// prevent put null value to the newColumns
 					newColumns.put(c, this.columns.get(c));