public String generateCreateCommand() throws NotImplementedTypesException { StringBuilder builder = new StringBuilder().append("create table ").append(tableName).append(" ("); for (int i = 0; i + 1 < fields.size(); i++) { builder.append(fields.get(i).generateDeclaration()); builder.append(", "); } builder.append(fields.get(fields.size() - 1).generateDeclaration()); builder.append(")"); return builder.toString(); }
public String generateInsertCommand(T item) throws NotImplementedTypesException { StringBuilder builder = new StringBuilder().append("insert into ").append(tableName).append(" values ("); for (int i = 0; i + 1 < fields.size(); i++) { builder.append(fields.get(i).stringValueOf(item)); builder.append(", "); } builder.append(fields.get(fields.size() - 1).stringValueOf(item)); builder.append(")"); return builder.toString(); }
public String generateUpdateCommand(T item) throws NotImplementedTypesException { StringBuilder builder = new StringBuilder().append("update ").append(tableName).append(" set "); for (int i = 0; i + 1 < fields.size(); i++) { builder .append(fields.get(i).getName()) .append(" = ") .append(fields.get(i).stringValueOf(item)) .append(", "); } builder .append(fields.get(fields.size() - 1).getName()) .append(" = ") .append(fields.get(fields.size() - 1).stringValueOf(item)); builder.append(" where "); builder .append(primaryKeyFieldConverter.getName()) .append(" = ") .append(primaryKeyFieldConverter.stringValueOf(item)); return builder.toString(); }