Package helma.objectmodel.db
Class DbMapping
java.lang.Object
helma.objectmodel.db.DbMapping
A DbMapping describes how a certain type of Nodes is to mapped to a
relational database table. Basically it consists of a set of JavaScript property-to-
Database row bindings which are represented by instances of the Relation class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Application
protected Relation
protected Relation
-
Constructor Summary
ConstructorsConstructorDescriptionDbMapping
(Application app, String parentTypeName) Create an internal DbMapping used for "virtual" mappings aka collections, mountpoints etc.DbMapping
(Application app, String typename, Properties props) Create a DbMapping from a type.properties property fileDbMapping
(Application app, String typename, Properties props, boolean virtual) Create a DbMapping from a type.properties property file -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDependency
(DbMapping dbmap) Register a DbMapping that depends on this DbMapping, so that collections of other mapping should be reloaded if data on this mapping is updated.void
addJoinConstraints
(StringBuffer s, String pre) Add constraints to select query string to join object referencesprotected void
appendCondition
(StringBuffer q, String column, String val) Append a sql-condition for the given column which must have the value given to the given StringBuffer.protected void
appendCondition
(StringBuffer q, String column, String[] values) Append a sql-condition for the given column which must have one of the values contained inside the given Set to the given StringBuffer.static boolean
areStorageCompatible
(DbMapping dbm1, DbMapping dbm2) Static utility method to check whether two DbMappings use the same storage.columnNameToProperty
(String columnName) Translate a database column name to an object property name according to this mapping.columnNameToRelation
(String columnName) Translate a database column name to an object property name according to this mapping.Get the application this DbMapping belongs to.Get the name of this mapping's applicationDbColumn[]
Return an array of DbColumns for the relational table mapped by this DbMapping.Get a JDBC connection for this DbMapping.Get the DbSource object for this DbMapping.Get the dbsource name used for this type mapping.getExactPropertyRelation
(String propname) Get the name of this type's parent type, if any.get the id-value of this extensionString[]
Returns the Set of Prototypes extending this prototypeIf subnodes are grouped by one of their properties, return the db-mapping with the right relations to create the group-by nodesGet the primary key column name for objects using this mapping.getIDgen()
Relation[]
getJoins()
Return the array of relations that are fetched with objects of this type.long
Get the last time something changed in our datalong
Get the last time something changed in the MappingGet the column used for (internal) names of objects of this type.protected long
getNewID
(long dbmax) Helper method to generate a new ID.Get the mapping we inherit from, or nullGet our ResourcePropertiesReturn an enumeration of all properties defined by this db mapping.getPropertyMapping
(String propname) String[]
Return the list of defined property names as String array.getPropertyRelation
(String propname) Get the column used for names of prototype.Looks up the prototype name identified by the given id, returing our own type name if it can't be resolvedGet a StringBuffer initialized to the first part of the select statement for objects defined by this DbMappingReturn the name of the prototype which specifies the storage location (dbsource + tablename) for this type, or null if it is stored in the embedded db.getSubProperties
(String prefix) Get the table name used for this type mapping.Get the name of the object type this DbMapping belongs to.protected boolean
Check whether this DbMapping inherits its storage location from its parent mapping.boolean
isGroup()
Find if this DbMapping describes a group node.boolean
isH2()
Is the database behind this a H2 db?boolean
isInstanceOf
(String other) Return true if this db mapping represents the prototype indicated by the string argument, either itself or via one of its parent prototypes.boolean
isMySQL()
Is the database behind this a MySQL db?boolean
isOracle()
Is the database behind this an Oracle db?boolean
Is the database behind this a PostgreSQL db?boolean
Tell whether this data mapping maps to a relational database table.boolean
isStorageCompatible
(DbMapping other) Tell if this DbMapping uses the same storage as the given DbMapping.boolean
Find if this DbMapping describes a virtual node (collection, mountpoint, groupnode)boolean
Find whether a node with this DbMapping must be stored in the database.boolean
needsQuotes
(String columnName) Return true if values for the column identified by the parameter need to be quoted in SQL queries.boolean
Tell the type manager whether we need update() to be calledpropertyToColumnName
(String propName) Translate an object property name to a database column name according to this mapping.propertyToRelation
(String propName) Translate an object property name to a database column name according to this mapping.void
remove()
Method in interface Updatable.protected void
Set the last time something changed in the data.void
Set the last time something changed in the data, propagating the event to mappings that depend on us through an additionalTables switch.void
toString()
Return a string representation for this DbMappingvoid
update()
Read the mapping from the Properties.
-
Field Details
-
app
-
subRelation
-
propRelation
-
-
Constructor Details
-
DbMapping
Create an internal DbMapping used for "virtual" mappings aka collections, mountpoints etc. -
DbMapping
Create a DbMapping from a type.properties property file -
DbMapping
Create a DbMapping from a type.properties property file
-
-
Method Details
-
needsUpdate
public boolean needsUpdate()Tell the type manager whether we need update() to be called -
update
public void update()Read the mapping from the Properties. Return true if the properties were changed. The read is split in two, this method and the rewire method. The reason is that in order for rewire to work, all other db mappings must have been initialized and registered. -
getExtensions
Returns the Set of Prototypes extending this prototype- Returns:
- the Set of Prototypes extending this prototype
-
getPrototypeName
Looks up the prototype name identified by the given id, returing our own type name if it can't be resolved- Parameters:
id
- the id specified for the prototype- Returns:
- the name of the extending prototype
-
getExtensionId
get the id-value of this extension -
remove
public void remove()Method in interface Updatable. -
getConnection
Get a JDBC connection for this DbMapping.- Throws:
ClassNotFoundException
SQLException
-
getDbSource
Get the DbSource object for this DbMapping. The DbSource describes a JDBC data source including URL, JDBC driver, username and password. -
getDbSourceName
Get the dbsource name used for this type mapping. -
getTableName
Get the table name used for this type mapping. -
getApplication
Get the application this DbMapping belongs to. -
getAppName
Get the name of this mapping's application -
getTypeName
Get the name of the object type this DbMapping belongs to. -
getExtends
Get the name of this type's parent type, if any. -
getIDField
Get the primary key column name for objects using this mapping. -
getNameField
Get the column used for (internal) names of objects of this type. -
getPrototypeField
Get the column used for names of prototype. -
columnNameToProperty
Translate a database column name to an object property name according to this mapping. -
propertyToColumnName
Translate an object property name to a database column name according to this mapping. If no mapping is found, the property name is returned, assuming property and column names are equal. -
columnNameToRelation
Translate a database column name to an object property name according to this mapping. -
propertyToRelation
Translate an object property name to a database column name according to this mapping. -
getParentSetting
- Returns:
- the parent info as unparsed string.
-
getParentInfo
- Returns:
- the parent info array, which tells an object of this type how to determine its parent object.
-
getSubnodeMapping
- Returns:
- ...
-
getPropertyMapping
- Parameters:
propname
- ...- Returns:
- ...
-
getGroupbyMapping
If subnodes are grouped by one of their properties, return the db-mapping with the right relations to create the group-by nodes -
setPropertyRelation
- Parameters:
rel
- ...
-
getSubnodeRelation
- Returns:
- ...
-
getPropertyNames
Return the list of defined property names as String array. -
getPropertyRelation
- Parameters:
propname
- ...- Returns:
- ...
-
getExactPropertyRelation
- Parameters:
propname
- ...- Returns:
- ...
-
getSubnodeGroupby
- Returns:
- ...
-
getIDgen
- Returns:
- ...
-
getWrappedNodeManager
- Returns:
- ...
-
isRelational
public boolean isRelational()Tell whether this data mapping maps to a relational database table. This returns true if a datasource is specified, even if it is not a valid one. Otherwise, objects with invalid mappings would be stored in the embedded db instead of an error being thrown, which is not what we want. -
getColumns
Return an array of DbColumns for the relational table mapped by this DbMapping.- Throws:
ClassNotFoundException
SQLException
-
getJoins
Return the array of relations that are fetched with objects of this type. -
getColumn
- Parameters:
columnName
- ...- Returns:
- ...
- Throws:
ClassNotFoundException
- ...SQLException
- ...
-
getSelect
Get a StringBuffer initialized to the first part of the select statement for objects defined by this DbMapping- Parameters:
rel
- the Relation we use to select. Currently only used for optimizer hints. Is null if selecting by primary key.- Returns:
- the StringBuffer containing the first part of the select query
-
getInsert
- Returns:
- ...
- Throws:
ClassNotFoundException
SQLException
-
getUpdate
- Returns:
- ...
-
needsQuotes
Return true if values for the column identified by the parameter need to be quoted in SQL queries.- Throws:
SQLException
ClassNotFoundException
-
addJoinConstraints
Add constraints to select query string to join object references -
isOracle
public boolean isOracle()Is the database behind this an Oracle db?- Returns:
- true if the dbsource is using an oracle JDBC driver
-
isMySQL
public boolean isMySQL()Is the database behind this a MySQL db?- Returns:
- true if the dbsource is using a MySQL JDBC driver
-
isPostgreSQL
public boolean isPostgreSQL()Is the database behind this a PostgreSQL db?- Returns:
- true if the dbsource is using a PostgreSQL JDBC driver
-
isH2
public boolean isH2()Is the database behind this a H2 db?- Returns:
- true if the dbsource is using a H2 JDBC driver
-
toString
Return a string representation for this DbMapping -
getLastTypeChange
public long getLastTypeChange()Get the last time something changed in the Mapping- Returns:
- time of last mapping change
-
getLastDataChange
public long getLastDataChange()Get the last time something changed in our data- Returns:
- time of last data change
-
setLastDataChange
public void setLastDataChange()Set the last time something changed in the data, propagating the event to mappings that depend on us through an additionalTables switch. -
setIndirectDataChange
protected void setIndirectDataChange()Set the last time something changed in the data. This is already an indirect data change triggered by a mapping we depend on, so we don't propagate it to mappings that depend on us through an additionalTables switch. -
getNewID
protected long getNewID(long dbmax) Helper method to generate a new ID. This is only used in the special case when using the select(max) method and the underlying table is still empty.- Parameters:
dbmax
- the maximum value already stored in db- Returns:
- a new and hopefully unique id
-
getPropertyEnumeration
Return an enumeration of all properties defined by this db mapping.- Returns:
- the property enumeration
-
getStorageTypeName
Return the name of the prototype which specifies the storage location (dbsource + tablename) for this type, or null if it is stored in the embedded db. -
inheritsStorage
protected boolean inheritsStorage()Check whether this DbMapping inherits its storage location from its parent mapping. The raison d'etre for this is that we need to detect inherited storage even if the dbsource and table are explicitly set in the extended mapping.- Returns:
- true if this mapping shares its parent mapping storage
-
areStorageCompatible
Static utility method to check whether two DbMappings use the same storage.- Returns:
- true if both use the embedded database or the same relational table.
-
isStorageCompatible
Tell if this DbMapping uses the same storage as the given DbMapping.- Returns:
- true if both use the embedded database or the same relational table.
-
isInstanceOf
Return true if this db mapping represents the prototype indicated by the string argument, either itself or via one of its parent prototypes. -
getParentMapping
Get the mapping we inherit from, or null- Returns:
- the parent DbMapping, or null
-
getProperties
Get our ResourceProperties- Returns:
- our properties
-
getSubProperties
-
addDependency
Register a DbMapping that depends on this DbMapping, so that collections of other mapping should be reloaded if data on this mapping is updated.- Parameters:
dbmap
- the DbMapping that depends on us
-
appendCondition
protected void appendCondition(StringBuffer q, String column, String[] values) throws SQLException, ClassNotFoundException Append a sql-condition for the given column which must have one of the values contained inside the given Set to the given StringBuffer.- Parameters:
q
- the StringBuffer to append tocolumn
- the column which must match one of the valuesvalues
- the list of values- Throws:
SQLException
ClassNotFoundException
-
appendCondition
protected void appendCondition(StringBuffer q, String column, String val) throws SQLException, ClassNotFoundException Append a sql-condition for the given column which must have the value given to the given StringBuffer.- Parameters:
q
- the StringBuffer to append tocolumn
- the column which must match one of the valuesval
- the value- Throws:
SQLException
ClassNotFoundException
-
isVirtual
public boolean isVirtual()Find if this DbMapping describes a virtual node (collection, mountpoint, groupnode)- Returns:
- true if this instance describes a virtual node.
-
isGroup
public boolean isGroup()Find if this DbMapping describes a group node.- Returns:
- true if this instance describes a group node.
-
needsPersistence
public boolean needsPersistence()Find whether a node with this DbMapping must be stored in the database. This is true if this mapping defines a non-virtual node, or a virtual node with non-relational child objects.- Returns:
- true if this node needs to be stored in the db, false otherwise
-