net.java.ao.types
Class TypeManager

java.lang.Object
  extended by net.java.ao.types.TypeManager

public class TypeManager
extends Object

Central managing class for the ActiveObjects type system. The type system in AO is designed to allow extensibility and control over how specific data types are handled internally. All database-agnostic, type-specific tasks are delegated to the actual type instances. This class acts as a singleton container for every available type, indexing them based on corresponding Java type and JDBC integer type.

This container is thread safe and so may be used from within multiple contexts.

Author:
Daniel Spiewak
See Also:
DatabaseType

Constructor Summary
TypeManager()
           
 
Method Summary
<T> DatabaseType<T>
getType(Class<T> javaType)
          Returns the corresponding DatabaseType for a given Java class.
 DatabaseType<?> getType(int sqlType)
          Returns the corresponding DatabaseType for a given JDBC integer type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeManager

public TypeManager()
Method Detail

getType

public <T> DatabaseType<T> getType(Class<T> javaType)

Returns the corresponding DatabaseType for a given Java class. This is the primary mechanism used by ActiveObjects internally to obtain type instances. Code external to the framework may also make use of this method to obtain the relevant type information or to just test if a type is in fact available. Types are internally prioritized by entry order. The first type to respond true to the DatabaseType.isHandlerFor(Class) method will be returned.

It's worth noting that this method worst case runs in O(n) time. This is because a linear search must be made through the raw list of available types. However, once the type has been found it is placed into a hash indexed by class type. Thus for most types, this method will run in constant time (O(1)).

Parameters:
javaType - The Class type for which a type instance should be returned.
Returns:
The type instance which corresponds to the specified class.
Throws:
RuntimeException - If no type was found correspondant to the given class.
See Also:
getType(int)

getType

public DatabaseType<?> getType(int sqlType)

Returns the corresponding DatabaseType for a given JDBC integer type. Code external to the framework may also make use of this method to obtain the relevant type information or to just test if a type is in fact available. Types are internally prioritized by entry order. The first type to respond true to the DatabaseType.isHandlerFor(int) method will be returned.

It's worth noting that this method worst case runs in O(n) time. This is because a linear search must be made through the raw list of available types. However, once the type has been found it is placed into a hash indexed by int value. Thus for most types, this method will run in constant time (O(1)).

Parameters:
sqlType - The JDBC Types constant for which a type instance should be retrieved.
Returns:
The type instance which corresponds to the specified type constant.
Throws:
RuntimeException - If no type was found correspondant to the given type constant.
See Also:
getType(Class)


Copyright © 2007-2011. All Rights Reserved.