Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
guooscar committed Nov 11, 2015
2 parents f426828 + def5769 commit 63600ac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
29 changes: 29 additions & 0 deletions JazminServer/src/jazmin/driver/jdbc/SmartBeanDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ private String querySql(QueryTerms qt,String... excludeProperties){
return sql.toString();
}
//
private String queryCountSql(QueryTerms qt){
StringBuilder sql=new StringBuilder();
Class<?>type=getTypeClass();
String tableName="t"+convertFieldName(type.getSimpleName());
sql.append("select count(1) ");
sql.append(" from ").append(tableName);
sql.append(" where 1=1");
for(Where k:qt.wheres){
getWhereStatement(sql,k);
}
if(!qt.orderBys.isEmpty()){
sql.append(" order by ");
for(String k:qt.orderBys){
sql.append(k).append(",");
}
sql.deleteCharAt(sql.length()-1);
}
if(qt.limitEnd!=-1){
sql.append(" limit ").
append(qt.limitStart).
append(",").
append(qt.limitEnd);
}
return sql.toString();
}
//
private void getWhereStatement(StringBuilder sql,Where w){
sql.append(" and ");
sql.append("`").append(w.key).append("` ");
Expand All @@ -163,6 +189,9 @@ private void getWhereStatement(StringBuilder sql,Where w){
sql.append(" ? ");
}
}
protected int queryCount(QueryTerms qt){
return queryForInteger(queryCountSql(qt), qt.whereValues());
}
//
protected T query(QueryTerms qt,String... excludeProperties){
Class<?>type=getTypeClass();
Expand Down
30 changes: 26 additions & 4 deletions JazminServer/src/jazmin/server/web/PublicFieldELResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Object getValue(ELContext context, Object base, Object property) {
return null;
}
try {
Field field = base.getClass().getDeclaredField((String) property);
Field field = getDeclaredField(base, (String)property);
field.setAccessible(true);
Object value = field.get(base);
context.setPropertyResolved(true);
Expand All @@ -60,14 +60,36 @@ public void setValue(ELContext context, Object base, Object property,
return;
}
try {
Field field = base.getClass().getDeclaredField((String) property);
field.setAccessible(true);
field.set(base, value);
setFieldValue(base, (String) property, value);
context.setPropertyResolved(true);
} catch (NoSuchFieldException e) {
super.setValue(context,base, property,value);
}catch (Exception e) {
throw new PropertyNotFoundException(e);
}
}
//
@SuppressWarnings("unused")
public static Field getDeclaredField(Object object,String fieldName)
throws NoSuchFieldException, SecurityException{
Field field=null;
Class<?>clazz=object.getClass();
for(;clazz!=Object.class;clazz=clazz.getSuperclass()){
try{
field=clazz.getDeclaredField(fieldName);
return field;
}catch(NoSuchFieldException e){}
}
if(field==null){
throw new NoSuchFieldException(clazz+" field:"+fieldName);
}
return field;
}
//
public static void setFieldValue(Object object,String fieldName,Object value)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
Field field=getDeclaredField(object, fieldName);
field.setAccessible(true);
field.set(object, value);
}
}
12 changes: 6 additions & 6 deletions JazminServer/src/jazmin/server/web/mvc/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private String getRequired(String key,boolean required){
//
public Boolean getBoolean(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Boolean.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Boolean.valueOf(ss);
}
public Boolean getBooleanOrDefault(String key,Boolean dv){
Boolean ss=getBoolean(key);
Expand All @@ -83,7 +83,7 @@ public String getString(String key){
//
public Long getLong(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Long.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Long.valueOf(ss);
}
//
public Long getLongOrDefault(String key,Long dv){
Expand All @@ -97,7 +97,7 @@ public Long getLong(String key){
//
public Integer getInteger(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Integer.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Integer.valueOf(ss);
}
//
public Integer getIntegerOrDefault(String key,Integer dv){
Expand All @@ -111,7 +111,7 @@ public Integer getInteger(String key){
//
public Short getShort(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Short.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Short.valueOf(ss);
}
//
public Short getShort(String key){
Expand All @@ -125,7 +125,7 @@ public Short getShortOrDefault(String key,Short dv){
//
public Float getFloat(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Float.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Float.valueOf(ss);
}
//
public Float getFloat(String key){
Expand All @@ -138,7 +138,7 @@ public Float getFloatOrDefault(String key,Float dv){
//
public Double getDouble(String key,boolean required){
String ss=getRequired(key, required);
return ss==null?null:Double.valueOf(ss);
return ss==null||ss.trim().isEmpty()?null:Double.valueOf(ss);
}
//
public Double getDoubleOrDefault(String key,Double dv){
Expand Down

0 comments on commit 63600ac

Please sign in to comment.