edu.internet2.middleware.grouperClient.jdbc
Class GcPersistableHelper

java.lang.Object
  extended by edu.internet2.middleware.grouperClient.jdbc.GcPersistableHelper

public class GcPersistableHelper
extends java.lang.Object

Author:
harveycg

Constructor Summary
GcPersistableHelper()
           
 
Method Summary
static java.lang.String columnName(java.lang.reflect.Field field)
          Get the name of the column to store the field value in from the Persistable annotation or field name.
static java.util.List<java.lang.reflect.Field> compoundPrimaryKeyFields(java.lang.Class<? extends java.lang.Object> clazz)
          Get the fields that have been specified as compound primary key fields.
static GcPersistableField findPersistableAnnotation(java.lang.reflect.Field field)
          Find the Persistable annotation on the field, return null if there is not one.
static GcPersistableClass findPersistableClassAnnotation(java.lang.Class<? extends java.lang.Object> clazz)
          Find the PersistableClass annotation on the class, or parent classes, return null if there is not one.
static boolean hasPersistableAnnotation(java.lang.Class<? extends java.lang.Object> clazz)
          Whether the class has at least one Persistable(Field or Class) annnotation on the class itself or on any field.
static java.util.List<java.lang.reflect.Field> heirarchicalFields(java.lang.Class<?> clazz)
          A list of heirachical fields from the entire object structure.
static boolean isCompoundPrimaryKey(java.lang.reflect.Field field)
          Whether the field is a compound primary key, check Persistable annotation if there is one on the field, default false.
static boolean isPersist(java.lang.reflect.Field field, java.lang.Class<?> clazz)
          Whether the field should be persisted to the database, check Persistable field and class level annotations.
static boolean isPrimaryKey(java.lang.reflect.Field field)
          Whether the field is a primary key, check Persistable annotation if there is one on the field, default false.
static boolean isSelect(java.lang.reflect.Field field, java.lang.Class<?> clazz)
          Whether the field should be selected from the database, check Persistable field and class level annotations.
static java.lang.String oracleStandardNameFromJava(java.lang.String javaName)
          Get the oracle underscore name e.g.
static java.lang.reflect.Field primaryKeyField(java.lang.Class<? extends java.lang.Object> clazz)
          Get the field that has been specified as the primary key - will return null if the class has compound column primary keys.
static boolean primaryKeyManuallyAssigned(java.lang.reflect.Field primaryKeyField)
          Whether the primary key is manually assigned.
static java.lang.String primaryKeySequenceName(java.lang.reflect.Field primaryKeyField)
          Get the sequence name for the primary key field.
static java.lang.String tableName(java.lang.Class<? extends java.lang.Object> clazz)
          Get the name of the database table to store the object in from the Persistable annotation or the class name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GcPersistableHelper

public GcPersistableHelper()
Method Detail

oracleStandardNameFromJava

public static java.lang.String oracleStandardNameFromJava(java.lang.String javaName)
Get the oracle underscore name e.g. javaNameHere -> JAVA_NAME_HERE.

Parameters:
javaName - is the java convention name.
Returns:
the oracle underscore name based on the java name.

columnName

public static java.lang.String columnName(java.lang.reflect.Field field)
Get the name of the column to store the field value in from the Persistable annotation or field name.

Parameters:
field - is the field to get the name from.
Returns:
the column name.

isPrimaryKey

public static boolean isPrimaryKey(java.lang.reflect.Field field)
Whether the field is a primary key, check Persistable annotation if there is one on the field, default false.

Parameters:
field - is the field to check.
Returns:
true if so.

isCompoundPrimaryKey

public static boolean isCompoundPrimaryKey(java.lang.reflect.Field field)
Whether the field is a compound primary key, check Persistable annotation if there is one on the field, default false.

Parameters:
field - is the field to check.
Returns:
true if so.

tableName

public static java.lang.String tableName(java.lang.Class<? extends java.lang.Object> clazz)
Get the name of the database table to store the object in from the Persistable annotation or the class name.

Parameters:
clazz - is the field to check.
Returns:
true if so.

hasPersistableAnnotation

public static boolean hasPersistableAnnotation(java.lang.Class<? extends java.lang.Object> clazz)
Whether the class has at least one Persistable(Field or Class) annnotation on the class itself or on any field.

Parameters:
clazz - is the field to check.
Returns:
true if so.

heirarchicalFields

public static java.util.List<java.lang.reflect.Field> heirarchicalFields(java.lang.Class<?> clazz)
A list of heirachical fields from the entire object structure.

Parameters:
clazz - is the child class.
Returns:
the list.

isSelect

public static boolean isSelect(java.lang.reflect.Field field,
                               java.lang.Class<?> clazz)
Whether the field should be selected from the database, check Persistable field and class level annotations.

Parameters:
field - is the field to check.
clazz - is teh type of object we are checking.
Returns:
true if so.

isPersist

public static boolean isPersist(java.lang.reflect.Field field,
                                java.lang.Class<?> clazz)
Whether the field should be persisted to the database, check Persistable field and class level annotations.

Parameters:
field - is the field to check.
clazz - is teh type of object we are checking.
Returns:
true if so.

findPersistableClassAnnotation

public static GcPersistableClass findPersistableClassAnnotation(java.lang.Class<? extends java.lang.Object> clazz)
Find the PersistableClass annotation on the class, or parent classes, return null if there is not one.

Parameters:
clazz - is the class to find it on.
Returns:
the annotation or null.

findPersistableAnnotation

public static GcPersistableField findPersistableAnnotation(java.lang.reflect.Field field)
Find the Persistable annotation on the field, return null if there is not one.

Parameters:
field - is the field to find it on.
Returns:
the annotation or null.

primaryKeyField

public static java.lang.reflect.Field primaryKeyField(java.lang.Class<? extends java.lang.Object> clazz)
Get the field that has been specified as the primary key - will return null if the class has compound column primary keys.

Parameters:
clazz - is the class to check for the field on.
Returns:
the primary key field.

compoundPrimaryKeyFields

public static java.util.List<java.lang.reflect.Field> compoundPrimaryKeyFields(java.lang.Class<? extends java.lang.Object> clazz)
Get the fields that have been specified as compound primary key fields.

Parameters:
clazz - is the class to check for the field on.
Returns:
the primary key field.

primaryKeySequenceName

public static java.lang.String primaryKeySequenceName(java.lang.reflect.Field primaryKeyField)
Get the sequence name for the primary key field.

Parameters:
primaryKeyField - is the field with the annotation for primary key and sequence on it.
Returns:
the sequence name or a failure.

primaryKeyManuallyAssigned

public static boolean primaryKeyManuallyAssigned(java.lang.reflect.Field primaryKeyField)
Whether the primary key is manually assigned.

Parameters:
primaryKeyField - is the field with the annotation for primary key and sequence on it.
Returns:
the sequence name or a failure.