Index: trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java
===================================================================
--- trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java	(revision 23)
+++ trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java	(revision 26)
@@ -18,6 +18,11 @@
 package com.fmguler.ven;
 
+import com.fmguler.ven.util.Convert;
+import java.beans.PropertyDescriptor;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
+import org.springframework.beans.BeanWrapper;
+import org.springframework.beans.BeanWrapperImpl;
 
 /**
@@ -27,7 +32,15 @@
 public class QueryGenerator {
     private Set domainPackages;
+    private Set dbClasses;
 
     public QueryGenerator() {
         domainPackages = new HashSet();
+        dbClasses = new HashSet();
+        //the predefined database classes;
+        this.dbClasses.add(Integer.class);
+        this.dbClasses.add(String.class);
+        this.dbClasses.add(Date.class);
+        this.dbClasses.add(Double.class);
+        this.dbClasses.add(Boolean.class);
     }
 
@@ -40,9 +53,77 @@
     }
 
-    public String generateUpdateQuery() {
-        return null;
+    public String generateInsertQuery(Object object) throws VenException {
+        BeanWrapper wr = new BeanWrapperImpl(object);
+        String objectName = Convert.toSimpleName(object.getClass().getName());
+        String tableName = Convert.toDB(objectName);
+        PropertyDescriptor[] pdArr = wr.getPropertyDescriptors();
+
+        //generate insert query
+        StringBuffer query = new StringBuffer("insert into " + tableName + "(");
+        StringBuffer values = new StringBuffer(" values(");
+        for (int i = 0; i < pdArr.length; i++) {
+            Class fieldClass = pdArr[i].getPropertyType(); //field class
+            String columnName = Convert.toDB(pdArr[i].getName()); //column name
+            String fieldName = pdArr[i].getName(); //field name
+            //if (fieldName.equals("id")) continue; //remove if it does not break the sequence
+            if (dbClasses.contains(fieldClass)) { //direct database field (Integer,String,Date, etc)
+                query.append(columnName);
+                query.append(",");
+                values.append(":").append(fieldName);
+                values.append(",");
+            }
+            if (fieldClass.getPackage() != null && domainPackages.contains(fieldClass.getPackage().getName())) { //object
+                query.append(Convert.toDB(fieldName)).append("_id");
+                query.append(",");
+                values.append(":").append(fieldName).append(".id");
+                values.append(",");
+            }
+        }
+        query.deleteCharAt(query.length() - 1);
+        query.append(")");
+        values.deleteCharAt(values.length() - 1);
+        values.append(");");
+        query.append(values);
+
+        return query.toString();
     }
 
-    //SETTERS-------------------------------------------------------------------
+    /**
+     * Generates insert/update query
+     * @return the insert update SQL query
+     */
+    public String generateUpdateQuery(Object object) throws VenException {
+        BeanWrapper wr = new BeanWrapperImpl(object);
+        String objectName = Convert.toSimpleName(object.getClass().getName());
+        String tableName = Convert.toDB(objectName);
+        PropertyDescriptor[] pdArr = wr.getPropertyDescriptors();
+
+        StringBuffer query = new StringBuffer("update " + tableName + " set ");
+        for (int i = 0; i < pdArr.length; i++) {
+            Class fieldClass = pdArr[i].getPropertyType(); //field class
+            String columnName = Convert.toDB(pdArr[i].getName()); //column name
+            String fieldName = pdArr[i].getName(); //field name
+            if (dbClasses.contains(fieldClass)) { //direct database field (Integer,String,Date, etc)
+                query.append(columnName).append("=:").append(fieldName);
+                query.append(",");
+            }
+            if (fieldClass.getPackage() != null && domainPackages.contains(fieldClass.getPackage().getName())) { //object
+                query.append(columnName).append("_id=:").append(fieldName).append(".id");
+                query.append(",");
+            }
+        }
+        query.deleteCharAt(query.length() - 1);
+        query.append(" where id = :id ;"); //TODO: remove the last comma
+        return query.toString();
+    }
+
+    public String generateSequenceQuery(Object object) throws VenException {
+        String objectName = Convert.toSimpleName(object.getClass().getName());
+        String tableName = Convert.toDB(objectName);
+        return "select nextval('" + tableName + "_id_seq');";
+    }
+
+    //--------------------------------------------------------------------------
+    //SETTERS
     public void addDomainPackage(String domainPackage) {
         domainPackages.add(domainPackage);
