Browse Source

删除 isEmpty(),避免生成 json 多出来 empty 字段

James 3 years ago
parent
commit
791b5a9f4e

+ 2 - 1
src/main/java/com/jfinal/plugin/activerecord/IRow.java

@@ -137,6 +137,7 @@ public interface IRow<M> {
      */
     public String toJson();
 
-    public boolean isEmpty();
+    // 该方法导致 Model、Record 生成 json 时多出一个 empty 字段,需要删掉
+    // public boolean isEmpty();
 }
 

File diff suppressed because it is too large
+ 149 - 154
src/main/java/com/jfinal/plugin/activerecord/Model.java


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

@@ -29,16 +29,16 @@ import com.jfinal.kit.TypeKit;
  * 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>();
-	
+
 	/**
 	 * Flag of column has been modified. update need this flag
 	 */
 	Set<String> modifyFlag;
-	
+
 	@SuppressWarnings("unchecked")
 	Set<String> _getModifyFlag() {
 		if (modifyFlag == null) {
@@ -51,13 +51,13 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return modifyFlag;
 	}
-	
+
 	void clearModifyFlag() {
 		if (modifyFlag != null) {
 			modifyFlag.clear();
 		}
 	}
-	
+
 	/**
 	 * Set the containerFactory by configName.
 	 * Only the containerFactory of the config used by Record for getColumnsMap()
@@ -68,16 +68,16 @@ public class Record implements IRow<Record>, Serializable {
 		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) {
@@ -88,7 +88,7 @@ public class Record implements IRow<Record>, Serializable {
 			columns.putAll(columnsOld);
 		}
 	}
-	
+
 	/**
 	 * Return columns map.
 	 */
@@ -103,7 +103,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return columns;
 	}
-	
+
 	/**
 	 * Set columns value with map.
 	 * @param columns the columns map
@@ -114,7 +114,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return this;
 	}
-	
+
 	/**
 	 * Set columns value with Record.
 	 * @param record the Record object
@@ -122,7 +122,7 @@ public class Record implements IRow<Record>, Serializable {
 	public Record setColumns(Record record) {
 		return setColumns(record.getColumns());
 	}
-	
+
 	/**
 	 * Set columns value with Model object.
 	 * @param model the Model object
@@ -130,7 +130,7 @@ public class Record implements IRow<Record>, Serializable {
 	public Record setColumns(Model<?> model) {
 		return setColumns(model._getAttrs());
 	}
-	
+
 	/**
 	 * Remove attribute of this record.
 	 * @param column the column name of the record
@@ -140,7 +140,7 @@ public class Record implements IRow<Record>, Serializable {
 		_getModifyFlag().remove(column);
 		return this;
 	}
-	
+
 	/**
 	 * Remove columns of this record.
 	 * @param columns the column names of the record
@@ -154,7 +154,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return this;
 	}
-	
+
 	/**
 	 * Remove columns if it is null.
 	 */
@@ -168,7 +168,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
@@ -197,7 +197,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return this;
 	}
-	
+
 	/**
 	 * Keep column of this record and remove other columns.
 	 * @param column the column names of the record
@@ -207,7 +207,7 @@ public class Record implements IRow<Record>, Serializable {
 			Object keepIt = getColumns().get(column);
 			getColumns().clear();
 			getColumns().put(column, keepIt);
-			
+
 			boolean keepFlag = _getModifyFlag().contains(column);
 			clearModifyFlag();
 			if (keepFlag) {
@@ -220,7 +220,7 @@ public class Record implements IRow<Record>, Serializable {
 		}
 		return this;
 	}
-	
+
 	/**
 	 * Remove all columns of this record.
 	 */
@@ -229,7 +229,7 @@ public class Record implements IRow<Record>, Serializable {
 		clearModifyFlag();
 		return this;
 	}
-	
+
 	/**
 	 * Set column to record.
 	 * @param column the column name
@@ -240,7 +240,7 @@ public class Record implements IRow<Record>, Serializable {
 		_getModifyFlag().add(column);	// Add modify flag, update() need this flag.
 		return this;
 	}
-	
+
 	/**
 	 * Get column of any mysql type
 	 */
@@ -248,7 +248,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.
 	 */
@@ -257,16 +257,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
 	 */
@@ -275,7 +275,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
 	 */
@@ -284,7 +284,7 @@ public class Record implements IRow<Record>, Serializable {
 		// return n != null ? n.intValue() : null;
 		return TypeKit.toInt(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: bigint, unsigned int
 	 */
@@ -293,7 +293,7 @@ public class Record implements IRow<Record>, Serializable {
 		// return n != null ? n.longValue() : null;
 		return TypeKit.toLong(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: unsigned bigint
 	 */
@@ -316,32 +316,32 @@ public class Record implements IRow<Record>, Serializable {
 
 		return (BigInteger)n;
 	}
-	
+
 	/**
 	 * Get column of mysql type: date, year
 	 */
 	public java.util.Date getDate(String column) {
 		return TypeKit.toDate(getColumns().get(column));
 	}
-	
+
 	public LocalDateTime getLocalDateTime(String column) {
 		return TypeKit.toLocalDateTime(getColumns().get(column));
 	}
-	
+
 	/**
 	 * 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
 	 */
@@ -350,7 +350,7 @@ public class Record implements IRow<Record>, Serializable {
 		// return n != null ? n.doubleValue() : null;
 		return TypeKit.toDouble(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: float
 	 */
@@ -359,19 +359,19 @@ public class Record implements IRow<Record>, Serializable {
 		// return n != null ? n.floatValue() : null;
 		return TypeKit.toFloat(getColumns().get(column));
 	}
-	
+
 	public Short getShort(String column) {
 		// Number n = getNumber(column);
 		// return n != null ? n.shortValue() : null;
 		return TypeKit.toShort(getColumns().get(column));
 	}
-	
+
 	public Byte getByte(String column) {
 		// Number n = getNumber(column);
 		// return n != null ? n.byteValue() : null;
 		return TypeKit.toByte(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: bit, tinyint(1)
 	 */
@@ -379,14 +379,14 @@ public class Record implements IRow<Record>, Serializable {
 		// return (Boolean)getColumns().get(column);
 		return TypeKit.toBoolean(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: decimal, numeric
 	 */
 	public BigDecimal getBigDecimal(String column) {
 		return TypeKit.toBigDecimal(getColumns().get(column));
 	}
-	
+
 	/**
 	 * Get column of mysql type: binary, varbinary, tinyblob, blob, mediumblob, longblob
 	 * I have not finished the test.
@@ -394,7 +394,7 @@ 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
 	 */
@@ -402,7 +402,7 @@ public class Record implements IRow<Record>, Serializable {
 		// return (Number)getColumns().get(column);
 		return TypeKit.toNumber(getColumns().get(column));
 	}
-	
+
 	public String toString() {
 		if (columns == null) {
 			return "{}";
@@ -425,7 +425,7 @@ public class Record implements IRow<Record>, Serializable {
 		sb.append('}');
 		return sb.toString();
 	}
-	
+
 	public boolean equals(Object o) {
 		if (!(o instanceof Record))
 			return false;
@@ -433,11 +433,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.
 	 */
@@ -445,7 +445,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.
 	 */
@@ -453,35 +453,30 @@ 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) {
 		getColumns().put(key, value);
 		return this;
 	}
-	
-	@Override
-	public boolean isEmpty() {
-		return columns == null || columns.isEmpty();
-	}
 }