Changeset 37
- Timestamp:
- Mar 20, 2012, 2:40:52 PM (13 years ago)
- Location:
- trunk/fmgVen
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/nbproject/build-impl.xml
r32 r37 21 21 --> 22 22 <project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="fmgVen-impl"> 23 <fail message="Please build using Ant 1. 7.1or higher.">23 <fail message="Please build using Ant 1.8.0 or higher."> 24 24 <condition> 25 25 <not> 26 <antversion atleast="1. 7.1"/>26 <antversion atleast="1.8.0"/> 27 27 </not> 28 28 </condition> … … 252 252 <property name="jar.index" value="false"/> 253 253 <property name="jar.index.metainf" value="${jar.index}"/> 254 <property name="copylibs.rebase" value="true"/> 254 255 <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> 255 256 </target> … … 438 439 <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/> 439 440 <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}"> 441 <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> 440 442 <jvmarg value="${profiler.info.jvmargs.agent}"/> 441 443 <jvmarg line="${profiler.info.jvmargs}"/> … … 573 575 </pathconvert> 574 576 <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> 575 <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" r untimeclasspath="${run.classpath.without.build.classes.dir}">577 <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> 576 578 <fileset dir="${build.classes.dir}"/> 577 579 <manifest> … … 898 900 <target depends="init" if="have.sources" name="-javadoc-build"> 899 901 <mkdir dir="${dist.javadoc.dir}"/> 902 <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}"> 903 <and> 904 <isset property="endorsed.classpath.cmd.line.arg"/> 905 <not> 906 <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/> 907 </not> 908 </and> 909 </condition> 900 910 <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> 901 911 <classpath> … … 909 919 <exclude name="*.java"/> 910 920 </fileset> 921 <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/> 911 922 </javadoc> 912 923 <copy todir="${dist.javadoc.dir}"> -
trunk/fmgVen/nbproject/genfiles.properties
r32 r37 5 5 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 6 nbproject/build-impl.xml.data.CRC32=31e5c25b 7 nbproject/build-impl.xml.script.CRC32= f19130078 nbproject/build-impl.xml.stylesheet.CRC32= 0ae3a408@1.44.1.457 nbproject/build-impl.xml.script.CRC32=74d9d881 8 nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.1.46 -
trunk/fmgVen/nbproject/project.properties
r34 r37 1 1 annotation.processing.enabled=true 2 2 annotation.processing.enabled.in.editor=false 3 annotation.processing.processors.list= 3 4 annotation.processing.run.all.processors=true 4 5 application.args= … … 54 55 meta.inf.dir=${src.dir}/META-INF 55 56 mkdist.disabled=true 56 platform.active=JDK_1. 457 platform.active=JDK_1.5 57 58 run.classpath=\ 58 59 ${javac.classpath}:\ -
trunk/fmgVen/src/com/fmguler/ven/Criteria.java
r32 r37 43 43 public class Criteria { 44 44 private StringBuffer criteriaStringBuffer = new StringBuffer(); //for string criteria 45 private StringBuffer orderStringBuffer = new StringBuffer(); //for ordering 45 46 private LinkedList criterionList = new LinkedList(); //for typed criteria 46 47 private Map parameters = new HashMap(); //the parameters used in criteria string … … 99 100 } 100 101 102 /** 103 * Return order string to SQL 104 */ 105 public String orderStringToSQL() { 106 if (orderStringBuffer.length() == 0) return ""; 107 orderStringBuffer.insert(0, " order by"); 108 return orderStringBuffer.toString(); 109 } 110 101 111 //-------------------------------------------------------------------------- 102 112 //Typed Criteria Methods … … 153 163 */ 154 164 public Criteria orderAsc(String attribute) { 155 //Not implemented yet. 165 if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 166 this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" asc"); 156 167 return this; 157 168 } … … 161 172 */ 162 173 public Criteria orderDesc(String attribute) { 163 //Not implemented yet. 174 if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 175 this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" desc"); 164 176 return this; 165 177 } … … 223 235 stack.push(sr); 224 236 } else if (conn.equals(Criterion.CONN_OR)) { 225 226 227 228 229 230 231 232 233 237 String s1 = (String)stack.pop(); 238 String s2 = (String)stack.pop(); 239 String sr = "(" + s1 + " or " + s2 + ")"; 240 stack.push(sr); 241 } else if (conn.equals(Criterion.CONN_NOT)) { 242 String s = (String)stack.pop(); 243 String sr = "not (" + s + ")"; 244 stack.push(sr); 245 } 234 246 } 235 247 } … … 284 296 .and() //connect previous criteria with and 285 297 .isNull("SomeDomainObject.description") //attribute is null 286 .or(); //connect previous criteria with and 298 .or() //connect previous criteria with or 299 .orderDesc("SomeDomainObject.name"); //order by some attribute 287 300 288 301 //print the resulting where clause SQL 289 302 System.out.println(criteria.criteriaToSQL()); 303 304 //print the resulting order clause SQL 305 System.out.println(criteria.orderStringToSQL()); 290 306 291 307 //the result is; -
trunk/fmgVen/src/com/fmguler/ven/QueryGenerator.java
r32 r37 21 21 import com.fmguler.ven.util.VenList; 22 22 import java.beans.PropertyDescriptor; 23 import java.math.BigDecimal; 23 24 import java.util.Date; 24 25 import java.util.HashSet; … … 47 48 this.dbClasses.add(Double.class); 48 49 this.dbClasses.add(Boolean.class); 50 this.dbClasses.add(BigDecimal.class); 49 51 } 50 52 … … 91 93 //if (fieldName.equals("id")) continue; //remove if it does not break the sequence 92 94 if (dbClasses.contains(fieldClass)) { //direct database field (Integer,String,Date, etc) 93 query.append(columnName );95 query.append(columnName.equals("order")?"\"order\"":columnName); 94 96 query.append(","); 95 97 values.append(":").append(fieldName); … … 129 131 String fieldName = pdArr[i].getName(); //field name 130 132 if (dbClasses.contains(fieldClass)) { //direct database field (Integer,String,Date, etc) 131 query.append(columnName ).append("=:").append(fieldName);133 query.append(columnName.equals("order")?"\"order\"":columnName).append("=:").append(fieldName); 132 134 query.append(","); 133 135 } -
trunk/fmgVen/src/com/fmguler/ven/QueryMapper.java
r35 r37 21 21 import com.fmguler.ven.util.VenList; 22 22 import java.beans.PropertyDescriptor; 23 import java.math.BigDecimal; 23 24 import java.sql.ResultSet; 24 25 import java.sql.SQLException; … … 56 57 this.dbClasses.add(Double.class); 57 58 this.dbClasses.add(Boolean.class); 59 this.dbClasses.add(BigDecimal.class); 58 60 } 59 61 … … 125 127 if (debug) System.out.println("--field not found: " + columnName); 126 128 } 129 continue; //if this is a primitive property, it cannot be an object or list 127 130 } 128 131 129 132 //many to one association (object property) 130 if ( map &&fieldClass.getPackage() != null && domainPackages.contains(fieldClass.getPackage().getName())) {133 if (fieldClass.getPackage() != null && domainPackages.contains(fieldClass.getPackage().getName())) { 131 134 if (columns.contains(columnName + "_id")) { 132 135 if (debug) System.out.println(">>object is found " + columnName); 133 136 List list = new ArrayList(1); //we know there will be single result 137 if (!map) list.add(fieldValue); //otherwise we cannot catch one to many assc. (lists) of many to one (object) assc. 134 138 mapRecursively(rs, columns, columnName, fieldClass, list); 135 139 if (list.size() > 0) wr.setPropertyValue(pd.getName(), list.get(0)); … … 151 155 } 152 156 } catch (Exception ex) { 157 System.out.println("Ven - error while mapping row, table: " + tableName + " object class: " + objectClass + " error: " + ex.getMessage()); 153 158 if (debug) { 154 System.out.println("Ven - error while mapping row; ");155 159 ex.printStackTrace(); 156 160 } -
trunk/fmgVen/src/com/fmguler/ven/Ven.java
r32 r37 53 53 * <p> 54 54 * By default none of the associations will be retrieved. 55 * To include the object associations (retrieve the object graph) joins should be specified, e.g. 56 * <code>SomeObject.anotherObject</code> 57 * 55 * To include the object associations (retrieve the object graph) joins 56 * should be specified, e.g. 57 * <code>SomeObject.anotherObject</code> 58 * 58 59 * @param id the id of the object to be retrieved 59 60 * @param objectClass the class of the object to be retrieved … … 76 77 77 78 /** 79 * Get the object with the specified id, of the specified objectClass type. 80 * <p> 81 * By default none of the associations will be retrieved. 82 * To include the object associations (retrieve the object graph) joins 83 * should be specified, e.g. 84 * <code>SomeObject.anotherObject</code> 85 * 86 * @param id the id of the object to be retrieved 87 * @param objectClass the class of the object to be retrieved 88 * @param joins the set of object graphs to be included with the object 89 * @param criteria to filter and order the result according to some criteria 90 * (e.g. for associations) 91 * @return the retrieved object including specified associations 92 */ 93 public Object get(int id, Class objectClass, Set joins, Criteria criteria) { 94 String query = generator.generateSelectQuery(objectClass, joins); 95 query += " where 1=1 and " + Convert.toDB(Convert.toSimpleName(objectClass.getName())) + ".id = :___id " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() + criteria.orderStringToSQL(); 96 97 criteria.getParameters().put("___id", new Integer(id)); 98 if (debug) System.out.println("Ven - SQL: " + query); 99 100 List result = mapper.list(query, criteria.getParameters(), objectClass); 101 if (result.isEmpty()) return null; 102 if (result.size() > 1) System.out.println("Ven - WARNING >> get(id) returns more than one row"); 103 return result.get(0); 104 } 105 106 /** 78 107 * List the objects of the specified objectClass type. 79 108 * <p> 80 109 * By default none of the associations will be retrieved. 81 * To include the object associations (retrieve the object graph) joins should be specified, e.g. 82 * <code>SomeObject.anotherObject</code> 83 * 110 * To include the object associations (retrieve the object graph) joins 111 * should be specified, e.g. 112 * <code>SomeObject.anotherObject</code> 113 * 84 114 * @param objectClass the class of the objects to be retrieved 85 115 * @param joins the set of object graphs to be included with objects … … 87 117 */ 88 118 public List list(Class objectClass, Set joins) { 89 String query = generator.generateSelectQuery(objectClass, joins); 90 91 Map paramMap = new HashMap(); 92 if (debug) System.out.println("Ven - SQL: " + query); 93 94 List result = mapper.list(query, paramMap, objectClass); 95 return result; 96 } 97 98 /** 99 * List the objects of the specified objectClass type, filtering according to some criteria. 100 * <p> 101 * By default none of the associations will be retrieved. 102 * To include the object associations (retrieve the object graph) joins should be specified, e.g. 103 * <code>SomeObject.anotherObject</code> 104 * 119 return list(objectClass, joins, new Criteria()); 120 } 121 122 /** 123 * List the objects of the specified objectClass type, filtering according 124 * to some criteria. 125 * <p> 126 * By default none of the associations will be retrieved. 127 * To include the object associations (retrieve the object graph) joins 128 * should be specified, e.g. 129 * <code>SomeObject.anotherObject</code> 130 * 105 131 * @param objectClass the class of the objects to be retrieved 106 132 * @param joins the set of object graphs to be included with objects 107 133 * @param criteria to filter and order the result according to some criteria 108 * @return the list of objects including the specified associations filtered according to the specified criteria 134 * @return the list of objects including the specified associations filtered 135 * according to the specified criteria 109 136 */ 110 137 public List list(Class objectClass, Set joins, Criteria criteria) { 111 138 String query = generator.generateSelectQuery(objectClass, joins); 112 query += " where 1=1 " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() ;139 query += " where 1=1 " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() + criteria.orderStringToSQL(); 113 140 114 141 if (debug) System.out.println("Ven - SQL: " + query); … … 119 146 120 147 /** 121 * Save the object. If it has a non null (or non zero) "id" property it will be updated. 148 * Save the object. If it has a non null (or non zero) "id" property it will 149 * be updated. 122 150 * It will be inserted otherwise. 123 151 * <p> 124 152 * The object will be saved to a table with the same name as the object, 125 153 * The fields of object will be mapped to the table fields. 126 * 154 * 127 155 * @param object the object to be saved 128 156 */ … … 144 172 145 173 /** 146 * Delete the the object with the specified id of the specified objectClass type 174 * Delete the the object with the specified id of the specified objectClass 175 * type 147 176 * @param id the id of the object to be deleted 148 177 * @param objectClass the class of the object to be deleted … … 200 229 * Set debug mode, true will log all debug messages to System.out 201 230 * <p> 202 * Note: Use debug mode to detect problems only. It is not a general purpose logging mode. 231 * Note: Use debug mode to detect problems only. It is not a general purpose 232 * logging mode. 203 233 * @param debug set true to enable debug mode 204 234 */ … … 208 238 mapper.setDebug(debug); 209 239 } 240 241 //-------------------------------------------------------------------------- 242 //GETTERS 243 244 /** 245 * @return the underlying query generator, for advanced usage. 246 */ 247 public QueryGenerator getQueryGenerator() { 248 return generator; 249 } 250 251 /** 252 * @return the underlying query mapper, for advanced usage. 253 */ 254 public QueryMapper getQueryMapper() { 255 return mapper; 256 } 210 257 } -
trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java
r30 r37 168 168 .like("SomeDomainObject.anotherDomainObjects.name", "a%") //attribute like value 169 169 .eq("SomeDomainObject.name", "sdo1") //attribute equals value 170 .and(); //connects previous criteria with and 170 .and() //connects previous criteria with and 171 .orderDesc("SomeDomainObject.anotherDomainObjects.name"); //order by some attribute 171 172 172 173 //list with includes and criteria
Note: See TracChangeset
for help on using the changeset viewer.