source: trunk/fmgVen/src/com/fmguler/ven/util/VenList.java @ 30

Last change on this file since 30 was 28, checked in by fmguler, 14 years ago

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 size: 2.6 KB
Line 
1/*
2 *  fmgVen - A Convention over Configuration Java ORM Tool
3 *  Copyright 2011 Fatih Mehmet Güler
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 *  under the License.
17 */
18package com.fmguler.ven.util;
19
20import java.util.LinkedList;
21import java.util.List;
22
23/**
24 * A Simple Linked List which informs the type of its elements.
25 * @author Fatih Mehmet Güler
26 */
27public class VenList extends LinkedList {
28    private Class elementClass;
29    private String joinField;
30
31    /**
32     * Creates new instance of VenList
33     */
34    public VenList() {
35    }
36
37    /**
38     * Creates new instance of VenList, specifying the type of elements
39     * @param elementClass the type of elements of this list
40     */
41    public VenList(Class elementClass) {
42        this.elementClass = elementClass;
43    }
44
45    /**
46     * Creates new instance of VenList, specifying the type of elements and the join field
47     * @param elementClass the type of elements of this list
48     * @param joinField the field which refers to the parent object
49     */
50    public VenList(Class elementClass, String joinField) {
51        this.elementClass = elementClass;
52        this.joinField = joinField;
53    }
54
55    /**
56     * Returns the type of the elements in this list.
57     * @return element type
58     */
59    public Class getElementClass() {
60        return elementClass;
61    }
62
63    /**
64     * Returns the field in the element class which refers the parent object
65     * @return element join field
66     */
67    public String getJoinField() {
68        return joinField;
69    }
70
71    /**
72     * Return the class of the elements in the list
73     * @param list the list
74     * @return the element class in the list
75     */
76    public static Class findElementClass(List list) {
77        if (list.size() > 0) {
78            Object elem = list.get(0);
79            return elem.getClass();
80        }
81        if (list instanceof VenList) {
82            return ((VenList)list).getElementClass();
83        } else {
84            //find according to 1.5 generic or some convention (e.g. xyzList -> xyz)
85            return null;
86        }
87    }
88}
Note: See TracBrowser for help on using the repository browser.