com.jenkov.mrpersister.impl.mapping
Class ObjectMappingKey

java.lang.Object
  extended by com.jenkov.mrpersister.impl.mapping.ObjectMappingKey
All Implemented Interfaces:
IObjectMappingKey

public class ObjectMappingKey
extends java.lang.Object
implements IObjectMappingKey

This class is a fast implementation of an object mapping key. The reason it is fast is, that the id returned by getId() (an int) is used both in the hashCode() call and the equals(Object o) call. These two methods are used when the object mapping key is used in hash maps, as is the case with the default implementation of the object mapping cache. Using a string or some other class as the key may be slightly slower, since the hashCode() and the equals() calls may be slower than this implementation.

ObjectMappingKey instances can also contain an ICustomObjectMapper instance which will create, or assist in creating, the object mapping this ObjectMappingKey instance represents.

When creating object mapping keys, assign them to a constant in some class of yours, like the example below (reading user instances from the database):

public class ObjectMappingKeys{

   public USER_READ = ObjectMappingKey.createInstance(User.class, "User Read");
   public USER_INSERT = ObjectMappingKey.createInstance(User.class, "User Insert");
   public USER_UPDATE = ObjectMappingKey.createInstance(User.class, "User Update");
   public USER_UPDATE_LAST_LOGIN = ObjectMappingKey.createInstance(User.class, "User Update Last Login");
   public USER_UPDATE_PASSWORD = ObjectMappingKey.createInstance(User.class, "User Update Password");
   public USER_DEACTIVATE = ObjectMappingKey.createInstance(User.class, "User Deactivate");
   public USER_DELETE = ObjectMappingKey.createInstance(User.class, "User Delete");

}


Method Summary
static ObjectMappingKey createInstance(java.lang.Class objectClass)
          Creates an instance of ObjectMappingKey with the object class set only.
static ObjectMappingKey createInstance(java.lang.Class objectClass, ICustomObjectMapper mapper)
          Creates an instance of ObjectMappingKey with both object class and a custom object mapper set.
static ObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name)
          Creates an instance of ObjectMappingKey with both object class and name set.
static ObjectMappingKey createInstance(java.lang.Class objectClass, java.lang.String name, ICustomObjectMapper mapper)
          Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set.
static ObjectMappingKey createInstanceForAutoGeneratedColumns(java.lang.Class objectClass, java.lang.String[] columns)
          Creates an instance of ObjectMappingKey with both object class, and a custom object mapper set.
static ObjectMappingKey createInstanceForAutoGeneratedColumns(java.lang.Class objectClass, java.lang.String name, java.lang.String[] columns)
          Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set.
static ObjectMappingKey createInstanceForAutoGeneratedPrimaryKey(java.lang.Class objectClass)
          Creates an instance of ObjectMappingKey with both object class and a custom object mapper set.
static ObjectMappingKey createInstanceForAutoGeneratedPrimaryKey(java.lang.Class objectClass, java.lang.String name)
          Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set.
static ObjectMappingKey createInstanceForCustomTableAutoGeneratedColumns(java.lang.Class objectClass, java.lang.String[] columns, java.lang.String tableName)
          Creates an instance of ObjectMappingKey with both object class, table name, and a custom object mapper set.
static ObjectMappingKey createInstanceForCustomTableAutoGeneratedColumns(java.lang.Class objectClass, java.lang.String[] columns, java.lang.String tableName, java.lang.String name)
          Creates an instance of ObjectMappingKey with both object class, table name, name, and a custom object mapper set.
static ObjectMappingKey createInstanceForCustomTableAutoGeneratedPrimaryKey(java.lang.Class objectClass, java.lang.String tableName)
          Creates an instance of ObjectMappingKey with both object class, table name, and a custom object mapper set.
static ObjectMappingKey createInstanceForCustomTableAutoGeneratedPrimaryKey(java.lang.Class objectClass, java.lang.String tableName, java.lang.String name)
          Creates an instance of ObjectMappingKey with both object class, table name, name, and a custom object mapper set.
 boolean equals(java.lang.Object obj)
           
 ICustomObjectMapper getCustomObjectMapper()
           
 int getId()
          Returns the id of this object mapping key.
 java.lang.String getName()
          Returns the name of this object mapping key.
 java.lang.Class getObjectClass()
          Returns the class mapped by the object mapping this ObjectMappingKey instance is key for.
 int hashCode()
          Returns the hash code of this object mapping key.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getId

public int getId()
Returns the id of this object mapping key. This id is provided by the user at creation time and must be unique across all instances of ObjectMappingKey.

Specified by:
getId in interface IObjectMappingKey
Returns:
The id of this object mapping key.

getObjectClass

public java.lang.Class getObjectClass()
Returns the class mapped by the object mapping this ObjectMappingKey instance is key for. Setting the class for the object mapping key is optional. It is just a help for you to identify object mapping keys at runtime. Setting the class also enables the AbstractDao subclasses to automatically generate an object mapping for this object mapping key, if none is cached already.

Specified by:
getObjectClass in interface IObjectMappingKey
Returns:
The class mapped by the object mapping stored in the object mapping cache under this object mapping key.

getName

public java.lang.String getName()
Returns the name of this object mapping key. Names for object mapping keys are optional. They are just a help for you to identify method keys at runtime.

Specified by:
getName in interface IObjectMappingKey
Returns:
The name of this object mapping key as set by the user.

getCustomObjectMapper

public ICustomObjectMapper getCustomObjectMapper()
Specified by:
getCustomObjectMapper in interface IObjectMappingKey

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns the hash code of this object mapping key. Since the id of the object method key is unique, the id is also used as the hash code of the object mapping key instance.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code for this ObjectMappingKey instance.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

createInstance

public static ObjectMappingKey createInstance(java.lang.Class objectClass)
Creates an instance of ObjectMappingKey with the object class set only. A unique id will be assigned to the ObjectMappingKey before it is returned.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstance

public static ObjectMappingKey createInstance(java.lang.Class objectClass,
                                              java.lang.String name)
Creates an instance of ObjectMappingKey with both object class and name set. A unique id will be assigned to the ObjectMappingKey before it is returned.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
name - A describing name. Any name you choose.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstance

public static ObjectMappingKey createInstance(java.lang.Class objectClass,
                                              ICustomObjectMapper mapper)
Creates an instance of ObjectMappingKey with both object class and a custom object mapper set. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstance

public static ObjectMappingKey createInstance(java.lang.Class objectClass,
                                              java.lang.String name,
                                              ICustomObjectMapper mapper)
Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
name - A describing name. Any name you choose.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForAutoGeneratedColumns

public static ObjectMappingKey createInstanceForAutoGeneratedColumns(java.lang.Class objectClass,
                                                                     java.lang.String[] columns)
Creates an instance of ObjectMappingKey with both object class, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the columns array as auto generated. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForAutoGeneratedColumns

public static ObjectMappingKey createInstanceForAutoGeneratedColumns(java.lang.Class objectClass,
                                                                     java.lang.String name,
                                                                     java.lang.String[] columns)
Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the columns array as auto generated. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
name - A describing name. Any name you choose.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForCustomTableAutoGeneratedColumns

public static ObjectMappingKey createInstanceForCustomTableAutoGeneratedColumns(java.lang.Class objectClass,
                                                                                java.lang.String[] columns,
                                                                                java.lang.String tableName)
Creates an instance of ObjectMappingKey with both object class, table name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the columns array as auto generated, and return the given table name as the table to map the class to. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
tableName - The name of the table to map this class to.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForCustomTableAutoGeneratedColumns

public static ObjectMappingKey createInstanceForCustomTableAutoGeneratedColumns(java.lang.Class objectClass,
                                                                                java.lang.String[] columns,
                                                                                java.lang.String tableName,
                                                                                java.lang.String name)
Creates an instance of ObjectMappingKey with both object class, table name, name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the columns array as auto generated, and return the given table name as the table to map the class to. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
tableName - The name of the table to map this class to.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForAutoGeneratedPrimaryKey

public static ObjectMappingKey createInstanceForAutoGeneratedPrimaryKey(java.lang.Class objectClass,
                                                                        java.lang.String name)
Creates an instance of ObjectMappingKey with both object class, name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the primary key as auto generated. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
name - A describing name. Any name you choose.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForAutoGeneratedPrimaryKey

public static ObjectMappingKey createInstanceForAutoGeneratedPrimaryKey(java.lang.Class objectClass)
Creates an instance of ObjectMappingKey with both object class and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the primary key as auto generated. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForCustomTableAutoGeneratedPrimaryKey

public static ObjectMappingKey createInstanceForCustomTableAutoGeneratedPrimaryKey(java.lang.Class objectClass,
                                                                                   java.lang.String tableName,
                                                                                   java.lang.String name)
Creates an instance of ObjectMappingKey with both object class, table name, name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the primary key as auto generated. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
name - A describing name. Any name you choose.
Returns:
An ObjectMappingKey instance with the given name and object class set.

createInstanceForCustomTableAutoGeneratedPrimaryKey

public static ObjectMappingKey createInstanceForCustomTableAutoGeneratedPrimaryKey(java.lang.Class objectClass,
                                                                                   java.lang.String tableName)
Creates an instance of ObjectMappingKey with both object class, table name, and a custom object mapper set. The custom object mapper will be set internally by this factory method. The custom object mapper will mark all the columns in the primary key as auto generated, and map the class to the given table name. A unique id will be assigned to the ObjectMappingKey before it is returned. The ICustomObjectMapper will be used when creating an object mapping for this object mapping key.

When creating object mapping keys, assign them to a constant in some class of yours.

Parameters:
objectClass - The class mapped by the object mapping that this ObjectMappingKey instance is key for.
tableName - The name of the table to map that class to.
Returns:
An ObjectMappingKey instance with the given name and object class set.