package freedb;
import java.util.Iterator;
import org.odbms.FUNCTION;
import org.odbms.OP;
import org.odbms.ObjectContainer;
import org.odbms.ObjectSet;
import org.odbms.Query;
import de.linwave.gtm.GTM;
import de.linwave.gtm.Util;
/**
*
* @author ljoeckel
*
*/
public class POQQuery1
{
protected static ObjectContainer gtm = GTM.getInstance();
/**
*
* @param searchFor
*/
public POQQuery1(String searchFor) {
if (searchFor == null)
throw new IllegalArgumentException("Parameter 'searchFor' must not be null");
Query q1 = gtm.query(Disc.class);
q1.constrain("DGENRE", OP.EQUALS, FUNCTION.TO_UPPER, "Jazz");
q1.constrain("DTITLE", OP.CONTAINS, FUNCTION.TO_UPPER, searchFor);
q1.constrain("DYEAR", OP.GREATER, 1999);
q1.sortBy("DYEAR");
ObjectSet<Disc> discs = q1.execute();
Util.printObjectSet(discs);
q1.printConstraintInfo();
gtm.printCacheStatistics();
System.out.println("-----------------------------------------");
// 2. query with Iterator
Query q2 = gtm.query(Disc.class);
q2.constrain("DTITLE", OP.STARTS_WITH, FUNCTION.TO_UPPER, searchFor);
q2.constrain("DTITLE", OP.CONTAINS, FUNCTION.TO_UPPER, "live");
q2.constrain("DYEAR", OP.RANGE, 2000, 2002);
q2.constrain("DGENRE", OP.EQUALS, FUNCTION.TO_UPPER, "BLUES");
discs = q2.execute();
Iterator<Disc> iter = discs.iterator();
while (iter.hasNext()) {
Disc disc = iter.next();
System.out.println(disc);
}
q2.printConstraintInfo();
gtm.printCacheStatistics();
}
/**
*
* @param args
*/
public static void main(String[] args)
{
// IndexUtils.addIndex(Disc.class, "DTITLE");
// IndexUtils.addIndex(Disc.class, "DYEAR");
String searchFor = "The";
if (args.length == 1)
searchFor = args[0];
new POQQuery1(searchFor);
}
}