Database Access - Data Access

By default, database queries in RapidClipse are performed in the data access layer (Project Management > Data Access). Thus, database queries are separated from UI entities and business logic. For each entity, a corresponding data access object (DAO) is available in the data access layer (standard when entities are created and imported). The DAO acts as the interface to the database. The database query itself is performed by using a custom method that is invoked on the DAO. This method queries the database and returns the query result. The DAO also provides some standard methods.

Standard query methods

  • Query all records related to the DAO object in use: .findAll ();

    List<Customer> allCustomers = new CustomerDAO().findAll();
    		
    for (Customer customer : allCustomers) {
    			...
    }
  • Query a particular object by using the primary key: .find(Object primaryKey).

    Customer specificCustomer = new CustomerDAO().find("SHG");
    String contactname = specificCustomer.getContactname();
  • Return a list of objects that fit the given example - .findByExample(Class entity, Object example)
    ATTENTION: Even the 0 or "" (empty string) default values are tested. Therefore, all values should be filled with the null value at a minimum.

    Customer exampleCustomer = new Customer();
    exampleCustomer.setCity("Musterhausen");
    exampleCustomer.setContacttitle("Herr");
    
    List<Customer> findByExample = new CustomerDAO().findByExample(Customer.class, exampleCustomer);
  • Manually abort the transaction with subsequent rollback: .rollback ().

    new CustomerDAO().rollback();
  • Save the created entities: .save (Object entity).

    Customer exampleCustomer = new Customer();
    exampleCustomer.setCity("Musterhausen");
    exampleCustomer.setContacttitle("Herr");
    		
    Customer savedCustomer = new CustomerDAO().save(exampleCustomer);

    or

    Customer exampleCustomer2 = new Customer();
    exampleCustomer2.setCity("Musterhausen2");
    
    Customer exampleCustomer3 = new Customer();
    exampleCustomer3.setCity("Musterhausen3");
    
    
    Customer exampleCustomer4 = new Customer();
    exampleCustomer4.setCity("Musterhausen4");
    		
    Customer savedCustomer = new CustomerDAO().save(exampleCustomer2, exampleCustomer3, exampleCustomer4);

Custom queries

XDEV Software Corp. - One Embarcadero Center, San Francisco, CA 94111, US
Copyright © 2015. XDEV Software Corp. All rights reserved.