예제 #1
0
 public List<Comment> getMyComments(String categoryId) {
   String request = "SELECT FROM Comment WHERE category.@rid = " + categoryId;
   try (OObjectDatabaseTx database = getOObjectDatabaseTx()) {
     List<Comment> posts = database.query(new OSQLSynchQuery<Comment>(request));
     return detachList(posts);
   }
 }
예제 #2
0
  public static void main(String[] args) {
    OObjectDatabaseTx db = new OObjectDatabaseTx("remote:localhost/testdb").open("root", "root");

    // REGISTER THE CLASS ONLY ONCE AFTER THE DB IS OPEN/CREATED
    db.setAutomaticSchemaGeneration(true);
    db.getEntityManager().registerEntityClasses("ch.rasc.playground.orientdb.domain");

    // CREATE A NEW PROXIED OBJECT AND FILL IT
    Account account = db.newInstance(Account.class);
    account.setName("Luke");
    account.setSurname("Skywalker");

    City rome = db.newInstance(City.class, "Rome", db.newInstance(Country.class, "Italy"));
    account.getAddresses().add(new Address("Residence", rome, "Piazza Navona, 1"));

    db.save(account);

    // CREATE A NEW OBJECT AND FILL IT
    account = new Account();
    account.setName("Luke");
    account.setSurname("Skywalker");

    rome = new City("Rome", new Country("Italy"));
    account.getAddresses().add(new Address("Residence", rome, "Piazza Navona, 1"));

    // SAVE THE ACCOUNT: THE DATABASE WILL SERIALIZE THE OBJECT AND GIVE THE PROXIED
    // INSTANCE
    account = db.save(account);

    List<Account> accounts =
        db.query(new OSQLSynchQuery<Account>("select from Account where name like 'L%'"));
    for (Account acc : accounts) {
      Account detached = db.detach(acc, true);
      System.out.println(detached);
      System.out.println(detached.getRid());
    }
  }