Cumulus4j API
(1.0.0)

org.cumulus4j.store.model
Class DataEntry

java.lang.Object
  extended by org.cumulus4j.store.model.DataEntry
All Implemented Interfaces:
StoreCallback

public class DataEntry
extends Object
implements StoreCallback

Persistent container holding an entity's data in encrypted form.

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Constructor Summary
protected DataEntry()
          Internal constructor.
  DataEntry(ClassMeta classMeta, String objectID)
          Create an instance of DataEntry.
 
Method Summary
 boolean equals(Object obj)
           
 ClassMeta getClassMeta()
           Get the type of the entity persisted in this container.
static DataEntry getDataEntry(PersistenceManager pmData, ClassMeta classMeta, String objectID)
          Get the DataEntry identified by the given type and JDO/JPA-object-ID.
static DataEntry getDataEntry(PersistenceManager pmData, long dataEntryID)
          Get the DataEntry identified by the specified dataEntryID or null if no such instance exists.
 long getDataEntryID()
          Get the single primary key field (= object-identifier) of DataEntry.
static Long getDataEntryID(PersistenceManager pmData, ClassMeta classMeta, String objectID)
           Get the dataEntryID of the DataEntry identified by the given type and JDO/JPA-object-ID.
static Set<Long> getDataEntryIDsNegated(PersistenceManager pmData, ClassMeta classMeta, String notThisObjectID)
           Get the dataEntryIDs of all those DataEntry instances which do not match the given type and JDO/JPA-object-ID.
 long getKeyID()
          Get the identifier of the encryption-key used to encrypt the value.
 String getObjectID()
           Get the String-representation of the entity's identifier.
 byte[] getValue()
          Get the encrypted data of an entity.
 int hashCode()
           
 void jdoPreStore()
           
 void setKeyID(long keyID)
          Set the identifier of the encryption-key used to encrypt the value.
 void setValue(byte[] value)
          Set the encrypted data of an entity.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataEntry

protected DataEntry()
Internal constructor. This exists only for JDO and should not be used by application code!


DataEntry

public DataEntry(ClassMeta classMeta,
                 String objectID)
Create an instance of DataEntry.

Parameters:
classMeta - the type of the entity persisted in this container (which must be the entity's concrete type - not the root-type of the inheritance tree!). See getClassMeta() for further details.
objectID - the String-representation of the entity's identifier (aka OID or object-ID). See getObjectID() for further details.
Method Detail

getDataEntry

public static DataEntry getDataEntry(PersistenceManager pmData,
                                     long dataEntryID)
Get the DataEntry identified by the specified dataEntryID or null if no such instance exists.

Parameters:
pmData - the backend-PersistenceManager. Must not be null.
dataEntryID - the DataEntry's identifier.
Returns:
the DataEntry matching the given dataEntryID or null, if no such instance exists.

getDataEntry

public static DataEntry getDataEntry(PersistenceManager pmData,
                                     ClassMeta classMeta,
                                     String objectID)
Get the DataEntry identified by the given type and JDO/JPA-object-ID.

Parameters:
pmData - the backend-PersistenceManager. Must not be null.
classMeta - reference to the searched DataEntry's classMeta (which must match the searched instance's concrete type - not the root-type of the inheritance tree!).
objectID - the String-representation of the JDO/JPA-object-ID.
Returns:
the DataEntry matching the given combination of classMeta and objectID; or null, if no such instance exists.

getDataEntryID

public static Long getDataEntryID(PersistenceManager pmData,
                                  ClassMeta classMeta,
                                  String objectID)

Get the dataEntryID of the DataEntry identified by the given type and JDO/JPA-object-ID.

This method is equivalent to first calling

DataEntry e = getDataEntry(PersistenceManager, ClassMeta, String)

and then

e == null ? null : Long.valueOf(e.getDataEntryID())

but faster, because it does not query unnecessary data from the underlying database.

Parameters:
pmData - the backend-PersistenceManager. Must not be null.
classMeta - reference to the searched DataEntry's classMeta (which must match the searched instance's concrete type - not the root-type of the inheritance tree!).
objectID - the String-representation of the JDO/JPA-object-ID.
Returns:
the dataEntryID of the DataEntry matching the given combination of classMeta and objectID; or null, if no such instance exists.

getDataEntryIDsNegated

public static Set<Long> getDataEntryIDsNegated(PersistenceManager pmData,
                                               ClassMeta classMeta,
                                               String notThisObjectID)

Get the dataEntryIDs of all those DataEntry instances which do not match the given type and JDO/JPA-object-ID.

This method is thus the negation of getDataEntryID(PersistenceManager, ClassMeta, String).

Parameters:
pmData - the backend-PersistenceManager. Must not be null.
classMeta - reference to the searched DataEntry's classMeta (which must match the searched instance's concrete type - not the root-type of the inheritance tree!).
notThisObjectID - the String-representation of the JDO/JPA-object-ID, which should be excluded.
Returns:
the dataEntryIDs of those DataEntrys which match the given classMeta but have an object-ID different from the one specified as notThisObjectID.

getDataEntryID

public long getDataEntryID()
Get the single primary key field (= object-identifier) of DataEntry.

Returns:
the object-identifier (= primary key).

getClassMeta

public ClassMeta getClassMeta()

Get the type of the entity persisted in this container.

Note, that this is the concrete type of the persisted object and not the root-type of the persistable hierarchy. For example, if bbb is persisted and bbb is an instance of class BBB which extends AAA and both classes are persistable, this will point to class BBB (and not AAA).

Therefore, if you want to query all instances of a certain type including subclasses, you have to ask for the sub-classes via StoreManager.getSubClassesForClass(String, boolean, org.datanucleus.ClassLoaderResolver) first and then query for all these classes individually.

Returns:
the type of the entity.

getObjectID

public String getObjectID()

Get the String-representation of the entity's identifier.

For JDO, please read the following (and related) documentation:

For JPA, please read the following (and related) documentation:

Returns:
the OID in String-form (e.g. the result of JDOHelper.getObjectId(entity).toString() when using JDO).

getKeyID

public long getKeyID()
Get the identifier of the encryption-key used to encrypt the value.

Returns:
the encryption-key used to encrypt this DataEntry's contents.
See Also:
setKeyID(long)

setKeyID

public void setKeyID(long keyID)
Set the identifier of the encryption-key used to encrypt the value.

Parameters:
keyID - the encryption-key used to encrypt this DataEntry's contents.
See Also:
getKeyID()

getValue

public byte[] getValue()
Get the encrypted data of an entity. The entity is transformed ("made flat") into an ObjectContainer which is then serialised using Java native serialisation and finally encrypted.

Returns:
the encrypted serialised data of an ObjectContainer holding the entity's data.
See Also:
setValue(byte[])

setValue

public void setValue(byte[] value)
Set the encrypted data of an entity.

Parameters:
value - the encrypted serialised data of an ObjectContainer holding the entity's data.
See Also:
getValue()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

jdoPreStore

public void jdoPreStore()
Specified by:
jdoPreStore in interface StoreCallback

Cumulus4j API
(1.0.0)

Copyright © 2012 NightLabs Consulting GmbH. All Rights Reserved.