org.ujorm.implementation.orm
Class OrmTable<U extends OrmTable>

java.lang.Object
  extended by org.ujorm.extensions.SuperAbstractUjo
      extended by org.ujorm.extensions.AbstractUjo
          extended by org.ujorm.implementation.quick.QuickUjo
              extended by org.ujorm.implementation.orm.OrmTable<U>
All Implemented Interfaces:
Serializable, UjoCloneable, UjoTextable, ExtendedOrmUjo<U>, OrmUjo, Ujo
Direct Known Subclasses:
OrmTableLockable

public abstract class OrmTable<U extends OrmTable>
extends QuickUjo
implements ExtendedOrmUjo<U>

This abstract implementation of the OrmUjo interface is situable for implementation the persistent entities.
Instances of the OrmTable can be serializable, but you need to know that only business data will be transferred, the session and property changes will not be passed.
The sample of use:

  /** Using INSERT */
  public void useCreateItem() {

      Order order = new Order();
      order.set(Order.DATE, new Date());
      order.set(Order.DESCR, "John's order");

      Item item = new Item();
      item.set(Item.ORDER, order);
      item.set(Item.DESCR, "Yellow table");

      Session session = OrmHandler.getInstance().getSession();
      session.save(order);
      session.save(item);
      session.commit();
  }

See Also:
RelationToMany, UjoIterator, Serialized Form

Constructor Summary
OrmTable()
           
 
Method Summary
<UJO extends U,VALUE>
VALUE
get(Key<UJO,VALUE> key)
          Getter based on Key implemeted by a pattern UjoExt
protected static
<UJO extends Ujo,FACTORY extends KeyFactory<UJO>>
FACTORY
newCamelFactory(Class<? extends UJO> ujoClass)
          Create a factory with a cammel-case Key name generator.
protected static
<UJO extends Ujo,FACTORY extends KeyFactory<UJO>>
FACTORY
newFactory(Class<? extends UJO> ujoClass)
          Create a base factory Key name generator where key name is the same as its field name.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKey()
          A Property Factory creates new key and assigns a next key index.
static
<UJO extends QuickUjo,VALUE>
Property<UJO,VALUE>
newKey(Key p)
          Returns a new instance of key where the default value is null.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKey(String name)
          A Property Factory creates new key and assigns a next key index.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKey(String name, Class<VALUE> type, VALUE defaultValue, int index, boolean lock)
          A Property Factory creates new key and assigns a next key index.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKey(String name, VALUE defaultValue)
          A Property Factory creates new key and assigns a next key index.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKey(VALUE value)
          A Property Factory creates new key and assigns a next key index.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newKeyDefault(VALUE defaultValue)
          A Property Factory creates new key and assigns a next key index.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty()
          Deprecated. Use the method newKey(...)
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(Class<VALUE> type)
          Deprecated. Use rather a method QuickUjo.newProperty() instead of this,
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(Class<VALUE> type, VALUE value)
          Deprecated. 
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(String name)
          Deprecated. Use the method newKey(...)
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(String name, Class<VALUE> type)
          Deprecated. Use rather a method QuickUjo.newProperty(java.lang.String) instead of this.
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(String name, Class<VALUE> type, VALUE defaultValue, int index, boolean lock)
          Deprecated. 
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(String name, VALUE value)
          Deprecated. Use the method newKey(...)
protected static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newProperty(VALUE value)
          Deprecated. Use the method newKey(...)
protected static
<UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo>
RelationToMany<UJO,ITEM>
newRelation()
          A PropertyIterator Factory creates an new key and assign a next index.
protected static
<UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo>
RelationToMany<UJO,ITEM>
newRelation(Class<ITEM> type)
          Deprecated. use the newRelation() instead of this.
protected static
<UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo>
RelationToMany<UJO,ITEM>
newRelation(String name)
          A PropertyIterator Factory creates an new key and assign a next index.
protected static
<UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo>
RelationToMany<UJO,ITEM>
newRelation(String name, Class<ITEM> type)
          Deprecated. use the newRelation(java.lang.String) instead of this.
 boolean readAuthorization(UjoAction action, Key key, Object value)
          Test an authorization of the action.
 Key[] readChangedProperties(boolean clear)
          Returns keys of changed values in a time when any session is assigned.
<UJO extends U>
ForeignKey
readFK(Key<UJO,? extends OrmUjo> key)
          Read the foreign key.
 Session readSession()
          Read a session
<UJO extends U,VALUE>
U
set(Key<UJO,VALUE> key, VALUE value)
          Setter based on Key.
 void writeSession(Session session)
          Write a session
 void writeValue(Key<?,?> key, Object value)
          A method for an internal use only.
 
Methods inherited from class org.ujorm.implementation.quick.QuickUjo
newListKey, newListKey, newListProperty, newListProperty, newListProperty, newListProperty
 
Methods inherited from class org.ujorm.extensions.AbstractUjo
readValue
 
Methods inherited from class org.ujorm.extensions.SuperAbstractUjo
clone, equals, init, init, readKeys, readUjoManager, readValueString, toString, writeValueString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ujorm.Ujo
readKeys, readValue
 

Constructor Detail

OrmTable

public OrmTable()
Method Detail

readSession

public Session readSession()
Read a session

Specified by:
readSession in interface OrmUjo

writeSession

public void writeSession(Session session)
Write a session

