Ignore:
Timestamp:
Feb 9, 2011, 10:53:45 PM (13 years ago)
Author:
fmguler
Message:

Refs #3 - Ven.get() is converted to the new format. QueryGenerator and QueryMapper are mostly OK, generateRecursively and mapRecursively are converted and checked. Handles joins (includes/associations) many to one and one to many. For one to many, the reverse join field can be determined in a couple of ways. First way is (prefereed) having VenList as the list implementation which specifies the element class and the join field. Second way is using Java 1.5 generic type to detect element class (not yet implemented) and guessing join field by convention (if multiple joins exist, this won't work). The last way is to have some kind of annotation or configuration, which is of course the least preferred way. VenList has a static method to determine the element class in the object list, which currently calls getElementClass if the list is an instance of VenList. In the future other options can be implemented.

Getting object using joins (includes/associations) are tested using dummy assocations between SomeDomainObject and AnotherDomainObject. The Sample class builds the database, tests the operations and rolls back to the initial state. Database refactoring operations are moved to the LiquibaseUtil for clarity.

In the future, the generated queries will be shortened using hashed aliases, and the criteria subsystem will be implemented.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fmgVen/src/com/fmguler/ven/Ven.java

    r27 r28  
    1818package com.fmguler.ven; 
    1919 
     20import com.fmguler.ven.util.Convert; 
    2021import java.util.HashMap; 
    2122import java.util.List; 
    2223import java.util.Map; 
     24import java.util.Set; 
    2325import javax.sql.DataSource; 
    2426import org.springframework.beans.BeanWrapper; 
     
    3638    private QueryGenerator generator; 
    3739    private QueryMapper mapper; 
     40    private boolean debug = true; 
    3841 
    3942    public Ven() { 
     
    5053    } 
    5154 
    52     public Object get(int id, Class objectClass) { 
    53         return null; 
     55    public Object get(int id, Class objectClass, Set joins) { 
     56        String query = generator.generateSelectQuery(objectClass, joins); 
     57        query += " where 1=1 and " + Convert.toDB(Convert.toSimpleName(objectClass.getName())) + ".id = :___id "; 
     58 
     59        Map paramMap = new HashMap(); 
     60        paramMap.put("___id", new Integer(id)); 
     61        if (debug) System.out.println("Ven - SQL: " + query); 
     62 
     63        List result = mapper.list(query, paramMap, objectClass); 
     64        if (result.isEmpty()) return null; 
     65        if (result.size() > 1) System.out.println("Ven - WARNING >> get(id) returns more than one row"); 
     66        return result.get(0); 
    5467    } 
    5568 
     
    114127        if (dataSource == null) throw new RuntimeException("fmgVen - DataSource cannot be null"); 
    115128        this.template = new NamedParameterJdbcTemplate(dataSource); 
     129        mapper.setDataSource(dataSource); 
    116130    } 
    117131 
Note: See TracChangeset for help on using the changeset viewer.