easierjava
gplv3-88x31 (1K)
Open Source Licensed with GPL.
Anyone Can Use It, In Any Situation.

Since 2005


Easy Java Persistence (EJP)

EJP can handle anything you need to do!

 

EJP is a powerful and easy to use relational database persistence API for Java. EJP's main features include:

  • more functionality than JPA (and a lot easier)
  • performance equal to or better then any JPA implementation
  • a footprint a fraction the size of any other (< 300k)
  • automatic object/relational mapping (A-O/RM)
  • automatic handling of all associations
  • automatic persistence tracking
  • commercially supported software
  • and a lot more (see features)

EJP has no need for mapping annotations or XML configuration, and there is no need to extend any classes or implement any interfaces. You truly do use your Plain Old Java Objects (POJOs). EJP is, by far, the easiest persistence API available for Java. And it can handle anything you need to do!

EJP is this easy (no annotations or configuration):


    public static void main(String[] args)
      {
        // One of many ways to connect to your database
        DatabaseManager dbm = DatabaseManager.getDatabaseManager("com.mysql.jdbc.Driver", 
                                                                 "jdbc:mysql://localhost/ejp_example");
     
        dbm.saveObject(new Customer("Smith", "John"));
     
        Customer customer;
     
        if ((customer = dbm.loadObject(new Customer("Smith"))) != null)
          {
            customer.getSupport().add(new Support(...));
     
            dbm.saveObject(customer);
          }
     
        Collection<Customer> list = dbm.loadObjects(new ArrayList<Customer>(), Customer.class);
        ...
      }

It's used with normal class definitions like the following:


    public class Customer
      {
        String firstName, lastName;
        List<Support> support;
        List<Order> orders;
        ...
        public Customer(String lastName) { this.lastName = lastName; }
        ...
        public getFirstName() { return firstName; }
        public setFirstName(String firstName) { this.firstName = firstName; }
        public getLastName() { return lastName; }
        public setLastName(String lastName) { this.lastName = lastName; }
        ...
        // Associations (automatic)
        public List<Support> getSupport() { return support; }
        public void setSupport(List<Support> support) { this.support = support; }
        public List<Order> getOrders() { return orders; }
        public void setOrders(List<Order> orders) { this.orders = orders; }
        ...
      }

That's it! No configuration and no annotation.

Easy Java Persistence (EJP)

  • Automatic object-relational mapping (A-O/RM)
  • Automatic tracking of object persistence
  • Mapping is automatic; there is no configuration, or annotation required
  • All associations are automatic
  • Handles associations with single instance, arrays, and collections
  • Automatic support for join inheritance
  • Support for single table inheritance and concrete table inheritance
  • Objects are isolated from database changes, and vice versa
  • Full support for major databases including: MySQL, DB2, Oracle, Derby, HSQL, PostgreSQL, H2, and more
  • Object-oriented queries, inserts, updates, deletes and more
  • Intermix objects with SQL, and use object properties in SQL fragments
  • Full support for batch updates
  • Full support for database transactions
  • Supports any JDBC source including DriverManager, JNDI, and DataSource
  • Support for third-party connection pooling (DBCP, C3PO, etc.)
  • No SQL required for queries, inserts, updates, deletes
  • Uses JDBC with access to underlying connection, statement and result set
  • Implements ListIterator and Iterable for object-oriented iteration through data
  • Multiple utilities for loading data into collections and maps
  • All JDBC functionality is supported
  • and lots more!
gplv3-88x31 (1K)
Open Source Licensed with GPL.
Anyone Can Use It, In Any Situation.

Since 2005

Easy Java Persistence (EJP)

EJP can handle anything you need to do!



EasierJava Purchase Options

Please use the support form to initiate any support requests you may have and/or to notify us of any extra needs regarding your purchase. Thank you.

Support - Please be pro-active and report any issues and/or requests. Thank you!

Note: If you don't receive a response within one business day, it's likely that your email address was incorrect.

EasierJava Purchase Options

Please use the support form to initiate any support requests you may have and/or to notify us of any extra needs regarding your purchase. Thank you.

Simple Example of EJP

