- Timestamp:
- Jan 16, 2011, 10:00:07 PM (14 years ago)
- Location:
- trunk/fmgVen
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/etc/test-db/test-db-changelog.xml
r26 r27 22 22 <changeSet author="fmguler" id="3"> 23 23 <insert schemaName="public" tableName="some_domain_object"> 24 <column name="id" value="1"/> 24 25 <column name="name" value="name1"/> 25 26 <column name="description" value="desc1"/> -
trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java
r26 r27 27 27 28 28 /** 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. 30 30 * @author Fatih Mehmet Güler 31 31 */ … … 53 53 } 54 54 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) { 56 61 BeanWrapper wr = new BeanWrapperImpl(object); 57 62 String objectName = Convert.toSimpleName(object.getClass().getName()); … … 90 95 91 96 /** 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 94 100 */ 95 101 public String generateUpdateQuery(Object object) throws VenException { … … 114 120 } 115 121 query.deleteCharAt(query.length() - 1); 116 query.append(" where id = :id ;"); //TODO: remove the last comma122 query.append(" where id = :id ;"); 117 123 return query.toString(); 118 124 } 119 125 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 */ 120 142 public String generateSequenceQuery(Object object) throws VenException { 121 143 String objectName = Convert.toSimpleName(object.getClass().getName()); -
trunk/fmgVen/src/com/fmguler/ven/Ven.java
r26 r27 20 20 import java.util.HashMap; 21 21 import java.util.List; 22 import java.util.Map; 22 23 import javax.sql.DataSource; 23 24 import org.springframework.beans.BeanWrapper; … … 54 55 55 56 /** 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. 57 58 * It will be inserted otherwise. 58 59 * <p> … … 78 79 } 79 80 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 */ 80 86 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); 81 91 } 82 92 … … 86 96 private boolean isObjectNew(Object object) throws VenException { 87 97 BeanWrapper beanWrapper = new BeanWrapperImpl(object); 88 Object objectId = beanWrapper.getPropertyValue("id"); 98 Object objectId = beanWrapper.getPropertyValue("id"); 89 99 if (objectId == null) return true; 90 100 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 39 39 public class Sample { 40 40 public static void main(String[] args) { 41 //build the sample database 41 42 buildDatabase(); 43 44 //save an object 42 45 testSave(); 46 //delete an object 47 testDelete(); 48 49 //rollback the sample database to original state 43 50 rollbackDatabase(); 44 51 }
Note: See TracChangeset
for help on using the changeset viewer.