Ejemplo n.º 1
0
  public static void mains(String[] args)
      throws ClassNotFoundException, SQLException, ActiveRecordException {
    // Register models
    Registration.register(Book.class);
    Registration.register(Author.class);

    // Register activerecord property binders
    ActiveRecordPropertyRegister.add("java.lang.String", new StringProperty());
    ActiveRecordPropertyRegister.add("java.lang.Integer", new IntegerProperty());
    ActiveRecordPropertyRegister.add(
        "jcube.activerecord.main.ActiveRecord", new ActiveRecordReferenceProperty());

    Connection.establish();

    Book book = new Book();
    Book foundBook = book.find().first();
    System.out.println("foundBook.id " + foundBook.id);
    System.out.println("foundBook.name " + foundBook.name);
    System.out.println("foundBook.author.id " + foundBook.author.id);
    System.out.println("foundBook.author.name " + foundBook.author.name);
    System.out.println("foundBook.another_book.id " + foundBook.another_book.id);
    System.out.println("foundBook.another_book.name " + foundBook.another_book.name);

    java.sql.Connection connection = Connection.getConnection();
    connection.close();
    // Connection.closePool();

  }
 @Test
 public void ModelsClass() {
   assertFalse("Class is not registred", Registration.isRegistered(Author.class));
   Registration.get(Author.class);
   assertTrue("Class is registred", Registration.isRegistered(Author.class));
 }
 @Test
 public void RegisterModels() {
   assertFalse("Class is not registred", Registration.isRegistered(Book.class));
   Registration.register(Book.class);
   assertTrue("Class is registred", Registration.isRegistered(Book.class));
 }