With the exception of the imports and ellipsis (...), the following is a complete, compilable, and runable program example. For the purposes of this example, the ellipsis are being used to reduce non-essential information. The class definitions and database table creation scripts follow. There are no mapping requirements, no XML and no Annotations.

public class DatabaseExample
  {
    public DatabaseExample(DatabaseManager dbm) throws DatabaseException
      {
        // Inserting customer with associations
        Customer customer = new Customer("deisenhower", ...);

        customer.getSupport().add(new Support("Request", ...));
        customer.getSupport().add(new Support("Response", ...));
        customer.getSupport().add(new Support("Request", ...));

        customer.getOrders().add(new Order("Dwight D. Eisenhower Dollar", ...));
        customer.getOrders().add(new Order("Susan B. Anthony Dollar", ...));

        // Saving within an automatic transaction (covers all relationships)
        dbm.saveObject(customer);

        // Load based on information contained in classes
        customer = dbm.loadObject(Customer.class, "where :customerId like 'tjef%'");
        System.out.println("\ncustomerId = " + customer.getCustomerId());

        // Load a collection of objects from the database
        Collection<Customer> c = dbm.loadObjects(new ArrayList<Customer>(), Customer.class);

        for (Customer customer2 : c)
          System.out.println("customerId = " + customer2.getCustomerId());
      }

    public static void main(String[] args) throws DatabaseException
      {
        DatabaseManager dbm = null;

        DatabaseManager.setLogLevel(Level.OFF);

        try
          {
            dbm = DatabaseManager.getDatabaseManager("example");

            new DatabaseExample(dbm);
          }
        finally
          {
            // Also closes any open Databases
            dbm.close();  // optional
          }
      }

    /*
     * The following are normal class definitions that
     * automatically map to your database
     */
     
    public static class Customer
      {
        private String customerId, password, firstName, lastName, companyName, email;
        private List<Support> support = new ArrayList<Support>();
        private List<Order> orders = new ArrayList<Order>();

        public Customer() {}

        public Customer(String customerId)
          {
            this.customerId = customerId;
          }

        public Customer(String customerId, String password, String firstName, 
                       String lastName, String companyName, String email)
          {
            this.customerId = customerId;
            this.password = password;
            this.firstName = firstName;
            this.lastName = lastName;
            this.companyName = companyName;
            this.email = email;
          }

        public String getCustomerId() { return customerId; }
        public void setCustomerId(String id) { customerId = id; }
        public String getPassword() { return password; }
        public void setPassword(String passwd) { password = passwd; }
        public String getFirstName() { return firstName; }
        public void setFirstName(String fName) { firstName = fName; }
        public String getLast() { return lastName; }
        public void setLast(String lName) { lastName = lName; }
        public String getCompanyName() { return companyName; }
        public void setCompanyName(String name) { companyName = name; }
        public String getEmail() { return email; }
        public void setEmail(String email) { this.email = email; }

        // Associations
        public List<Support> getSupport() { return support; }
        public void setSupport(List<Support> support) { this.support = support; }
        public List<Order> getOrders() { return orders; }
        public void setOrders(List<Order> orders) { this.orders = orders; }
      }
    
    public static class Order
      {
        // keys are all handled behind the scenes; map them if needed
        //private Long orderId;
        private Integer quantity;
        private Double price;
        private String product, status; //customerId,

        public Order() {}

        public Order(String product, Integer quantity, Double price, String status)
          {
            this.product = product;
            this.quantity = quantity;
            this.price = price;
            this.status = status;
          }

        // keys are all handled behind the scenes; map them if needed
    
        //public Long getOrderId() { return orderId; }
        //public void setOrderId(Long orderId) { this.orderId = orderId; }
        //public String getCustomerId() { return customerId;}
        //public void setCustomerId(String customerId) { this.customerId = customerId; }
        public String getProduct() { return product; }
        public void setProduct(String product) { this.product = product; }
        public Integer getQuantity() { return quantity; }
        public void setQuantity(Integer quantity) { this.quantity = quantity; }
        public Double getPrice() { return price; }
        public void setPrice(Double price) { this.price = price; }
        public String getStatus() { return status; }
        public void setStatus(String status) { this.status = status; }
      }
      
    public static class Support
      {
        // keys are all handled behind the scenes; map them if needed
        //private Long supportId;
        private String code, status, phone, email, request; //customerId, 

        public Support() {}

        public Support(String code, String status, String phone, 
                       String email, String request)
          {
            this.code = code;
            this.status = status;
            this.phone = phone;
            this.email = email;
            this.request = request;
          }

        // keys are all handled behind the scenes; map them if needed
    
        //public Long getSupportId() { return supportId; }
        //public void setSupportId(Long id) { supportId = id; }
        //public String getCustomerId() { return customerId; }
        //public void setCustomerId(String id) { customerId = id; }
        public String getCode() { return code; }
        public void setCode(String code) { this.code = code; }
        public String getStatus() { return status; }
        public void setStatus(String status) { this.status = status; }
        public String getPhone() { return phone; }
        public void setPhone(String phone) { this.phone = phone; }
        public String getEmail() { return email; }
        public void setEmail(String email) { this.email = email; }
        public String getRequest() { return request; }
        public void setRequest(String request) { this.request = request; }
      }
  }

