1 package org.apache.ojb.broker.accesslayer.sql; 2 3 17 18 import org.apache.ojb.broker.metadata.ClassDescriptor; 19 import org.apache.ojb.broker.metadata.FieldDescriptor; 20 import org.apache.ojb.broker.util.logging.Logger; 21 22 28 public class SqlUpdateStatement extends SqlPkStatement 29 { 30 protected String sql; 31 32 38 public SqlUpdateStatement(ClassDescriptor cld, Logger logger) 39 { 40 super(cld, logger); 41 } 42 43 48 private void appendSetClause(ClassDescriptor cld, StringBuffer stmt) 49 { 50 FieldDescriptor[] fields = cld.getNonPkRwFields(); 51 52 if(fields.length == 0) 53 { 54 return; 55 } 56 57 stmt.append(" SET "); 58 for(int i = 0; i < fields.length; i++) 59 { 60 stmt.append(fields[i].getColumnName()); 61 stmt.append("=?"); 62 if(i < fields.length - 1) 63 { 64 stmt.append(","); 65 } 66 } 67 } 68 69 72 public String getStatement() 73 { 74 if(sql == null) 75 { 76 StringBuffer stmt = new StringBuffer (1024); 77 ClassDescriptor cld = getClassDescriptor(); 78 79 stmt.append("UPDATE "); 80 appendTable(cld, stmt); 81 appendSetClause(cld, stmt); 82 appendWhereClause(cld, true, stmt); 84 sql = stmt.toString(); 85 } 86 return sql; 87 } 88 89 } 90 | Popular Tags |