Created
February 1, 2011 23:45
-
-
Save dustingetz/806975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String buildUpdateSingleSql(SimpleDataCollection data, ITmfTypeInfo typeInfo, ITmfAppContext context)throws Exception | |
| { | |
| long revision = getRevisionValue(data); | |
| List<ITmfTypeFieldInfo> appFields = typeInfo.getAppSingleFields(); | |
| StringBuilder sb = new StringBuilder(2048); | |
| sb.append("UPDATE "); | |
| appendSchemaPrefix(sb); | |
| sb.append(typeInfo.getSingleTableName()); | |
| sb.append(" SET "); | |
| boolean isFirstField = true; | |
| for(ITmfTypeFieldInfo field : appFields) | |
| { | |
| if(field.isReadOnly()) | |
| { | |
| continue; | |
| } | |
| if(isFirstField) | |
| { | |
| isFirstField = false; | |
| } | |
| else | |
| { | |
| sb.append(", "); | |
| } | |
| Object value = data.fetchDataValue(field.getFieldName(), null); | |
| sb.append(field.getFieldName()).append(" = "); | |
| appendSqlValue(sb, value, field.getJavaDataType()); | |
| } | |
| sb.append(", ").append(ITmfObject.ATTR_MODIFIED_BY).append(" = ");appendSqlValue(sb, context.getUserName(), String.class); // Modified by | |
| sb.append(", ").append(ITmfObject.ATTR_MODIFIED_DATE).append(" = CURRENT_TIMESTAMP"); //modified Date | |
| sb.append(", ").append(ITmfObject.ATTR_REVISION).append(" = ").append(revision + 1); // bump the revision number to prevent overwriting deletes | |
| sb.append(" WHERE "); | |
| sb.append(ITmfObject.ATTR_ID).append(" = ");appendSqlValue(sb, data.fetchDataValue(ITmfObject.ATTR_ID, null), String.class); // ID | |
| sb.append(" AND "); | |
| sb.append(ITmfObject.ATTR_REVISION).append(" = ");appendSqlValue(sb, revision, Long.class); // ID | |
| return sb.toString(); | |
| } | |
| public static void appendSchemaPrefix(StringBuilder a) | |
| { | |
| String schema = GFRuntime.getGFRuntime().getAppDatabaseSchemaName(); | |
| if(null == schema) | |
| { | |
| return; | |
| } | |
| a.append(schema).append('.'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment