org.azzyzt.jee.runtime.eao
Class IdTranslator

java.lang.Object
  extended by org.azzyzt.jee.runtime.eao.IdTranslator

public class IdTranslator
extends java.lang.Object

When a graph of new but connected objects is persisted, the DTOs can't be connected by each other's IDs, because at that time no object has an ID yet. Instead of real IDs we use temporary negative proxy ID values and translate them on the fly.

ID translation happens inside of the generated converters. MultiObjectSaver creates one instance of IdTranslator and then traverses the list of DTOs. For each DTO it creates or uses an already existing converter, passing the common translator into the converters. The DTOs are expected to be in an order such that no proxy ID is referenced, that is not already defined.

See Also:
MultiObjectSaver

Constructor Summary
IdTranslator()
           
 
Method Summary
 void addTranslation(java.lang.Number proxy, java.lang.Object value)
           
 java.lang.Object translate(java.lang.Number proxy)
          Translates a proxy ID to a real ID.
 java.lang.Object translate(java.io.Serializable embeddedId)
          Translates the IDs in an embedded ID.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdTranslator

public IdTranslator()
Method Detail

addTranslation

public void addTranslation(java.lang.Number proxy,
                           java.lang.Object value)
                    throws DuplicateProxyIdException
Parameters:
proxy - a negative proxy ID value
value - a positive real ID value
Throws:
DuplicateProxyIdException

translate

public java.lang.Object translate(java.lang.Number proxy)
                           throws InvalidProxyIdException
Translates a proxy ID to a real ID. If the proxy is null or positive, the proxy is returned. If no translation for a negative proxy value is found, an exception is thrown. This could be due to a wrong order of the DTO list.

Parameters:
proxy - a negative proxy ID value or null
Returns:
the translation or null
Throws:
InvalidProxyIdException

translate

public java.lang.Object translate(java.io.Serializable embeddedId)
                           throws InvalidProxyIdException,
                                  InvalidIdException
Translates the IDs in an embedded ID.

Parameters:
embeddedId - an embedded ID
Returns:
the same ID with ID fields translated
Throws:
InvalidProxyIdException
InvalidIdException