use of org.jaffa.persistence.engines.jdbcengine.configservice.ClassMetaData in project jaffa-framework by jaffa-projects.
the class StatementHelper method getDeleteStatementString.
/**
* Returns a SQL String for use in Statements for deleting records from the table corresponding to the input Persistent object.
* @param object The object to be deleted.
* @param engineType The engine type as defined in init.xml
* @throws IllegalAccessException if the accessor Method for an attribute enforces Java language access control and the underlying method is inaccessible.
* @throws InvocationTargetException if the accessor method for an attribute throws an exception.
* @throws IOException if any error occurs while extracting the value for an attribute.
* @return a SQL String for use in Statements for deleting records.
*/
public static String getDeleteStatementString(IPersistent object, String engineType) throws IllegalAccessException, InvocationTargetException, IOException {
ClassMetaData classMetaData = getClassMetaData(object);
StringBuffer buf = new StringBuffer(DELETE_FROM);
buf.append(' ');
buf.append(classMetaData.getTable());
buf.append(' ');
buf.append(WHERE);
buf.append(' ');
boolean first = true;
for (Iterator i = classMetaData.getAllKeyFieldNames().iterator(); i.hasNext(); ) {
if (first) {
first = false;
} else {
buf.append(' ');
buf.append(AND);
buf.append(' ');
}
String attributeName = (String) i.next();
Object value = MoldingService.getInstanceValue(object, classMetaData, attributeName);
buf.append(formatSqlName(classMetaData.getSqlName(attributeName), engineType));
if (value == null)
buf.append(' ').append(IS_NULL);
else
buf.append('=').append(DataTranslator.getDml(value, classMetaData.getSqlType(attributeName), engineType));
}
return buf.toString();
}
use of org.jaffa.persistence.engines.jdbcengine.configservice.ClassMetaData in project jaffa-framework by jaffa-projects.
the class StatementHelper method getUpdateStatementString.
/**
* Returns a SQL String for use in Statements for updating records in the table corresponding to the input Persistent object.
* @param object The object to be updated.
* @param engineType The engine type as defined in init.xml
* @throws IllegalAccessException if the accessor Method for an attribute enforces Java language access control and the underlying method is inaccessible.
* @throws InvocationTargetException if the accessor method for an attribute throws an exception.
* @throws IOException if any error occurs while extracting the value for an attribute.
* @return a SQL String for use in Statements for updating records.
*/
public static String getUpdateStatementString(IPersistent object, String engineType) throws IllegalAccessException, InvocationTargetException, IOException {
ClassMetaData classMetaData = getClassMetaData(object);
StringBuffer buf = new StringBuffer(UPDATE);
buf.append(' ');
buf.append(classMetaData.getTable());
buf.append(' ');
buf.append(SET);
buf.append(' ');
boolean first = true;
for (Iterator i = classMetaData.getAttributes().iterator(); i.hasNext(); ) {
if (first) {
first = false;
} else {
buf.append(',');
}
String attributeName = (String) i.next();
Object value = MoldingService.getInstanceValue(object, classMetaData, attributeName);
buf.append(formatSqlName(classMetaData.getSqlName(attributeName), engineType));
buf.append('=');
buf.append(DataTranslator.getDml(value, classMetaData.getSqlType(attributeName), engineType));
}
buf.append(' ');
buf.append(WHERE);
buf.append(' ');
first = true;
for (Iterator i = classMetaData.getAllKeyFieldNames().iterator(); i.hasNext(); ) {
if (first) {
first = false;
} else {
buf.append(' ');
buf.append(AND);
buf.append(' ');
}
String attributeName = (String) i.next();
Object value = MoldingService.getInstanceValue(object, classMetaData, attributeName);
buf.append(formatSqlName(classMetaData.getSqlName(attributeName), engineType));
if (value == null)
buf.append(' ').append(IS_NULL);
else
buf.append('=').append(DataTranslator.getDml(value, classMetaData.getSqlType(attributeName), engineType));
}
return buf.toString();
}
Aggregations