# MySQL database creation

CREATE TABLE CUSTOMERS
  (
    CUSTOMER_ID varchar(40) NOT NULL PRIMARY KEY,
    PASSWORD varchar(40) NOT NULL,
    FIRST_NAME varchar(40) NOT NULL,
    LAST_NAME varchar(60) NOT NULL,
    COMPANY_NAME varchar(60),
    EMAIL varchar(255),
    CREATED timestamp NOT NULL default CURRENT_TIMESTAMP
  );

CREATE TABLE ORDERS
  (
    ORDER_ID int(11) NOT NULL auto_increment PRIMARY KEY,
    CUSTOMER_ID varchar(40) NOT NULL,
    PRODUCT varchar(40) NOT NULL,
    QUANTITY int(11) NOT NULL,
    PRICE double NOT NULL,
    STATUS varchar(20) NOT NULL default 'unverified',
    created timestamp NOT NULL default CURRENT_TIMESTAMP,
    FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS (CUSTOMER_ID) ON DELETE CASCADE
  );

CREATE TABLE SUPPORT
  (
    SUPPORT_ID int(11) NOT NULL auto_increment PRIMARY KEY,
    CUSTOMER_ID varchar(40) NOT NULL,
    CODE varchar(10) NOT NULL,
    STATUS varchar(20) NOT NULL,
    PHONE varchar(20),
    EMAIL varchar(255),
    REQUEST varchar(255) NOT NULL,
    CREATED timestamp NOT NULL default CURRENT_TIMESTAMP,
    FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS (CUSTOMER_ID) ON DELETE CASCADE
  );

In-Depth Example of EJP

With the exception of the imports and ellipsis (...), the following is a complete, compilable, and runable program example. For the purposes of this example, the ellipsis are being used to reduce non-essential information. The class definitions and database table creation scripts follow. There are no mapping requirements, no XML and no Annotations.

