wiki:FmgVen/Documentation

Version 2 (modified by fmguler, 14 years ago) (diff)

added quick intro, copied code blocks from Sample.java

fmgVen Documentation

This page will contain documentation for the end user. Will illustrate how to use fmgVen by code samples, step by step.

Quick Intro

Here is a quick and dirty introduction to Ven. For more, see the Sample.java file in the test classes. (In the future, I am also planning to implement Pet Clinic sample application using Ven, which will be much more explanatory).

The domain model used in the examples;

SomeDomainObject has both many to one and one to many relationship with AnotherDomainObject (SDO.ado, SDO.ados). AnotherDomainObject has many to one relationship with SomeDomainObject (ADO.sdo).

Save and Update

Ven ven = getVen();

//insert
SomeDomainObject obj = new SomeDomainObject();
obj.setName("name");
obj.setDescription("desc");
obj.setDate(new Date());
ven.save(obj);
System.out.println(obj);

//update
obj.setName("name update");
ven.save(obj);
System.out.println(obj);

Delete

Ven ven = getVen();
ven.delete(2, SomeDomainObject.class);

Get

Ven ven = getVen();

//get with includes
Set joins = new HashSet();
joins.add("SomeDomainObject.anotherDomainObjects");
joins.add("SomeDomainObject.anotherDomainObject");
SomeDomainObject obj = (SomeDomainObject)ven.get(1, SomeDomainObject.class, joins);
System.out.println(obj);

Set joins2 = new HashSet();
joins2.add("AnotherDomainObject.someDomainObject");
AnotherDomainObject obj2 = (AnotherDomainObject)ven.get(1, AnotherDomainObject.class, joins2);
System.out.println(obj2);

List

Ven ven = getVen();

//list with includes
Set joins = new HashSet();
joins.add("SomeDomainObject.anotherDomainObjects");
joins.add("SomeDomainObject.anotherDomainObject");
List objList = ven.list(SomeDomainObject.class, joins);

Iterator it = objList.iterator();
while (it.hasNext()) {
    SomeDomainObject someDomainObject = (SomeDomainObject)it.next();
    System.out.println(someDomainObject);
}

List by Criteria

Ven ven = getVen();

//these objects will be included
Set joins = new HashSet();
joins.add("SomeDomainObject.anotherDomainObjects");
joins.add("SomeDomainObject.anotherDomainObject");

//the results will be filtered according to this criteria
Criteria criteria = new Criteria() //criteria object
        .like("SomeDomainObject.anotherDomainObjects.name", "a%") //attribute like value
        .eq("SomeDomainObject.name", "sdo1") //attribute equals value
        .and(); //connects previous criteria with logical and (postfix notation)

//list with includes and criteria
List objList = ven.list(SomeDomainObject.class, joins, criteria);

//print the results
Iterator it = objList.iterator();
while (it.hasNext()) {
    SomeDomainObject someDomainObject = (SomeDomainObject)it.next();
    System.out.println(someDomainObject);
}