ソースを参照

jfinal 4.9.17 release ^_^

James 4 年 前
コミット
d873c55116
1 ファイル変更51 行追加51 行削除
  1. 51 51
      src/main/java/com/jfinal/plugin/activerecord/Record.java

+ 51 - 51
src/main/java/com/jfinal/plugin/activerecord/Record.java

@@ -32,11 +32,11 @@ import java.util.Map.Entry;
  * Record
  */
 public class Record implements IRow<Record>, Serializable {
-
+	
 	private static final long serialVersionUID = 905784513600884082L;
-
+	
 	private Map<String, Object> columns;	// = getColumnsMap();	// getConfig().containerFactory.getColumnsMap();	// new HashMap<String, Object>();
-
+	
 	/**
 	 * Set the containerFactory by configName.
 	 * Only the containerFactory of the config used by Record for getColumnsMap()
@@ -46,16 +46,16 @@ public class Record implements IRow<Record>, Serializable {
 		Config config = DbKit.getConfig(configName);
 		if (config == null)
 			throw new IllegalArgumentException("Config not found: " + configName);
-
+		
 		processColumnsMap(config);
 		return this;
 	}
-
+	
 	// 用于 RecordBuilder 中注入 Map。也可以通过调用 CPI.setColumnsMap(record, columns) 实现
 	void setColumnsMap(Map<String, Object> columns) {
 		this.columns = columns;
 	}
-
+	
 	@SuppressWarnings("unchecked")
 	private void processColumnsMap(Config config) {
 		if (columns == null || columns.size() == 0) {
@@ -66,7 +66,7 @@ public class Record implements IRow<Record>, Serializable {
 			columns.putAll(columnsOld);
 		}
 	}
-
+	
 	/**
 	 * Return columns map.
 	 */
@@ -80,7 +80,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return columns;
 	}
-
+	
 	/**
 	 * Set columns value with map.
 	 * @param columns the columns map
@@ -89,7 +89,7 @@ public class Record implements IRow<Record>, Serializable {
 		this.getColumns().putAll(columns);
 		return this;
 	}
-
+	
 	/**
 	 * Set columns value with Record.
 	 * @param record the Record object
@@ -98,7 +98,7 @@ public class Record implements IRow<Record>, Serializable {
 		getColumns().putAll(record.getColumns());
 		return this;
 	}
-
+	
 	/**
 	 * Set columns value with Model object.
 	 * @param model the Model object
@@ -107,7 +107,7 @@ public class Record implements IRow<Record>, Serializable {
 		getColumns().putAll(model._getAttrs());
 		return this;
 	}
-
+	
 	/**
 	 * Remove attribute of this record.
 	 * @param column the column name of the record
@@ -116,7 +116,7 @@ public class Record implements IRow<Record>, Serializable {
 		getColumns().remove(column);
 		return this;
 	}
-
+	
 	/**
 	 * Remove columns of this record.
 	 * @param columns the column names of the record
@@ -127,7 +127,7 @@ public class Record implements IRow<Record>, Serializable {
 				this.getColumns().remove(c);
 		return this;
 	}
-
+	
 	/**
 	 * Remove columns if it is null.
 	 */
@@ -140,7 +140,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return this;
 	}
-
+	
 	/**
 	 * Keep columns of this record and remove other columns.
 	 * @param columns the column names of the record
@@ -151,7 +151,7 @@ public class Record implements IRow<Record>, Serializable {
 			for (String c : columns)
 				if (this.getColumns().containsKey(c))	// prevent put null value to the newColumns
 					newColumns.put(c, this.getColumns().get(c));
-
+			
 			this.getColumns().clear();
 			this.getColumns().putAll(newColumns);
 		}
@@ -159,7 +159,7 @@ public class Record implements IRow<Record>, Serializable {
 			this.getColumns().clear();
 		return this;
 	}
-
+	
 	/**
 	 * Keep column of this record and remove other columns.
 	 * @param column the column names of the record
@@ -174,7 +174,7 @@ public class Record implements IRow<Record>, Serializable {
 			getColumns().clear();
 		return this;
 	}
-
+	
 	/**
 	 * Remove all columns of this record.
 	 */
@@ -182,7 +182,7 @@ public class Record implements IRow<Record>, Serializable {
 		getColumns().clear();
 		return this;
 	}
-
+	
 	/**
 	 * Set column to record.
 	 * @param column the column name
@@ -192,7 +192,7 @@ public class Record implements IRow<Record>, Serializable {
 		getColumns().put(column, value);
 		return this;
 	}
-
+	
 	/**
 	 * Get column of any mysql type
 	 */