Specified by:
writeSession in interface OrmUjo

writeValue

public void writeValue(Key<?,?> key,
                       Object value)
A method for an internal use only.

Specified by:
writeValue in interface Ujo
Overrides:
writeValue in class AbstractUjo

readChangedProperties

public Key[] readChangedProperties(boolean clear)
Returns keys of changed values in a time when any session is assigned. The method is used by a SQL UPDATE statement to update assigned values only. Implementation tip: create a new property type of Set and in the method writeValue assign the current Key always.

Specified by:
readChangedProperties in interface OrmUjo
Parameters:
clear - True value clears all the key changes.
Returns:
Key array of the modified values.

get

public final <UJO extends U,VALUE> VALUE get(Key<UJO,VALUE> key)
Getter based on Key implemeted by a pattern UjoExt


set

public final <UJO extends U,VALUE> U set(Key<UJO,VALUE> key,
                                         VALUE value)
Setter based on Key. Type of value is checked in the runtime. The method was implemented by a pattern UjoExt.


readAuthorization

public boolean readAuthorization(UjoAction action,
                                 Key key,
                                 Object value)
Test an authorization of the action.

Specified by:
readAuthorization in interface Ujo
Overrides:
readAuthorization in class SuperAbstractUjo

readFK

public <UJO extends U> ForeignKey readFK(Key<UJO,? extends OrmUjo> key)
                  throws IllegalStateException
Read the foreign key. This is useful to obtain the foreign key value without (lazy) loading the entire object. If the lazy object is loaded, the method will need the Session to build the ForeignKey instance.
NOTE: The method is designed for developers only, the Ujorm doesn't call it newer.

Specified by:
readFK in interface ExtendedOrmUjo<U extends OrmTable>
Parameters:
key - Must be direct key only (Key.isDirect()==true)
Returns:
If no related object is available, then the result has the NULL value.
Throws:
IllegalStateException - Method throws an exception for a wrong key type.
NullPointerException - Method throws an exception if a Session is missing after a lazy initialization of the key.

newCamelFactory

protected static <UJO extends Ujo,FACTORY extends KeyFactory<UJO>> FACTORY newCamelFactory(Class<? extends UJO> ujoClass)
Create a factory with a cammel-case Key name generator.
Note: after declarations of all properties is recommend to call method KeyFactory.close();


newFactory

protected static <UJO extends Ujo,FACTORY extends KeyFactory<UJO>> FACTORY newFactory(Class<? extends UJO> ujoClass)
Create a base factory Key name generator where key name is the same as its field name.
Note: after declarations of all properties is recommend to call method KeyFactory.close();


newRelation

@Deprecated
protected static <UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo> RelationToMany<UJO,ITEM> newRelation(String name,
                                                                                                                          Class<ITEM> type)
Deprecated. use the newRelation(java.lang.String) instead of this.

A PropertyIterator Factory creates an new key and assign a next index.


newRelation

protected static <UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo> RelationToMany<UJO,ITEM> newRelation(String name)
A PropertyIterator Factory creates an new key and assign a next index.


newRelation

@Deprecated
protected static <UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo> RelationToMany<UJO,ITEM> newRelation(Class<ITEM> type)
Deprecated. use the newRelation() instead of this.

A PropertyIterator Factory creates an new key and assign a next index.


newRelation

protected static <UJO extends ExtendedOrmUjo,ITEM extends ExtendedOrmUjo> RelationToMany<UJO,ITEM> newRelation()
A PropertyIterator Factory creates an new key and assign a next index.


newKey

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKey()
A Property Factory creates new key and assigns a next key index.


newKey

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKey(String name)
A Property Factory creates new key and assigns a next key index.


newKey

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKey(String name,
                                                                    VALUE defaultValue)
A Property Factory creates new key and assigns a next key index.


newKeyDefault

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKeyDefault(VALUE defaultValue)
A Property Factory creates new key and assigns a next key index.


newKey

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKey(String name,
                                                                    Class<VALUE> type,
                                                                    VALUE defaultValue,
                                                                    int index,
                                                                    boolean lock)
A Property Factory creates new key and assigns a next key index.


newKey

protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newKey(VALUE value)
A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newKey

public static <UJO extends QuickUjo,VALUE> Property<UJO,VALUE> newKey(Key p)
Returns a new instance of key where the default value is null.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(String name,
                                                                                    Class<VALUE> type)
Deprecated. Use rather a method QuickUjo.newProperty(java.lang.String) instead of this.

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(String name)
Deprecated. Use the method newKey(...)

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(String name,
                                                                                    VALUE value)
Deprecated. Use the method newKey(...)

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(Class<VALUE> type)
Deprecated. Use rather a method QuickUjo.newProperty() instead of this,

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(String name,
                                                                                    Class<VALUE> type,
                                                                                    VALUE defaultValue,
                                                                                    int index,
                                                                                    boolean lock)
Deprecated. 


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(VALUE value)
Deprecated. Use the method newKey(...)

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty(Class<VALUE> type,
                                                                                    VALUE value)
Deprecated. 


newProperty

@Deprecated
protected static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newProperty()
Deprecated. Use the method newKey(...)

A Property Factory creates new key and assigns a next key index.
Warning: Method does not lock the key so you must call AbstractUjo.init(..) method after initialization!



Copyright 2013, Pavel Ponec