rendered paste bodyimport java.util.List;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* User: ivan
* Date: Oct 26, 2007
* Time: 10:41:17 PM
* To change this template use File | Settings | File Templates.
*/
public class DocsSQLMakerThingyMaJig {
protected static int NUM_OF_OBJECTS = 45;
protected class ValueObject {
private int typeID;
private int valueID;
public ValueObject() {
}
public ValueObject(int typeID, int valueID) {
this.typeID = typeID;
this.valueID = valueID;
}
public int getValueID() {
return valueID;
}
public void setValueID(int valueID) {
this.valueID = valueID;
}
public int getTypeID() {
return typeID;
}
public void setTypeID(int typeID) {
this.typeID = typeID;
}
public String toString() {
return "ValueObject(typeID="+typeID+"; valueID="+valueID+")";
}
}
private List<ValueObject> LIST_OF_VALUE_OBJECTS;
public DocsSQLMakerThingyMaJig() {
LIST_OF_VALUE_OBJECTS = new ArrayList<ValueObject>();
for (int i = 0; i < NUM_OF_OBJECTS; i++) {
for (int j = 0; j < NUM_OF_OBJECTS; j++) {
LIST_OF_VALUE_OBJECTS.add(new ValueObject(i, j));
}
}
}
public void runMe() {
System.out.println(" MAKING SQL QUERY ");
String myQuery = buildMyQuery(LIST_OF_VALUE_OBJECTS);
System.out.println(" ******* SQL ***********");
System.out.println(myQuery);
}
public static void main(String[] args) {
DocsSQLMakerThingyMaJig test = new DocsSQLMakerThingyMaJig();
test.runMe();
}
private String buildMyQuery(List<ValueObject> valueObjects) {
System.out.println(" generating sql for "+valueObjects.size()+" value objects. ");
StringBuffer q = new StringBuffer();
q.append(" select * from selected_product p " +
" where p.id = (select po.selected_product_id " +
" from selected_product_option po " +
" where po.selected_product_id = p.id " +
" and (");
for (int i = 0; i < valueObjects.size(); i++) {
ValueObject o = valueObjects.get(i);
System.out.println(" adding "+o);
q.append("(");
q.append(" po.product_attribute_type_id=").append(o.getTypeID());
q.append(" and po.product_attribute_value_id =").append(o.getValueID());
q.append(" )\n");
if (i + 1 != valueObjects.size()) {
q.append(" || ");
}
}
q.append(" )");
q.append(" group by po.selected_product_id " +
" );");
return q.toString();
}
}