Changeset 27 for trunk/fmgVen


Ignore:
Timestamp:
Jan 16, 2011, 10:00:07 PM (13 years ago)
Author:
fmguler
Message:

Refs #3 - Ven.delete() is converted to the new format. Missing javadocs are entered.

Location:
trunk/fmgVen
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/fmgVen/etc/test-db/test-db-changelog.xml

    r26 r27  
    2222    <changeSet author="fmguler" id="3"> 
    2323        <insert schemaName="public" tableName="some_domain_object"> 
     24            <column name="id" value="1"/> 
    2425            <column name="name" value="name1"/> 
    2526            <column name="description" value="desc1"/> 
  • trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java

    r26 r27  
    2727 
    2828/** 
    29  * Generates queries in the form of 'Convention over Configuration' of the specified class. 
     29 * Generates queries in the form of 'Convention over Configuration' for the specified objects. 
    3030 * @author Fatih Mehmet Güler 
    3131 */ 
     
    5353    } 
    5454 
    55     public String generateInsertQuery(Object object) throws VenException { 
     55    /** 
     56     * Generates insert query for the specified object 
     57     * @param object the object to generate insert query for 
     58     * @return the insert SQL query 
     59     */ 
     60    public String generateInsertQuery(Object object) { 
    5661        BeanWrapper wr = new BeanWrapperImpl(object); 
    5762        String objectName = Convert.toSimpleName(object.getClass().getName()); 
     
    9095 
    9196    /** 
    92      * Generates insert/update query 
    93      * @return the insert update SQL query 
     97     * Generates update query for the specified object 
     98     * @param object the object to generate update query for 
     99     * @return the update SQL query 
    94100     */ 
    95101    public String generateUpdateQuery(Object object) throws VenException { 
     
    114120        } 
    115121        query.deleteCharAt(query.length() - 1); 
    116         query.append(" where id = :id ;"); //TODO: remove the last comma 
     122        query.append(" where id = :id ;"); 
    117123        return query.toString(); 
    118124    } 
    119125 
     126    /** 
     127     * Generates delete query for the specified object class 
     128     * @param objectClass the object class to generate query for 
     129     * @return the delete SQL query 
     130     */ 
     131    public String generateDeleteQuery(Class objectClass){ 
     132        StringBuffer query = new StringBuffer(); 
     133        query.append("delete from ").append(Convert.toDB(Convert.toSimpleName(objectClass.getName()))).append(" where id = :id;"); 
     134        return query.toString(); 
     135    } 
     136         
     137    /** 
     138     * Generates sequence query for the specified object 
     139     * @param object the objectc to generate sequence query for 
     140     * @return the SQL query to select next id 
     141     */ 
    120142    public String generateSequenceQuery(Object object) throws VenException { 
    121143        String objectName = Convert.toSimpleName(object.getClass().getName()); 
  • trunk/fmgVen/src/com/fmguler/ven/Ven.java

    r26 r27  
    2020import java.util.HashMap; 
    2121import java.util.List; 
     22import java.util.Map; 
    2223import javax.sql.DataSource; 
    2324import org.springframework.beans.BeanWrapper; 
     
    5455 
    5556    /** 
    56      * Save the object. If it has a "id" property it will be updated. 
     57     * Save the object. If it has a non null (or non zero) "id" property it will be updated. 
    5758     * It will be inserted otherwise. 
    5859     * <p> 
     
    7879    } 
    7980 
     81    /** 
     82     * Delete the the object with the specified id of the specified objectClass type 
     83     * @param id the id of the object to be deleted 
     84     * @param objectClass the class of the object to be deleted 
     85     */ 
    8086    public void delete(int id, Class objectClass) { 
     87        String query = generator.generateDeleteQuery(objectClass); 
     88        Map parameterMap = new HashMap(); 
     89        parameterMap.put("id", new Integer(id)); 
     90        template.update(query, parameterMap); 
    8191    } 
    8292 
     
    8696    private boolean isObjectNew(Object object) throws VenException { 
    8797        BeanWrapper beanWrapper = new BeanWrapperImpl(object); 
    88         Object objectId = beanWrapper.getPropertyValue("id");  
     98        Object objectId = beanWrapper.getPropertyValue("id"); 
    8999        if (objectId == null) return true; 
    90100        if (!(objectId instanceof Integer)) throw new VenException(VenException.EC_GENERATOR_OBJECT_ID_TYPE_INVALID); 
  • trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java

    r26 r27  
    3939public class Sample { 
    4040    public static void main(String[] args) { 
     41        //build the sample database 
    4142        buildDatabase(); 
     43 
     44        //save an object 
    4245        testSave(); 
     46        //delete an object 
     47        testDelete(); 
     48 
     49        //rollback the sample database to original state 
    4350        rollbackDatabase(); 
    4451    } 
Note: See TracChangeset for help on using the changeset viewer.