Browse Source

jfinal 2.1 release ^_^

James 10 years ago
parent
commit
c3ed47ae38

+ 1 - 1
src/com/jfinal/config/Constants.java

@@ -349,7 +349,7 @@ final public class Constants {
 	}
 	
 	/**
-	 * 置 devMode 之下的 action report 是否在 invocation 之后,默认值为 true
+	 * 置 devMode 之下的 action report 是否在 invocation 之后,默认值为 true
 	 */
 	public void setReportAfterInvocation(boolean reportAfterInvocation) {
 		ActionReporter.setReportAfterInvocation(reportAfterInvocation);

+ 2 - 1
src/com/jfinal/config/JFinalConfig.java

@@ -112,8 +112,9 @@ public abstract class JFinalConfig {
 	}
 	
 	private Prop getProp() {
-		if (prop == null)
+		if (prop == null) {
 			throw new IllegalStateException("Load propties file by invoking loadPropertyFile(String fileName) method first.");
+		}
 		return prop;
 	}
 	

+ 12 - 2
src/com/jfinal/config/Routes.java

@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import com.jfinal.core.Controller;
+import com.jfinal.kit.StrKit;
 
 /**
  * Routes.
@@ -40,8 +41,17 @@ public abstract class Routes {
 	public Routes add(Routes routes) {
 		if (routes != null) {
 			routes.config();	// very important!!!
-			map.putAll(routes.map);
-			viewPathMap.putAll(routes.viewPathMap);
+			
+			for (Entry<String, Class<? extends Controller>> e : routes.map.entrySet()) {
+				String controllerKey = e.getKey();
+				Class<? extends Controller> controllerClass = e.getValue();
+				String viewPath = routes.getViewPath(controllerKey);
+				if (StrKit.notBlank(viewPath)) {
+					add(controllerKey, controllerClass, viewPath);
+				} else {
+					add(controllerKey, controllerClass);
+				}
+			}
 		}
 		return this;
 	}

+ 36 - 15
src/com/jfinal/core/Injector.java

@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import javax.servlet.http.HttpServletRequest;
 import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.ActiveRecordException;
 import com.jfinal.plugin.activerecord.Model;
 import com.jfinal.plugin.activerecord.Table;
 import com.jfinal.plugin.activerecord.TableMapping;
@@ -91,23 +92,43 @@ public class Injector {
 		}
 		
 		Model<?> model = (Model<?>)temp;
-		String modelNameAndDot = StrKit.notBlank(modelName) ? modelName + "." : null;
-		
 		Table table = TableMapping.me().getTable(model.getClass());
+		if (table == null) {
+			throw new ActiveRecordException("The Table mapping of model: " + modelClass.getName() + 
+					" not exists or the ActiveRecordPlugin not start.");
+		}
+		
+		String modelNameAndDot = StrKit.notBlank(modelName) ? modelName + "." : null;
 		Map<String, String[]> parasMap = request.getParameterMap();
-		for (Entry<String, Class<?>> entry : table.getColumnTypeMapEntrySet()) {
-			String attrName = entry.getKey();
-			String paraName = modelNameAndDot != null ? modelNameAndDot + attrName : attrName;
-			if (parasMap.containsKey(paraName)) {
-				try {
-					Class<?> colType = entry.getValue();
-					String paraValue = request.getParameter(paraName);
-					Object value = paraValue != null ? TypeConverter.convert(colType, paraValue) : null;
-					model.set(attrName, value);
-				} catch (Exception e) {
-					if (skipConvertError == false) {
-						throw new RuntimeException("Can not convert parameter: " + paraName, e);
-					}
+		// 对 paraMap进行遍历而不是对table.getColumnTypeMapEntrySet()进行遍历,以便支持 CaseInsensitiveContainerFactory
+		// 以及支持界面的 attrName有误时可以感知并抛出异常避免出错
+		for (Entry<String, String[]> entry : parasMap.entrySet()) {
+			String paraName = entry.getKey();
+			String attrName;
+			if (modelNameAndDot != null) {
+				if (paraName.startsWith(modelNameAndDot)) {
+					attrName = paraName.substring(modelNameAndDot.length());
+				} else {
+					continue ;
+				}
+			} else {
+				attrName = paraName;
+			}
+			
+			try {
+				Class<?> colType = table.getColumnType(attrName);
+				if (colType == null) {
+					throw new ActiveRecordException("The model attribute " + attrName + " is not exists.");
+				}
+				
+				String[] paraValueArray = entry.getValue();
+				String paraValue = (paraValueArray != null && paraValueArray.length > 0) ? paraValueArray[0] : null;
+				
+				Object value = paraValue != null ? TypeConverter.convert(colType, paraValue) : null;
+				model.set(attrName, value);
+			} catch (Exception e) {
+				if (skipConvertError == false) {
+					throw new RuntimeException("Can not convert parameter: " + paraName, e);
 				}
 			}
 		}

+ 2 - 2
src/com/jfinal/ext/render/CaptchaRender.java

@@ -61,8 +61,8 @@ public class CaptchaRender extends Render {
 		try {
 			// try catch 用来兼容不支持 httpOnly 的 tomcat、jetty
 			cookie.setHttpOnly(true);
-		} catch (Throwable t) {
-			LogKit.logNothing(t);
+		} catch (Exception e) {
+			LogKit.logNothing(e);
 		}
 		response.addCookie(cookie);
 		response.setHeader("Pragma","no-cache");

+ 1 - 1
src/com/jfinal/json/FastJson.java

@@ -24,7 +24,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
  */
 public class FastJson extends Json {
 	
-	public static Json getJson() {
+	public static FastJson getJson() {
 		return new FastJson();
 	}
 	

+ 1 - 1
src/com/jfinal/json/JFinalJson.java

@@ -81,7 +81,7 @@ public class JFinalJson extends Json {
 		return this;
 	}
 	
-	public static Json getJson() {
+	public static JFinalJson getJson() {
 		return new JFinalJson();
 	}
 	

+ 1 - 1
src/com/jfinal/json/Jackson.java

@@ -59,7 +59,7 @@ public class Jackson extends Json {
 		return objectMapper;
 	}
 	
-	public static Json getJson() {
+	public static Jackson getJson() {
 		return new Jackson();
 	}
 	

+ 2 - 2
src/com/jfinal/log/JdkLog.java

@@ -36,11 +36,11 @@ public class JdkLog extends Log {
 		clazzName = name;
 	}
 	
-	public static Log getLog(Class<?> clazz) {
+	public static JdkLog getLog(Class<?> clazz) {
 		return new JdkLog(clazz);
 	}
 	
-	public static Log getLog(String name) {
+	public static JdkLog getLog(String name) {
 		return new JdkLog(name);
 	}
 	

+ 2 - 2
src/com/jfinal/log/Log4jLog.java

@@ -34,11 +34,11 @@ public class Log4jLog extends Log {
 		log = org.apache.log4j.Logger.getLogger(name);
 	}
 	
-	public static Log getLog(Class<?> clazz) {
+	public static Log4jLog getLog(Class<?> clazz) {
 		return new Log4jLog(clazz);
 	}
 	
-	public static Log getLog(String name) {
+	public static Log4jLog getLog(String name) {
 		return new Log4jLog(name);
 	}
 	

+ 28 - 37
src/com/jfinal/plugin/activerecord/CaseInsensitiveContainerFactory.java

@@ -17,15 +17,17 @@
 package com.jfinal.plugin.activerecord;
 
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
+/**
+ * CaseInsensitiveContainerFactory.
+ */
 public class CaseInsensitiveContainerFactory implements IContainerFactory {
 	
-	private static boolean toLowerCase = false;
+	private static Boolean toLowerCase = null;
 	
 	public CaseInsensitiveContainerFactory() {
 	}
@@ -35,22 +37,23 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
 	}
 	
 	public Map<String, Object> getAttrsMap() {
-		return new CaseInsensitiveMap();
+		return new CaseInsensitiveMap<Object>();
 	}
 	
 	public Map<String, Object> getColumnsMap() {
-		return new CaseInsensitiveMap();
+		return new CaseInsensitiveMap<Object>();
 	}
 	
 	public Set<String> getModifyFlagSet() {
 		return new CaseInsensitiveSet();
 	}
 	
-	private static Object convertCase(Object key) {
-		if (key instanceof String) {
-			return toLowerCase ? ((String)key).toLowerCase() : ((String)key).toUpperCase();
+	private static String convertCase(String key) {
+		if (toLowerCase != null) {
+			return toLowerCase ? key.toLowerCase() : key.toUpperCase();
+		} else {
+			return key;
 		}
-		return key;
 	}
 	
 	/*
@@ -60,25 +63,21 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
 	 * 3:外部类CaseInsensitiveContainerFactory 需要 implements Serializable 才能被序列化
 	 * 4:可以使用静态内部类来实现内部类的序列化,而非让外部类实现 implements Serializable 
 	 */
-	public static class CaseInsensitiveSet extends HashSet {
-		
-		private static final long serialVersionUID = 102410961064096233L;
+	public static class CaseInsensitiveSet extends TreeSet<String> {
 		
-		public boolean add(Object e) {
-			return super.add(convertCase(e));
-		}
+		private static final long serialVersionUID = 6236541338642353211L;
 		
-		public boolean remove(Object e) {
-			return super.remove(convertCase(e));
+		public CaseInsensitiveSet() {
+			super(String.CASE_INSENSITIVE_ORDER);
 		}
 		
-		public boolean contains(Object e) {
-			return super.contains(convertCase(e));
+		public boolean add(String e) {
+			return super.add(convertCase(e));
 		}
 		
-		public boolean addAll(Collection c) {
+		public boolean addAll(Collection<? extends String> c) {
 			boolean modified = false;
-			for (Object o : c) {
+			for (String o : c) {
 				if (super.add(convertCase(o))) {
 					modified = true;
 				}
@@ -87,31 +86,23 @@ public class CaseInsensitiveContainerFactory implements IContainerFactory {
 		}
 	}
 	
-	public static class CaseInsensitiveMap extends HashMap {
-		
-		private static final long serialVersionUID = 6843981594457576677L;
+	public static class CaseInsensitiveMap<V> extends TreeMap<String, V> {
 		
-		public Object get(Object key) {
-			return super.get(convertCase(key));
-		}
+		private static final long serialVersionUID = 7482853823611007217L;
 		
-		public boolean containsKey(Object key) {
-			return super.containsKey(convertCase(key));
+		public CaseInsensitiveMap() {
+			super(String.CASE_INSENSITIVE_ORDER);
 		}
 		
-		public Object put(Object key, Object value) {
+		public V put(String key, V value) {
 			return super.put(convertCase(key), value);
 		}
 		
-		public void putAll(Map m) {
-			for (Map.Entry e : (Set<Map.Entry>)(m.entrySet())) {
+		public void putAll(Map<? extends String, ? extends V> map) {
+			for (Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
 				super.put(convertCase(e.getKey()), e.getValue());
 			}
 		}
-		
-		public Object remove(Object key) {
-			return super.remove(convertCase(key));
-		}
 	}
 }
 

+ 4 - 2
src/com/jfinal/plugin/activerecord/dialect/Dialect.java

@@ -114,12 +114,14 @@ public abstract class Dialect {
 	protected static class Holder {
 		// "order\\s+by\\s+[^,\\s]+(\\s+asc|\\s+desc)?(\\s*,\\s*[^,\\s]+(\\s+asc|\\s+desc)?)*";
 		private static final Pattern ORDER_BY_PATTERN = Pattern.compile(
-			"order\\s+by\\s+[^,\\)\\s]+(\\s+asc|\\s+desc)?(\\s*,\\s*[^,\\)\\s]+(\\s+asc|\\s+desc)?)*",
+			"order\\s+by\\s+[^,\\s]+(\\s+asc|\\s+desc)?(\\s*,\\s*[^,\\s]+(\\s+asc|\\s+desc)?)*",
 			Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
 		
 		// "(^\\s*select\\s+[\\s\\S]+?(\\s+|\\)))from\\b";
+		// "(^\\s*select\\s+(\\s*\\S*\\([\\s\\S]+\\)\\s*as\\s+\\S+|\\s*\\S+(\\s+as\\s+\\S+)?)+?\\s*)from"
 		private static final Pattern SELECT_PATTERN = Pattern.compile(
-			"(^\\s*select\\s+[\\s\\S]+?(\\s+|\\)))from",
+			// "(^\\s*select\\s+[\\s\\S]+?(\\s+|\\)))from",
+			"(^\\s*select\\s+(\\s*\\S*\\([\\s\\S]+\\)\\s*as\\s+\\S+|\\s*\\S+(\\s+as\\s+\\S+)?)+?\\s*)from",
 			Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
 		
 		private static final Pattern GROUP_BY_PATTERN = Pattern.compile(

+ 2 - 1
src/com/jfinal/plugin/activerecord/generator/Generator.java

@@ -147,8 +147,9 @@ public class Generator {
 	 * 设置是否在 Model 中生成 dao 对象,默认生成
 	 */
 	public void setGenerateDaoInModel(boolean generateDaoInModel) {
-		if (modelGenerator != null)
+		if (modelGenerator != null) {
 			modelGenerator.setGenerateDaoInModel(generateDaoInModel);
+		}
 	}
 	
 	/**

+ 5 - 1
src/com/jfinal/plugin/activerecord/generator/MetaBuilder.java

@@ -107,7 +107,8 @@ public class MetaBuilder {
 	}
 	
 	protected void buildTableNames(List<TableMeta> ret) throws SQLException {
-		ResultSet rs = dbMeta.getTables(conn.getCatalog(), null, null, new String[]{"TABLE", "VIEW"});
+		String userName = dialect.isOracle() ? dbMeta.getUserName() : null;
+		ResultSet rs = dbMeta.getTables(conn.getCatalog(), userName, null, new String[]{"TABLE", "VIEW"});
 		while (rs.next()) {
 			String tableName = rs.getString("TABLE_NAME");
 			
@@ -128,6 +129,9 @@ public class MetaBuilder {
 						}
 					}
 				}
+				if (dialect.isOracle()) {
+					tableName = tableName.toLowerCase();
+				}
 				tableMeta.modelName = StrKit.firstCharToUpperCase(StrKit.toCamelCase(tableName));
 				tableMeta.baseModelName = "Base" + tableMeta.modelName;
 				ret.add(tableMeta);

+ 2 - 2
src/com/jfinal/render/CaptchaRender.java

@@ -69,8 +69,8 @@ public class CaptchaRender extends Render {
 		try {
 			// try catch 用来兼容不支持 httpOnly 的 tomcat、jetty
 			cookie.setHttpOnly(true);
-		} catch (Throwable t) {
-			LogKit.logNothing(t);
+		} catch (Exception e) {
+			LogKit.logNothing(e);
 		}
 		response.addCookie(cookie);
 		response.setHeader("Pragma","no-cache");