public class DatabaseExample
  {
    public DatabaseExample(DatabaseManager dbm) throws DatabaseException
      {
        // Inserting customer with associations
        Customer customer = new Customer("deisenhower", ...);

        customer.getSupport().add(new Support("Request", ...));
        customer.getSupport().add(new Support("Response", ...));
        customer.getSupport().add(new Support("Request", ...));

        customer.getOrders().add(new Order("Dwight D. Eisenhower Dollar", ...));
        customer.getOrders().add(new Order("Susan B. Anthony Dollar", ...));

        // Saving within an automatic transaction (covers all relationships)
        dbm.saveObject(customer);

        // Add an association and update
        customer.getSupport().add(new Support("Response", ...));

        dbm.saveObject(customer);

        // Saving within a transaction manager
        new TransactionManager(dbm)
          {
            public void run() throws Exception
              {
                // Inserting individually using the
                // TransactionManager's saveObject() and deleteObject()
                saveObject(new Customer("tjefferson", ...));
                saveObject(new Support("tjefferson", ...));
                saveObject(new Order("tjefferson", ...));

                // Insert new customer only
                Customer customer = new Customer("fdroosevelt", ...);
                
                saveObject(customer);
                
                // Add associations and update
                customer.getSupport().add(new Support("fdroosevelt", ...));
                customer.getOrders().add(new Order("fdroosevelt", ...));
                
                saveObject(customer);

                // Can still freely use commit, savepoint and rollback
                commit();

                Savepoint savepoint = null;
                
                if (supportsSavepoints())
                  savepoint = setSavepoint();

                customer = new Customer("gwashington", ...);
                customer.getSupport().add(new Support("gwashington", ...));
                customer.getOrders().add(saveObject(new Order("gwashington", ...));
                
                saveObject(customer);
                
                if (supportsSavepoints())
                  rollback(savepoint);

                // Same as saveObject()
                customer = new Customer("jkennedy", ...);
                
                customer.getSupport().add(new Support("jkennedy", ...));
                customer.getSupport().add(new Support("jkennedy", ...));
                customer.getOrders().add(new Order("jkennedy", ...));
                
                getDatabase().saveObject(customer);
              }
          }.executeTransaction();
        
        /*
         * The ejp.DatabaseManager way to load objects
         */
        
        // Load based on information contained in classes
        customer = dbm.loadObject(Customer.class, "where :customerId like 'tjef%'");
        System.out.println("\ncustomerId = " + customer.getCustomerId());

        // or Load based on information contained in objects
        customer = dbm.loadObject(new Customer("tjef%"));
        System.out.println("customerId = " + customer.getCustomerId());
        
        // or with variable argument parameters
        customer = dbm.loadObject(Customer.class, "where :customerId like ?", "tjef%");
        System.out.println("customerId = " + customer.getCustomerId() + "\n");
        
        // Load a collection of objects from the database
        Collection<Customer> c = dbm.loadObjects(new ArrayList<Customer>(), Customer.class);

        for (Customer customer2 : c)
          System.out.println("customerId = " + customer2.getCustomerId());

        System.out.println();
        
        /*
         * The ejp.Database way to load objects
         */
        
        Database db = dbm.getDatabase();

        try
          {
            // Query all
            Result<Customer> result = db.queryObject(Customer.class, "order by :lastName");

            // Result is Iterable
            for (Customer customer3 : result)
              {
                System.out.println(customer3);
              }

            // ejp.Result is a cursor
            // and can be closed to free the resource
            result.close();

            // or
            
            result = db.queryObject(Customer.class);
            
            // Print and delete
            while (result.hasNext() && (customer = result.next()) != null)
              {
                System.out.println(customer);
                db.deleteObject(customer);
              }
            
            result.close();
          }
        finally
          {
            // Also closes any open results
            db.close();
          }
      }

    public static void main(String[] args) throws DatabaseException
      {
        DatabaseManager dbm = null;

        DatabaseManager.setLogLevel(Level.OFF);

        try
          {
            dbm = DatabaseManager.getDatabaseManager("example");

            new DatabaseExample(dbm);
          }
        finally
          {
            // Also closes any open Databases
            dbm.close();  // optional
          }
      }

    /*
     * The following are normal class definitions that
     * automatically map to your database
     */
     
    public static class Customer
      {
        private String customerId, password, firstName, lastName, companyName, email;
        private List<Support> support = new ArrayList<Support>();
        private List<Order> orders = new ArrayList<Order>();

        public Customer() {}

        public Customer(String customerId)
          {
            this.customerId = customerId;
          }

        public Customer(String customerId, String password, String firstName, 
                       String lastName, String companyName, String email)
          {
            this.customerId = customerId;
            this.password = password;
            this.firstName = firstName;
            this.lastName = lastName;
            this.companyName = companyName;
            this.email = email;
          }

        public String getCustomerId() { return customerId; }
        public void setCustomerId(String id) { customerId = id; }
        public String getPassword() { return password; }
        public void setPassword(String passwd) { password = passwd; }
        public String getFirstName() { return firstName; }
        public void setFirstName(String fName) { firstName = fName; }
        public String getLast() { return lastName; }
        public void setLast(String lName) { lastName = lName; }
        public String getCompanyName() { return companyName; }
        public void setCompanyName(String name) { companyName = name; }
        public String getEmail() { return email; }
        public void setEmail(String email) { this.email = email; }

        // Associations
        public List<Support> getSupport() { return support; }
        public void setSupport(List<Support> support) { this.support = support; }
        public List<Order> getOrders() { return orders; }
        public void setOrders(List<Order> orders) { this.orders = orders; }
      }
    
    public static class Order
      {
        // keys are all handled behind the scenes; map them if needed
        //private Long orderId;
        private Integer quantity;
        private Double price;
        private String product, status; //customerId,

        public Order() {}

        public Order(String product, Integer quantity, Double price, String status)
          {
            this.product = product;
            this.quantity = quantity;
            this.price = price;
            this.status = status;
          }

        // keys are all handled behind the scenes; map them if needed
    
        //public Long getOrderId() { return orderId; }
        //public void setOrderId(Long orderId) { this.orderId = orderId; }
        //public String getCustomerId() { return customerId;}
        //public void setCustomerId(String customerId) { this.customerId = customerId; }
        public String getProduct() { return product; }
        public void setProduct(String product) { this.product = product; }
        public Integer getQuantity() { return quantity; }
        public void setQuantity(Integer quantity) { this.quantity = quantity; }
        public Double getPrice() { return price; }
        public void setPrice(Double price) { this.price = price; }
        public String getStatus() { return status; }
        public void setStatus(String status) { this.status = status; }
      }
      
    public static class Support
      {
        // keys are all handled behind the scenes; map them if needed
        //private Long supportId;
        private String code, status, phone, email, request; //customerId, 

        public Support() {}

        public Support(String code, String status, String phone, 
                       String email, String request)
          {
            this.code = code;
            this.status = status;
            this.phone = phone;
            this.email = email;
            this.request = request;
          }

        // keys are all handled behind the scenes; map them if needed
    
        //public Long getSupportId() { return supportId; }
        //public void setSupportId(Long id) { supportId = id; }
        //public String getCustomerId() { return customerId; }
        //public void setCustomerId(String id) { customerId = id; }
        public String getCode() { return code; }
        public void setCode(String code) { this.code = code; }
        public String getStatus() { return status; }
        public void setStatus(String status) { this.status = status; }
        public String getPhone() { return phone; }
        public void setPhone(String phone) { this.phone = phone; }
        public String getEmail() { return email; }
        public void setEmail(String email) { this.email = email; }
        public String getRequest() { return request; }
        public void setRequest(String request) { this.request = request; }
      }
  }

# MySQL database creation

CREATE TABLE CUSTOMERS
  (
    CUSTOMER_ID varchar(40) NOT NULL PRIMARY KEY,
    PASSWORD varchar(40) NOT NULL,
    FIRST_NAME varchar(40) NOT NULL,
    LAST_NAME varchar(60) NOT NULL,
    COMPANY_NAME varchar(60),
    EMAIL varchar(255),
    CREATED timestamp NOT NULL default CURRENT_TIMESTAMP
  );

CREATE TABLE ORDERS
  (
    ORDER_ID int(11) NOT NULL auto_increment PRIMARY KEY,
    CUSTOMER_ID varchar(40) NOT NULL,
    PRODUCT varchar(40) NOT NULL,
    QUANTITY int(11) NOT NULL,
    PRICE double NOT NULL,
    STATUS varchar(20) NOT NULL default 'unverified',
    created timestamp NOT NULL default CURRENT_TIMESTAMP,
    FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS (CUSTOMER_ID) ON DELETE CASCADE
  );

CREATE TABLE SUPPORT
  (
    SUPPORT_ID int(11) NOT NULL auto_increment PRIMARY KEY,
    CUSTOMER_ID varchar(40) NOT NULL,
    CODE varchar(10) NOT NULL,
    STATUS varchar(20) NOT NULL,
    PHONE varchar(20),
    EMAIL varchar(255),
    REQUEST varchar(255) NOT NULL,
    CREATED timestamp NOT NULL default CURRENT_TIMESTAMP,
    FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS (CUSTOMER_ID) ON DELETE CASCADE
  );