用JDBCTemplate实现的单表通用DAO,实现增删改查和统计(四)

2014-11-24 07:23:27 · 作者: · 浏览: 4
me)
|| (getAutoGeneratePK() && name.compareToIgnoreCase(getTableKey())==0)){
continue;
}
tempColumns.append(name).append(",");
tempValueHolds.append(getHoldFlag(descriptor)).append(",");
}
cache.setInsertSqlPrefix("insert into "+tableName+"("
+tempColumns.substring(0,tempColumns.length()-1)+") values ("
+tempValueHolds.substring(0,tempValueHolds.length()-1)+")");
}
{
StringBuffer tempColumns = new StringBuffer();
for (PropertyDescriptor descriptor : cache.getProperties()) {
String name = descriptor.getName();
if (!beanWrapper.isWritableProperty(name)
|| (getAutoGeneratePK() && name.compareToIgnoreCase(getTableKey())==0)){
continue;
}
tempColumns.append(name).append("=").append(getHoldFlag(descriptor)).append(",");
}
cache.setUpdateSqlPrefix("update "+tableName+" set "+tempColumns.substring(0,tempColumns.length()-1)
+" where "+tableKey+"="+getHoldFlag(cache.getKeyDescriptor()));
}
}

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getTableKey() {
return tableKey;
}

public void setTableKey(String tableKey) {
this.tableKey = tableKey;
}

public boolean getAutoGeneratePK() {
return autoGeneratePK;
}

public void setAutoGeneratePK(boolean autoGeneratePK) {
this.autoGeneratePK = autoGeneratePK;
}

public SimpleDateFormat getDateFormat() {
return dateFormat;
}

public void setDateFormat(SimpleDateFormat dateFormat) {
this.dateFormat = dateFormat;
}

public TableCache getCache() {
return cache;
}

public void setCache(TableCache cache) {
this.cache = cache;
}

public Class< > getBeanClass() {
return beanClass;
}

public void setBeanClass(Class< > beanClass) {
this.beanClass = beanClass;
}

public RowMapper getRowMapper() {
return rowMapper;
}

public void setRowMapper(RowMapper rowMapper) {
this.rowMapper = rowMapper;
}

public T setID(T instance,Object value) {
try {
cache.getKeySetMethod().invoke(instance, value);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return instance;
}


public PK getPK(T instance){
PK pkValuePk = null;
try {
pkValuePk = (PK) cache.getKeyGetMethod().invoke(instance, null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();