Package sc.db
Class DBTypeDescriptor
- java.lang.Object
-
- sc.db.BaseTypeDescriptor
-
- sc.db.DBTypeDescriptor
-
public class DBTypeDescriptor extends BaseTypeDescriptor
Stores the metadata for a given type in the system that represents the mapping to a persistence storage layer. A given type can be persisted from one or more tables, in the same or different databases. There's a primary table, that will have one row per object instance. Auxiliary tables store alternate properties and can be optionally created. Multi-tables store multi-valued properties stored with 'multiRow' mode. A selectGroup allows collections of properties to be loaded at the same time. By default, a select group is created for each table.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.List<DBPropertyDescriptor>
allDBProps
java.util.List<TableDescriptor>
auxTables
DBTypeDescriptor
baseType
static int
DBAbstractTypeId
boolean
dbDisabled
Turn off database entirely - store objects and run queries only in memory for testingstatic java.lang.String
DBDynPropsColumnName
static java.lang.String
DBDynPropsColumnType
boolean
dbReadOnly
Turn off writes to the database - instead, these will be stored in memory and merged into query results for testing purposesstatic java.lang.String
DBTypeIdColumnName
static java.lang.String
DBTypeIdPropertyName
static int
DBUnsetTypeId
Two reserved type ids - either not specified or it's an abstract type so it's not createdjava.lang.String
defaultFetchGroup
long
expireTimeMillis
DBPropertyDescriptor
lastModifiedProperty
static java.lang.String
LastModifiedPropertyName
boolean
liveDynTypes
java.util.List<TableDescriptor>
multiTables
boolean
needsAutoId
Set to true for types where the source has no 'id' propertyTableDescriptor
primaryTable
java.util.List<BaseQueryDescriptor>
queries
java.util.List<DBPropertyDescriptor>
reverseProps
boolean
runtimeMode
False during the code-generation phase, true when connected to a databasejava.lang.String
schemaSQL
Commands in the database's DDL language (usually SQL) to be added after the generated create tablesjava.util.LinkedHashMap<java.lang.String,SelectGroupQuery>
selectGroups
java.util.List<DBTypeDescriptor>
subTypes
java.util.Map<java.lang.Integer,DBTypeDescriptor>
subTypesById
SyncProperties
syncProps
boolean
syncPropsInited
int
typeId
int[]
typeIdList
java.util.concurrent.ConcurrentHashMap<java.lang.Object,IDBObject>
typeInstances
The cache of instances for this type but only if baseType = null - otherwise, we use the baseType's typeInstances cacheDBPropertyDescriptor
versionProperty
-
Fields inherited from class sc.db.BaseTypeDescriptor
dataSource, dataSourceName, tablesInitialized, typeDecl
-
-
Constructor Summary
Constructors Constructor Description DBTypeDescriptor(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<BaseQueryDescriptor> queries, java.lang.String schemaSQL)
Defines the type with the id properties of the primary table in tact so it can be used to create references from other types.DBTypeDescriptor(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.util.List<BaseQueryDescriptor> queries, java.lang.String versionPropName, java.lang.String schemaSQL, boolean needsAutoId)
The constructor called from generated runtime code - but the generated code uses the static 'create' method that calls this
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate()
void
addFetchQuery(sc.db.DBQuery query)
void
addQueryDescriptor(BaseQueryDescriptor queryDesc)
void
addReverseProperty(DBPropertyDescriptor reverseProp)
void
addSubType(DBTypeDescriptor subType)
static void
clearAllCaches()
void
clearTypeCache()
static java.lang.String
convertToSQLSearchString(java.lang.String text)
void
copyQueriesFrom(DBTypeDescriptor fromType)
int
count(Query query)
int
countAll()
static DBTypeDescriptor
create(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.util.List<BaseQueryDescriptor> queries, java.lang.String versionPropName, java.lang.String schemaSQL, boolean needsAutoId)
IDBObject
createInstance()
IDBObject
createInstance(DBObject dbObj)
IDBObject
createInstanceOfType(int typeId)
IDBObject
createPrototype(boolean concreteOnly)
void
enableLiveDynTypes()
java.util.List<? extends IDBObject>
findAll(java.util.List<java.lang.String> orderByNames, int startIx, int maxResults)
java.util.List<? extends IDBObject>
findBy(java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues, java.lang.String selectGroup, java.util.List<java.lang.String> orderByNames, int startIx, int maxResults)
IDBObject
findById(java.lang.Object... idArgs)
java.util.List<? extends IDBObject>
findByIds(java.lang.Object... ids)
DBTypeDescriptor
findSubType(java.lang.String subTypeName)
static BaseTypeDescriptor
getBaseByType(java.lang.Object type, boolean start)
java.lang.String
getBaseTypeName()
static DBTypeDescriptor
getByName(java.lang.String typeName, boolean start)
static DBTypeDescriptor
getByTableName(java.lang.String tableName)
static DBTypeDescriptor
getByType(java.lang.Object type, boolean start)
DBDataSource
getDataSource()
SelectGroupQuery
getDefaultFetchQuery()
sc.db.DBQuery
getFetchQueryForNum(int queryNum)
SelectGroupQuery
getFetchQueryForProperty(java.lang.String propName)
java.lang.Object
getIdColumnType(int ci)
java.lang.Object
getIdColumnValue(java.lang.Object inst, int ci)
DBColumnType
getIdDBColumnType(int ci)
java.util.List<IdPropertyDescriptor>
getIdProperties()
java.lang.Object
getIdPropertyType(int ci)
java.lang.StringBuilder
getMetadataString()
TableDescriptor
getMultiTableByName(java.lang.String tableName, DBPropertyDescriptor mvProp)
int
getNumFetchPropQueries()
TableDescriptor
getPrimaryTable()
DBPropertyDescriptor
getPropertyDescriptor(java.lang.String propNamePath)
DBPropertyDescriptor
getPropertyForColumn(java.lang.String colName)
DBTypeDescriptor
getRootType()
boolean
getSchemaReady()
SelectGroupQuery
getSelectGroupQuery(java.lang.String selectGroup)
DBTypeDescriptor
getSubTypeByTypeId(int typeId)
TableDescriptor
getTableByName(java.lang.String tableName)
int[]
getTypeIdList()
DBPropertyDescriptor
getTypeIdProperty()
void
init()
void
initDBObject(DBObject obj)
void
initSyncForInst(java.lang.Object inst, boolean onDemand, boolean resetState)
void
initTables(java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.lang.String versionPropName, boolean runtimeMode)
void
invalidateExpiredItems()
IDBObject
lookupInstById(java.lang.Object id, int typeId, boolean createProto, boolean selectDefault)
Lower level method used to lookup an instance of this type with a given id - based on the "highlander principle" - we try to ensure there's only one instance of an object with the same id to prevent aliasing, simplify code and caching and provide a 'transactional view' of objects with persistent state.IDBObject
matchOne(DBObject proto, java.util.List<java.lang.String> props, java.lang.String selectGroup)
java.util.List<? extends IDBObject>
matchQuery(DBObject proto, java.util.List<java.lang.String> protoProps, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
The core "declarative query" method to return objects for this type matching a prototype object and list of protoProp names.java.util.List<IDBObject>
mergeResultLists(java.util.List<IDBObject> primary, java.util.List<IDBObject> other)
java.lang.Object
namedQuery(java.lang.String queryName, java.lang.Object... args)
java.util.List<? extends IDBObject>
query(Query query, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
java.util.List<IDBObject>
queryCache(DBObject proto, java.util.List<java.lang.String> props, DBTypeDescriptor fromType)
IDBObject
registerInstance(IDBObject inst, boolean clearTransient)
boolean
removeInstance(DBObject dbObj, boolean remove)
void
replaceInstance(IDBObject inst)
void
resolve()
int
searchCountQuery(java.lang.String text, java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues)
java.util.List<? extends IDBObject>
searchQuery(java.lang.String text, java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
void
start()
java.lang.Object
stringToId(java.lang.String idStr)
void
updateTypeDescriptor(IDBObject newInst, DBObject dbObj)
void
waitForSchemaReady()
Allow test or application threads to wait until the SchemaManager finishes updating/validating the schema before continuing-
Methods inherited from class sc.db.BaseTypeDescriptor
getTypeName, toString
-
-
-
-
Field Detail
-
DBTypeIdPropertyName
public static final java.lang.String DBTypeIdPropertyName
- See Also:
- Constant Field Values
-
DBTypeIdColumnName
public static final java.lang.String DBTypeIdColumnName
- See Also:
- Constant Field Values
-
LastModifiedPropertyName
public static final java.lang.String LastModifiedPropertyName
- See Also:
- Constant Field Values
-
DBDynPropsColumnName
public static final java.lang.String DBDynPropsColumnName
- See Also:
- Constant Field Values
-
DBDynPropsColumnType
public static final java.lang.String DBDynPropsColumnType
- See Also:
- Constant Field Values
-
DBUnsetTypeId
public static final int DBUnsetTypeId
Two reserved type ids - either not specified or it's an abstract type so it's not created- See Also:
- Constant Field Values
-
DBAbstractTypeId
public static final int DBAbstractTypeId
- See Also:
- Constant Field Values
-
baseType
public DBTypeDescriptor baseType
-
dbReadOnly
public boolean dbReadOnly
Turn off writes to the database - instead, these will be stored in memory and merged into query results for testing purposes
-
dbDisabled
public boolean dbDisabled
Turn off database entirely - store objects and run queries only in memory for testing
-
needsAutoId
public boolean needsAutoId
Set to true for types where the source has no 'id' property
-
defaultFetchGroup
public java.lang.String defaultFetchGroup
-
typeInstances
public java.util.concurrent.ConcurrentHashMap<java.lang.Object,IDBObject> typeInstances
The cache of instances for this type but only if baseType = null - otherwise, we use the baseType's typeInstances cache
-
queries
public java.util.List<BaseQueryDescriptor> queries
-
schemaSQL
public java.lang.String schemaSQL
Commands in the database's DDL language (usually SQL) to be added after the generated create tables
-
runtimeMode
public boolean runtimeMode
False during the code-generation phase, true when connected to a database
-
expireTimeMillis
public long expireTimeMillis
-
subTypesById
public java.util.Map<java.lang.Integer,DBTypeDescriptor> subTypesById
-
subTypes
public java.util.List<DBTypeDescriptor> subTypes
-
typeId
public int typeId
-
typeIdList
public int[] typeIdList
-
syncProps
public SyncProperties syncProps
-
syncPropsInited
public boolean syncPropsInited
-
liveDynTypes
public boolean liveDynTypes
-
primaryTable
public TableDescriptor primaryTable
-
auxTables
public java.util.List<TableDescriptor> auxTables
-
multiTables
public java.util.List<TableDescriptor> multiTables
-
versionProperty
public DBPropertyDescriptor versionProperty
-
lastModifiedProperty
public DBPropertyDescriptor lastModifiedProperty
-
allDBProps
public java.util.List<DBPropertyDescriptor> allDBProps
-
reverseProps
public java.util.List<DBPropertyDescriptor> reverseProps
-
selectGroups
public java.util.LinkedHashMap<java.lang.String,SelectGroupQuery> selectGroups
-
-
Constructor Detail
-
DBTypeDescriptor
public DBTypeDescriptor(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<BaseQueryDescriptor> queries, java.lang.String schemaSQL)
Defines the type with the id properties of the primary table in tact so it can be used to create references from other types. Properties may be later added to the primary table and other tables added with initTables. This version is used from the code processor as it must create the descriptors in phases.
-
DBTypeDescriptor
public DBTypeDescriptor(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.util.List<BaseQueryDescriptor> queries, java.lang.String versionPropName, java.lang.String schemaSQL, boolean needsAutoId)
The constructor called from generated runtime code - but the generated code uses the static 'create' method that calls this
-
-
Method Detail
-
clearAllCaches
public static void clearAllCaches()
-
create
public static DBTypeDescriptor create(java.lang.Object typeDecl, DBTypeDescriptor baseType, int typeId, java.lang.String dataSourceName, TableDescriptor primary, java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.util.List<BaseQueryDescriptor> queries, java.lang.String versionPropName, java.lang.String schemaSQL, boolean needsAutoId)
-
getByType
public static DBTypeDescriptor getByType(java.lang.Object type, boolean start)
-
getBaseByType
public static BaseTypeDescriptor getBaseByType(java.lang.Object type, boolean start)
-
getByName
public static DBTypeDescriptor getByName(java.lang.String typeName, boolean start)
-
getByTableName
public static DBTypeDescriptor getByTableName(java.lang.String tableName)
-
findSubType
public DBTypeDescriptor findSubType(java.lang.String subTypeName)
-
getRootType
public DBTypeDescriptor getRootType()
-
addSubType
public void addSubType(DBTypeDescriptor subType)
-
initTables
public void initTables(java.util.List<TableDescriptor> auxTables, java.util.List<TableDescriptor> multiTables, java.lang.String versionPropName, boolean runtimeMode)
-
addQueryDescriptor
public void addQueryDescriptor(BaseQueryDescriptor queryDesc)
-
getTableByName
public TableDescriptor getTableByName(java.lang.String tableName)
-
getMultiTableByName
public TableDescriptor getMultiTableByName(java.lang.String tableName, DBPropertyDescriptor mvProp)
-
copyQueriesFrom
public void copyQueriesFrom(DBTypeDescriptor fromType)
-
getDefaultFetchQuery
public SelectGroupQuery getDefaultFetchQuery()
-
getSelectGroupQuery
public SelectGroupQuery getSelectGroupQuery(java.lang.String selectGroup)
-
getFetchQueryForProperty
public SelectGroupQuery getFetchQueryForProperty(java.lang.String propName)
-
getFetchQueryForNum
public sc.db.DBQuery getFetchQueryForNum(int queryNum)
-
getNumFetchPropQueries
public int getNumFetchPropQueries()
-
getPropertyDescriptor
public DBPropertyDescriptor getPropertyDescriptor(java.lang.String propNamePath)
-
getPropertyForColumn
public DBPropertyDescriptor getPropertyForColumn(java.lang.String colName)
-
addFetchQuery
public void addFetchQuery(sc.db.DBQuery query)
-
stringToId
public java.lang.Object stringToId(java.lang.String idStr)
-
findById
public IDBObject findById(java.lang.Object... idArgs)
-
findByIds
public java.util.List<? extends IDBObject> findByIds(java.lang.Object... ids)
-
findAll
public java.util.List<? extends IDBObject> findAll(java.util.List<java.lang.String> orderByNames, int startIx, int maxResults)
-
findBy
public java.util.List<? extends IDBObject> findBy(java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues, java.lang.String selectGroup, java.util.List<java.lang.String> orderByNames, int startIx, int maxResults)
-
convertToSQLSearchString
public static java.lang.String convertToSQLSearchString(java.lang.String text)
-
searchQuery
public java.util.List<? extends IDBObject> searchQuery(java.lang.String text, java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
-
searchCountQuery
public int searchCountQuery(java.lang.String text, java.util.List<java.lang.String> propNames, java.util.List<java.lang.Object> propValues)
-
countAll
public int countAll()
-
query
public java.util.List<? extends IDBObject> query(Query query, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
-
count
public int count(Query query)
-
lookupInstById
public IDBObject lookupInstById(java.lang.Object id, int typeId, boolean createProto, boolean selectDefault)
Lower level method used to lookup an instance of this type with a given id - based on the "highlander principle" - we try to ensure there's only one instance of an object with the same id to prevent aliasing, simplify code and caching and provide a 'transactional view' of objects with persistent state. If createProto is true, and the instance is not in the cache, a prototype is created with that and returned. If selectDefault is true, that prototype is populated with the default property group if the row exists and returned. If the row does not exist null is returned in that case.
-
createInstance
public IDBObject createInstance()
-
createInstanceOfType
public IDBObject createInstanceOfType(int typeId)
-
createPrototype
public IDBObject createPrototype(boolean concreteOnly)
-
initSyncForInst
public void initSyncForInst(java.lang.Object inst, boolean onDemand, boolean resetState)
-
replaceInstance
public void replaceInstance(IDBObject inst)
-
removeInstance
public boolean removeInstance(DBObject dbObj, boolean remove)
-
clearTypeCache
public void clearTypeCache()
-
getIdColumnValue
public java.lang.Object getIdColumnValue(java.lang.Object inst, int ci)
-
getIdColumnType
public java.lang.Object getIdColumnType(int ci)
-
getIdDBColumnType
public DBColumnType getIdDBColumnType(int ci)
-
getIdPropertyType
public java.lang.Object getIdPropertyType(int ci)
-
getIdProperties
public java.util.List<IdPropertyDescriptor> getIdProperties()
-
getPrimaryTable
public TableDescriptor getPrimaryTable()
-
init
public void init()
- Overrides:
init
in classBaseTypeDescriptor
-
resolve
public void resolve()
-
start
public void start()
- Overrides:
start
in classBaseTypeDescriptor
-
activate
public void activate()
- Overrides:
activate
in classBaseTypeDescriptor
-
addReverseProperty
public void addReverseProperty(DBPropertyDescriptor reverseProp)
-
initDBObject
public void initDBObject(DBObject obj)
-
matchQuery
public java.util.List<? extends IDBObject> matchQuery(DBObject proto, java.util.List<java.lang.String> protoProps, java.lang.String selectGroup, java.util.List<java.lang.String> orderByProps, int startIx, int maxResults)
The core "declarative query" method to return objects for this type matching a prototype object and list of protoProp names. The query returns matching objects for all properties (i.e. 'where clause' using 'and' for all properties in the list). Optionally provide an orderByProps list for the list of properties used in sorting the result. Use "-propName" for a descending order sort on that property and start and max properties for limit/offset in the result list.
-
matchOne
public IDBObject matchOne(DBObject proto, java.util.List<java.lang.String> props, java.lang.String selectGroup)
-
mergeResultLists
public java.util.List<IDBObject> mergeResultLists(java.util.List<IDBObject> primary, java.util.List<IDBObject> other)
-
queryCache
public java.util.List<IDBObject> queryCache(DBObject proto, java.util.List<java.lang.String> props, DBTypeDescriptor fromType)
-
getDataSource
public DBDataSource getDataSource()
-
waitForSchemaReady
public void waitForSchemaReady()
Allow test or application threads to wait until the SchemaManager finishes updating/validating the schema before continuing
-
getSchemaReady
public boolean getSchemaReady()
-
namedQuery
public java.lang.Object namedQuery(java.lang.String queryName, java.lang.Object... args)
-
getTypeIdProperty
public DBPropertyDescriptor getTypeIdProperty()
-
getTypeIdList
public int[] getTypeIdList()
-
getMetadataString
public java.lang.StringBuilder getMetadataString()
- Specified by:
getMetadataString
in classBaseTypeDescriptor
-
getSubTypeByTypeId
public DBTypeDescriptor getSubTypeByTypeId(int typeId)
-
getBaseTypeName
public java.lang.String getBaseTypeName()
- Overrides:
getBaseTypeName
in classBaseTypeDescriptor
-
enableLiveDynTypes
public void enableLiveDynTypes()
-
invalidateExpiredItems
public void invalidateExpiredItems()
-
-