@@ -200,7 +200,7 @@ public class Record implements IRow<Record>, Serializable {
 	public <T> T get(String column) {
 		return (T)getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of any mysql type. Returns defaultValue if null.
 	 */
@@ -209,16 +209,16 @@ public class Record implements IRow<Record>, Serializable {
 		Object result = getColumns().get(column);
 		return (T)(result != null ? result : defaultValue);
 	}
-
+	
 	public Object getObject(String column) {
 		return getColumns().get(column);
 	}
-
+	
 	public Object getObject(String column, Object defaultValue) {
 		Object result = getColumns().get(column);
 		return result != null ? result : defaultValue;
 	}
-
+	
 	/**
 	 * Get column of mysql type: varchar, char, enum, set, text, tinytext, mediumtext, longtext
 	 */
@@ -227,7 +227,7 @@ public class Record implements IRow<Record>, Serializable {
 		Object s = getColumns().get(column);
 		return s != null ? s.toString() : null;
 	}
-
+	
 	/**
 	 * Get column of mysql type: int, integer, tinyint(n) n > 1, smallint, mediumint
 	 */
@@ -235,7 +235,7 @@ public class Record implements IRow<Record>, Serializable {
 		Number n = getNumber(column);
 		return n != null ? n.intValue() : null;
 	}
-
+	
 	/**
 	 * Get column of mysql type: bigint, unsigned int
 	 */
@@ -243,20 +243,20 @@ public class Record implements IRow<Record>, Serializable {
 		Number n = getNumber(column);
 		return n != null ? n.longValue() : null;
 	}
-
+	
 	/**
 	 * Get column of mysql type: unsigned bigint
 	 */
 	public java.math.BigInteger getBigInteger(String column) {
 		return (java.math.BigInteger)getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of mysql type: date, year
 	 */
 	public java.util.Date getDate(String column) {
 		Object ret = getColumns().get(column);
-
+		
 		if (ret instanceof Temporal) {
 			if (ret instanceof LocalDateTime) {
 				return TimeKit.toDate((LocalDateTime)ret);
@@ -268,13 +268,13 @@ public class Record implements IRow<Record>, Serializable {
 				return TimeKit.toDate((LocalTime)ret);
 			}
 		}
-
+		
 		return (java.util.Date)ret;
 	}
-
+	
 	public LocalDateTime getLocalDateTime(String column) {
 		Object ret = getColumns().get(column);
-
+		
 		if (ret instanceof LocalDateTime) {
 			return (LocalDateTime)ret;
 		}
@@ -287,24 +287,24 @@ public class Record implements IRow<Record>, Serializable {
 		if (ret instanceof java.util.Date) {
 			return TimeKit.toLocalDateTime((java.util.Date)ret);
 		}
-
+		
 		return (LocalDateTime)ret;
 	}
-
+	
 	/**
 	 * Get column of mysql type: time
 	 */
 	public java.sql.Time getTime(String column) {
 		return (java.sql.Time)getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of mysql type: timestamp, datetime
 	 */
 	public java.sql.Timestamp getTimestamp(String column) {
 		return (java.sql.Timestamp)getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of mysql type: real, double
 	 */
@@ -312,7 +312,7 @@ public class Record implements IRow<Record>, Serializable {
 		Number n = getNumber(column);
 		return n != null ? n.doubleValue() : null;
 	}
-
+	
 	/**
 	 * Get column of mysql type: float
 	 */
@@ -320,24 +320,24 @@ public class Record implements IRow<Record>, Serializable {
 		Number n = getNumber(column);
 		return n != null ? n.floatValue() : null;
 	}
-
+	
 	public Short getShort(String column) {
 		Number n = getNumber(column);
 		return n != null ? n.shortValue() : null;
 	}
-
+	
 	public Byte getByte(String column) {
 		Number n = getNumber(column);
 		return n != null ? n.byteValue() : null;
 	}
-
+	
 	/**
 	 * Get column of mysql type: bit, tinyint(1)
 	 */
 	public Boolean getBoolean(String column) {
 		return (Boolean)getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of mysql type: decimal, numeric
 	 */
@@ -351,7 +351,7 @@ public class Record implements IRow<Record>, Serializable {
 			return null;
 		}
 	}
-
+	
 	/**
 	 * Get column of mysql type: binary, varbinary, tinyblob, blob, mediumblob, longblob
 	 * I have not finished the test.
@@ -359,14 +359,14 @@ public class Record implements IRow<Record>, Serializable {
 	public byte[] getBytes(String column) {
 		return (byte[])getColumns().get(column);
 	}
-
+	
 	/**
 	 * Get column of any type that extends from Number
 	 */
 	public Number getNumber(String column) {
 		return (Number)getColumns().get(column);
 	}
-
+	
 	public String toString() {
 		if (columns == null) {
 			return "{}";
@@ -389,7 +389,7 @@ public class Record implements IRow<Record>, Serializable {
 		sb.append('}');
 		return sb.toString();
 	}
-
+	
 	public boolean equals(Object o) {
 		if (!(o instanceof Record))
 			return false;
@@ -397,11 +397,11 @@ public class Record implements IRow<Record>, Serializable {
 			return true;
 		return getColumns().equals(((Record)o).getColumns());
 	}
-
+	
 	public int hashCode() {
 		return getColumns().hashCode();
 	}
-
+	
 	/**
 	 * Return column names of this record.
 	 */
@@ -409,7 +409,7 @@ public class Record implements IRow<Record>, Serializable {
 		Set<String> attrNameSet = getColumns().keySet();
 		return attrNameSet.toArray(new String[attrNameSet.size()]);
 	}
-
+	
 	/**
 	 * Return column values of this record.
 	 */
@@ -417,25 +417,25 @@ public class Record implements IRow<Record>, Serializable {
 		java.util.Collection<Object> attrValueCollection = getColumns().values();
 		return attrValueCollection.toArray(new Object[attrValueCollection.size()]);
 	}
-
+	
 	/**
 	 * Return json string of this record.
 	 */
 	public String toJson() {
 		return com.jfinal.kit.JsonKit.toJson(getColumns());
 	}
-
+	
 	@Override
 	public Map<String, Object> toMap() {
 		return getColumns();
 	}
-
+	
 	@Override
 	public Record put(Map<String, Object> map) {
 		getColumns().putAll(map);
 		return this;
 	}
-
+	
 	@Override
 	public Record put(String key, Object value) {
 		return this.set(key,value);