Oracle NoSQL Database Examples
version 11gR2.2.0.26

schema
Class KeyDefinition

java.lang.Object
  extended by schema.KeyDefinition

 class KeyDefinition
extends Object

Defines the use of Keys in this application.

In the schema of a KVStore application, an important design aspect is the Key structure, including the use of the Key major path and minor path. In a Key, the major and minor path each consists of a List of String components. In comments here we describe the Key as if it were a single String with '/' separators between components of each path, and a "/-/" separator between the major and minor paths.

/majorComponent1/majorComponent2/-/minorComponent1/minorComponent2

In many applications, including this one, the first String component of the major path identifies the object type. Although in this example there is only one object type -- the "user" type -- it is expected that other types would be present in a real application. For example, a "group" object type might identify Key/Value pairs that contain sets of user identifiers. The second component of the major path is the user's unique identifier, the email address in this case. The Key major path in this application is simply:

/user/EMAIL

where "user" is the String constant identifying the object type, and EMAIL is the user's email address.

Four different types of Key/Value pairs are maintained for each user, and are identified by the Key minor path. Because all Key/Value pairs for a given user have the same Key major path, they are stored together physically and can be accessed in a single atomic operation such as KVStore.multiGet or KVStore.execute. The different data types and the full Key structures are:

/user/EMAIL/-/info

A single Key/Value pair per user containing a set of small attributes such as name, phone and address. A UserInfo class instance represents each Key/Value pair.

/user/EMAIL/-/image

A single Key/Value pair per user containing a potentially large, binary image. A UserImage class instance represents each Key/Value pair.

/user/EMAIL/-/login

A single Key/Value pair per user containing a summary of all login information for the user. A LoginSummary class instance represents each Key/Value pair.

/user/EMAIL/-/login/TIMESTAMP

Multiple Key/Value pairs per user, each containing a record of a single session. The TIMESTAMP is a UTC-format String identifying the start time of the session. The TIMESTAMP orders session information chronologically and can be used to query session information for a specific date/time interval. A LoginSession class instance represents each Key/Value pair.


Field Summary
(package private) static SimpleDateFormat DATE_TIME_FORMAT
           
(package private) static String IMAGE_PROPERTY_NAME
           
(package private) static String INFO_PROPERTY_NAME
           
(package private) static String LOGIN_PROPERTY_NAME
           
(package private) static SimpleDateFormat TIME_FORMAT
           
(package private) static String USER_OBJECT_TYPE
           
 
Constructor Summary
KeyDefinition()
           
 
Method Summary
(package private) static Object deserializeAny(Bindings bindings, Key key, Value value)
          Translates the given Key/Value to its corresponding Java object.
(package private) static String formatDuration(long millis)
          Formats a time duration for reporting purposes.
(package private) static String formatTimestamp(long millis)
          Returns a timestamp String for the given time in millis.
(package private) static long getSessionLoginTime(Key key)
          Returns the login time in millis for a given LoginSession Key.
(package private) static String getUserEmail(Key key)
          Returns the email address for a given Key.
(package private) static Key makeLoginSessionKey(String email, long loginTimeMs)
          Returns a Key that can be used to access LoginSession Key/Value pairs.
(package private) static Key makeLoginSummaryKey(String email)
          Returns a Key that can be used to access LoginSummary Key/Value pairs.
(package private) static Key makeUserImageKey(String email)
          Returns a Key that can be used to access UserImage Key/Value pairs.
(package private) static Key makeUserInfoKey(String email)
          Returns a Key that can be used to access UserInfo Key/Value pairs.
(package private) static Key makeUserTypeKey()
          Returns a Key that can be used as a parentKey to select all user Key/Value pairs when using KVStore.storeIterator or storeKeysIterator.
(package private) static long parseTimestamp(String timestamp)
          Parses the timestamp and returns the time in millis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_OBJECT_TYPE

static final String USER_OBJECT_TYPE
See Also:
Constant Field Values

INFO_PROPERTY_NAME

static final String INFO_PROPERTY_NAME
See Also:
Constant Field Values

IMAGE_PROPERTY_NAME

static final String IMAGE_PROPERTY_NAME
See Also:
Constant Field Values

LOGIN_PROPERTY_NAME

static final String LOGIN_PROPERTY_NAME
See Also:
Constant Field Values

DATE_TIME_FORMAT

static final SimpleDateFormat DATE_TIME_FORMAT

TIME_FORMAT

static final SimpleDateFormat TIME_FORMAT
Constructor Detail

KeyDefinition

KeyDefinition()
Method Detail

makeUserTypeKey

static Key makeUserTypeKey()
Returns a Key that can be used as a parentKey to select all user Key/Value pairs when using KVStore.storeIterator or storeKeysIterator.


makeUserInfoKey

static Key makeUserInfoKey(String email)
Returns a Key that can be used to access UserInfo Key/Value pairs.


makeUserImageKey

static Key makeUserImageKey(String email)
Returns a Key that can be used to access UserImage Key/Value pairs.


makeLoginSummaryKey

static Key makeLoginSummaryKey(String email)
Returns a Key that can be used to access LoginSummary Key/Value pairs.


makeLoginSessionKey

static Key makeLoginSessionKey(String email,
                               long loginTimeMs)
Returns a Key that can be used to access LoginSession Key/Value pairs.


formatTimestamp

static String formatTimestamp(long millis)
Returns a timestamp String for the given time in millis. The timestamp is used as the last Key component in the LoginSession Key. It can be used for creating KeyRange objects for selecting a range of LoginSession Key/Value pairs.


parseTimestamp

static long parseTimestamp(String timestamp)
Parses the timestamp and returns the time in millis. Used to convert the timestamp in a LoginSession key to millis.


formatDuration

static String formatDuration(long millis)
Formats a time duration for reporting purposes.


getUserEmail

static String getUserEmail(Key key)
Returns the email address for a given Key. The 2nd major path component is the email address, for all user objects.


getSessionLoginTime

static long getSessionLoginTime(Key key)
Returns the login time in millis for a given LoginSession Key. The 2nd minor path component is the timestamp.


deserializeAny

static Object deserializeAny(Bindings bindings,
                             Key key,
                             Value value)
Translates the given Key/Value to its corresponding Java object. This is useful when an arbitrary user Key/Value pair is obtained, for example by iterating over all Key/Value pairs in the store or all Key/Value pairs for a particular user.


Oracle NoSQL Database Examples
version 11gR2.2.0.26

Copyright (c) 2011, 2013 Oracle and/or its affiliates. All rights reserved.