Package org.ujorm.orm

The ORM support.

See: Description

Package org.ujorm.orm Description

The ORM support.
logo

ORM module of the Ujorm

am easy to use implementation of the object-relation mapping
Why a new ORM mapping?
  • framework has a type safe query language which allows the java compiler find a syntax error similar like a 4GL language
  • never more a LazyInitialization exception though a lazy initialization is supported
  • no confusing proxy business objects
  • no list properties are supported but a special object called UjoIterator is designed for a collection. The UjoIterator provides a toList() method however
  • easy to configure the ORM model by java source code, optionaly by annotations or a XML file
  • very small framework without more library dependencies, the current size of the JAR file is around 160 kB
  • great performance mainly for the SQL SELECT statement
Some other features:
  • all persistent objects are based on the OrmUjo interface, namely on the OrmTable implementation
  • resources for ORM mapping can be a database table, view, or your own SQL SELECT
  • default ORM mapping is described by KeyProperties however there is possible overwrite the mapping by annotations and the annotations can be overwrited by a XML files
  • JDBC query parameters are passed by a question notation to the PreparedStatement for a high security
  • internal object cache is based on the WeakHashMap class so that large transactions does not cause any OutOfMemoryException
  • the API was inspired by ORM frameworks Cayenne and Hibernate

A sample of use

See how to create database and to how to INSERT an order with two items into database:
  OrmHandler.getInstance().loadDatabase(Database.class);

  Order order = new Order();
  order.setDate(new Date());
  order.setDescr("John's order");

  Item item1 = new Item();
  item1.setOrder(order);
  item1.setDescr("Yellow table");

  Item item2 = new Item();
  item2.setOrder(order);
  item2.setDescr("Green window");

  Session session = OrmHandler.getInstance().getSession();
  session.save(order);
  session.save(item1);
  session.save(item2);

  session.commit();
            
The next source code calls a SELECT by the UJO Criteria:
  Criterion<Order> criter1 = Criterion.where(Order.DESCR, "John's order");
  Criterion<Order> criter2 = Criterion.where(Order.DATE, Operator.LE, new Date());
  Criterion<Order> criterion = criter1.and(criter2);

  Session session = OrmHandler.getInstance().getSession();
  UjoIterator<Order> orders = session.createQuery(criterion).iterate();
  System.out.println("ORDER COUNT: " + orders.count()); // method calls SQL SELECT COUNT(*) in case the iterator can provide first item!

  for (Order order : orders) {
      String descr = order.getDescr();
      System.out.println("ORDER ROW: " + order + " // descr: " + descr);
  }
            
The next source code calls a SELECT by an UJO object relation:
  Session session = OrmHandler.getInstance().getSession();
  Database db = session.getDatabase();
  UjoIterator<Order> orders = db.get(Database.ORDERS);

  for (Order order : orders) {
      String descr = order.getDescr();
      System.out.println("Order: " + order + " // descr: " + descr);

      for (Item item : order.getItems()) {
          Long itemId = item.getId();
          String itemDescr = item.getDescr();
          System.out.println(" Item id: " + itemId + " descr: " + itemDescr);
      }
  }
            

More sources:

License:

Copyright 2015, Pavel Ponec