Package de.linwave.gtm.query

Source Code of de.linwave.gtm.query.SimplePOQ

package de.linwave.gtm.query;

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;
import de.linwave.music.Album;
import de.linwave.music.Artist;
import freedb.Disc;

public class SimplePOQ
{
  private static ObjectContainer gtm = GTM.getInstance();

  public void allAritsts()
  {
    Util.enter("QBE: ALL Artists");

    Query query = gtm.query(Artist.class);

    ObjectSet<Artist> artists = query.execute();
    Util.snapshot();

    for (Artist artist : artists) {
      System.out.println("Artist = " + artist.getOID() + " " + artist.getName() + " played=" + artist.getPlayed());
    }
    Util.leave(artists.size());
  }

  public void artistJohnLennon()
  {
    Util.enter("QBE: Artist.name='John Lennon'");

    Query query = gtm.query(Artist.class);
    query.constrain("name", OP.EQUALS, null, "John Lennon");

    ObjectSet<Artist> artists = query.execute();
    Util.snapshot();

    for (Artist artist : artists) {
      System.out.println("Artist = " + artist.getOID() + " " + artist.getName() + " played=" + artist.getPlayed());
    }

    query.printConstraintInfo();
    Util.leave(artists.size());
  }

  public void albumYelloSubmarine()
  {
    Util.enter("QBE: Album.name='YELLOW SUBMARINE");
    Query query = gtm.query(Album.class);
    query.constrain("name", OP.EQUALS, FUNCTION.TO_UPPER, "YELLOW SUBMARINE");

    ObjectSet<Album> albums = query.execute();
    Util.snapshot();
    for (Album album : albums) {
      System.out.println("Album " + album.getOID() + " " + album.getName() + " " + album.getYear());
    }
    Util.leave(albums.size());
  }

  public void albumYelloSubmarine1970()
  {
    Util.enter("QBE: Album.name='YELLOW SUBMARINE AND yeear=1970");
    Query query = gtm.query(Album.class);
    query.constrain("name", OP.EQUALS, FUNCTION.TO_UPPER, "YELLOW SUBMARINE");
    query.constrain("year", OP.EQUALS, null, "1970");

    ObjectSet<Album> albums = query.execute();
    Util.snapshot();
    for (Album album : albums) {
      System.out.println("Album " + album.getOID() + " " + album.getName() + " " + album.getYear());
    }
    Util.leave(albums.size());
  }

  // public void albumYelloSubmarine1970() {
  // Util.enter("QBE: Album.name='Yellow Submarine' and ALbum.year=1970");
  // ObjectSet<Album> albums = gtm.queryByExample(new Album("Yellow Submarine", 1970));
  // Util.snapshot();
  // for (Album album : albums) {
  // System.out.println("Album " + album.getOID() + " " + album.getName() + " " + album.getYear());
  // }
  // Util.leave(albums.size());
  // }

  public void albumYear1969()
  {
    Util.enter("QBE: Album.year=1969");

    Query query = gtm.query(Album.class);
    query.constrain("year", OP.EQUALS, null, "1969");

    ObjectSet<Album> albums = query.execute();
    Util.snapshot();
    for (Album album : albums) {
      System.out.println("Album " + album.getOID() + " " + album.getName() + " " + album.getYear());
    }
    Util.leave(albums.size());
  }

  public void discsStartsWithBeatles1965()
  {
    Util.enter("QBE: Disc starts with 'The Beatles' and year = 1965");

    Disc d = new Disc();
    d.setDYEAR(1965);
    d.setDTITLE("The Beatles*");

    ObjectSet<Disc> discs = gtm.queryByExample(d);
    Util.snapshot();
    int cnt = 0;
    for (Disc disc : discs) {
      System.out.println(++cnt + " [DISC " + disc.getOID() + "] " + disc.getDYEAR() + " " + disc.getDTITLE());
    }
    Util.leave(cnt);
  }

  public void discsEndsWithBeatles()
  {
    Util.enter("QBE: Disc ends with 'The Beatles'");

    Disc d = new Disc();
    d.setDTITLE("The Beatles*");

    ObjectSet<Disc> discs = gtm.queryByExample(d);
    Util.snapshot();
    int cnt = 0;
    for (Disc disc : discs) {
      System.out.println(++cnt + " [DISC " + disc.getOID() + "] " + disc.getDYEAR() + " " + disc.getDTITLE());
    }
    Util.leave(cnt);
  }

  public void discsContainsBeatles()
  {
    Util.enter("QBE: Disc contains 'Beatles'");

    Disc d = new Disc();
    d.setDTITLE("*Beatles*");

    ObjectSet<Disc> discs = gtm.queryByExample(d);
    Util.snapshot();
    int cnt = 0;
    for (Disc disc : discs) {
      System.out.println(++cnt + " [DISC " + disc.getOID() + "] " + disc.getDYEAR() + " " + disc.getDTITLE());
    }
    Util.leave(cnt);
  }

  public static void main(String[] args)
  {
    long t1 = System.currentTimeMillis();

    SimplePOQ test = new SimplePOQ();
    test.allAritsts();
    test.artistJohnLennon();
    test.albumYelloSubmarine();
    test.albumYelloSubmarine1970();
    test.albumYear1969();
    test.discsStartsWithBeatles1965();
    test.discsEndsWithBeatles();
    test.discsContainsBeatles();

    gtm.printCacheStatistics();

    System.out.println("Overall runtime is " + (System.currentTimeMillis() - t1 + " ms."));
  }
}
TOP

Related Classes of de.linwave.gtm.query.SimplePOQ

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.