Package org.apache.empire.db
Class DBColumn
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBExpr
org.apache.empire.db.DBColumnExpr
org.apache.empire.db.DBColumn
- All Implemented Interfaces:
Column,ColumnExpr
- Direct Known Subclasses:
DBCommandExpr.DBCmdColumn,DBQueryColumn,DBTableColumn,DBView.DBViewColumn
This is the base class for all database columns that have a physical representation.
i.e. either table or view columns (DBTableColumn oder DBViewColumn)
The column object describes a database column and thus provides metadata. Other non data model specific metadata may be added through attributes.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected final Stringprotected Booleanprotected final DBRowSetFields inherited from class org.apache.empire.db.DBColumnExpr
attributes, beanPropertyName, optionsFields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUEFields inherited from interface org.apache.empire.data.Column
COLATTR_CASESENSITIVE, COLATTR_CURRENCY_CODE, COLATTR_ENUMTYPE, COLATTR_FRACTION_DIGITS, COLATTR_INTEGER_DIGITS, COLATTR_MAXVALUE, COLATTR_MINLENGTH, COLATTR_MINVALUE, COLATTR_NORMCOLUMN, COLATTR_NULLTEXT, COLATTR_NUMBER_GROUPSEP, COLATTR_NUMBER_TYPE, COLATTR_REFCOLUMNS, COLATTR_REGEXP, COLATTR_SORTDESCENDING, COLATTR_SORTEXPRESSION, COLATTR_TITLE, COLATTR_TOOLTIP, COLATTR_TYPE, NUMTYPE_CURRENCY, NUMTYPE_DECIMAL, NUMTYPE_INTEGER, NUMTYPE_PERCENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReferencedColumns(Set<DBColumn> list) Internal function to obtain all DBColumnExpr-objects used by this expression.voidaddSQL(DBSQLBuilder sql, long context) Adds the colunm name to the SQL-Command.abstract ElementAppends column meta information to the parent elementcoalesceColumn(Object nullValue) Creates a column expression with coalesce and renames it to this columnCreates and returns a sql-expression that maps enum values by name or ordinal to their string representationdecodeSort(boolean defaultToEnd) Creates and returns a sql-expression that maps enum values from name to ordinalbooleanCustom serialization for transient rowset.getAlias()returns the qualified alias name for this columngetAttribute(String name) Returns the value of a column attribute.Returns all metadata attributes.Returns a comment describing the column in the data scheme.final DBDatabaseReturns the database object to which this object belongs to.Returns the Entity Type Same as getRowSet()Returns the enum type for this columnReturns the full qualified column name.Gets an identifier for this RowSet ObjectClass<?>Returns the java type for this columngetName()Returns the column name.Returns the normalized column for the columnExpr (if any)Returns the list of options for this column containing all possible field values.Returns the maximum allowed valueReturns DBTable, DBQuery or DBView object.abstract doublegetSize()Returns the size of the column.Returns the sort expression for a given column If no sort expression is explicitly set then the column itself is returned The returned expression should be assigned to an DBCommand.orderBy() function.Returns itself as the underlying column.inthashCode()booleanAlways returns false since DBColumns cannot be aggregates.abstract booleanReturns true if column is a columns value is an automatically generated valuefinal booleanisEnum()Returns true if an enum type has been set for this columnabstract booleanReturns true if the column is read-only.abstract booleanReturns true if the column is required.returns an expression that renames the column with its alias nameReturns a reference expression for this column This can be used to reference a parent column in a subqueryfinal <T extends DBColumn>
TSets the case sensitivity of the column to insensitive Text columns are case sensitive by default<T extends DBColumn>
TsetCaseSensitive(Boolean caseSensitiv) Sets the case sensitivity of the columnExprvoidsetComment(String comment) Sets a comment describing the current column.<T extends Column>
TsetNormalizedColumn(DBColumnExpr normalizedColumn) Sets a normalized columnExpr for this columnExprfinal <T extends DBColumn>
TsetNumberType(String numberType) Sets the number type to a given value<T extends DBColumn>
TsetRegExPattern(String regex) Set the regular expression to validate the columnExpr value<T extends DBColumn>
TsetSortExpr(String sortFunctionTemplate) Sets a sort function template for a given column<T extends DBColumn>
TsetSortExpr(DBColumnExpr sortExpression) Sets a sort function expression for a given columnCreates and returns a new DBSetExpr object.toString()Override the toString method.abstract ObjectvalidateValue(Object value) Checks if the given value is a valid value for this column If not, an exception is thrownMethods inherited from class org.apache.empire.db.DBColumnExpr
abs, aggregate, append, as, as, asc, avg, ceiling, cmp, coalesce, concat, concat, contains, convertTo, convertTo, count, countDistinct, day, decode, decode, decode, decode, decode, decode, decodeEnum, decodeSort, desc, divideBy, floor, format, function, getAttribute, getBeanPropertyName, getControlType, getDataType, getDefaultSortOrder, getExprFromPhrase, getExprFromPhrase, getIgnoreCaseExpr, getNumberType, getSourceColumn, getTitle, in, in, in, indexOf, indexOf, indexOf, is, isBetween, isCaseSensitive, isGreaterThan, isLessOrEqual, isLiteralValue, isMoreOrEqual, isNot, isNotBetween, isSmallerThan, length, like, like, likeLower, likeUpper, lower, max, min, minus, minus, modulo, month, multiplyWith, notContains, notIn, notIn, notIn, notLike, nvl, on, parenthesis, plus, plus, prepend, replace, reverse, round, setAttribute, setBeanPropertyName, setControlType, setDefaultSortOrder, setOptions, setTitle, stringAgg, stringAgg, substring, substring, substring, substring, substring, substring, sum, toChar, toChar, trim, trimLeft, trimRight, trunc, upper, when, yearMethods inherited from class org.apache.empire.db.DBObject
checkParamNullMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.empire.data.ColumnExpr
getBeanPropertyName, getControlType, getDataType, getSourceColumn, getTitle, setAttribute
-
Field Details
-
rowset
-
name
-
comment
-
quoteName
-
-
Constructor Details
-
DBColumn
Constructs a DBColumn object and set the specified parameters to this object.- Parameters:
rowset- the rowset (i.e. Table or View) that this column belongs toname- the column name
-
-
Method Details
-
getIdentifier
Gets an identifier for this RowSet Object- Returns:
- the rowset identifier
-
equals
Custom serialization for transient rowset. private void writeObject(ObjectOutputStream strm) throws IOException { // RowSet strm.writeObject(rowset.getDatabase().getIdentifier()); strm.writeObject(rowset.getName()); // write default strm.defaultWriteObject(); } private void readObject(ObjectInputStream strm) throws IOException, ClassNotFoundException { String dbid = String.valueOf(strm.readObject()); String rsid = String.valueOf(strm.readObject()); // find database DBDatabase dbo = DBDatabase.findByIdentifier(dbid); if (dbo==null) throw new ClassNotFoundException(dbid); // find rowset DBRowSet rso = dbo.getRowSet(rsid); if (rso==null) throw new ClassNotFoundException(dbid+"."+rsid); // set final field ClassUtils.setPrivateFieldValue(DBColumn.class, this, "rowset", rso); // read the rest strm.defaultReadObject(); } -
hashCode
public int hashCode() -
getSize
public abstract double getSize()Returns the size of the column. -
isRequired
public abstract boolean isRequired()Returns true if the column is required.- Specified by:
isRequiredin interfaceColumn- Returns:
- Returns true if the column is required
-
isAutoGenerated
public abstract boolean isAutoGenerated()Returns true if column is a columns value is an automatically generated value- Specified by:
isAutoGeneratedin interfaceColumn- Returns:
- true if column is auto-generated
-
isReadOnly
public abstract boolean isReadOnly()Returns true if the column is read-only.- Specified by:
isReadOnlyin interfaceColumn- Returns:
- Returns true if the column is read-only
-
validateValue
Checks if the given value is a valid value for this column If not, an exception is thrown- Specified by:
validateValuein interfaceColumn- Parameters:
value- the value to validate- Returns:
- the value the validated and possibly converted value
-
addXml
Appends column meta information to the parent element- Specified by:
addXmlin classDBColumnExpr- Parameters:
parent- the parent element to which to append the column descriptionflags- currently not used- Returns:
- the newly created child element
-
getDatabase
Description copied from class:DBObjectReturns the database object to which this object belongs to. For the database object itself this function will return the this pointer.- Specified by:
getDatabasein classDBObject- Returns:
- the current DBDatabase object
-
addReferencedColumns
Description copied from class:DBExprInternal function to obtain all DBColumnExpr-objects used by this expression.- Specified by:
addReferencedColumnsin classDBExpr- Parameters:
list- list to which all used column expressions must be added- See Also:
-
addSQL
Adds the colunm name to the SQL-Command.
This can be either a qualified or unqualified name depending on the context. -
getName
Returns the column name.- Specified by:
getNamein interfaceColumnExpr- Specified by:
getNamein classDBColumnExpr- Returns:
- the column name
-
getRowSet
Returns DBTable, DBQuery or DBView object.- Specified by:
getRowSetin classDBColumnExpr- Returns:
- the DBTable, DBQuery or DBView object
-
getEntity
Returns the Entity Type Same as getRowSet() -
getUpdateColumn
Returns itself as the underlying column.- Specified by:
getUpdateColumnin interfaceColumnExpr- Specified by:
getUpdateColumnin classDBColumnExpr- Returns:
- the underlying column
-
isAggregate
public boolean isAggregate()Always returns false since DBColumns cannot be aggregates.- Specified by:
isAggregatein classDBColumnExpr- Returns:
- false
-
reference
Returns a reference expression for this column This can be used to reference a parent column in a subquery- Returns:
- the column value expression
-
getFullName
Returns the full qualified column name.- Returns:
- the full qualified column name
-
getAlias
returns the qualified alias name for this column- Returns:
- the alias
-
qualified
returns an expression that renames the column with its alias name- Overrides:
qualifiedin classDBColumnExpr- Returns:
- a qualified expression for this column
-
coalesceColumn
Creates a column expression with coalesce and renames it to this column- Parameters:
nullValue- the alternative value when this column is null- Returns:
- the coalesce and alias expression
-
getAttribute
Description copied from class:DBColumnExprReturns the value of a column attribute. Column attributes are used to provide metadata for a column.- Specified by:
getAttributein interfaceColumnExpr- Overrides:
getAttributein classDBColumnExpr- Parameters:
name- the attribute name- Returns:
- value of the attribute if it exists or null otherwise
- See Also:
-
getAttributes
Returns all metadata attributes.- Specified by:
getAttributesin interfaceColumn- Returns:
- set of metadata attributes
-
getOptions
Description copied from class:DBColumnExprReturns the list of options for this column containing all possible field values.- Specified by:
getOptionsin interfaceColumnExpr- Overrides:
getOptionsin classDBColumnExpr- Returns:
- the list of options
-
isEnum
public final boolean isEnum()Returns true if an enum type has been set for this column- Returns:
- true if an enum type has been set for this column or false otherwise
-
getEnumType
Returns the enum type for this column- Specified by:
getEnumTypein interfaceColumnExpr- Returns:
- the enum type
-
getJavaType
Returns the java type for this column- Overrides:
getJavaTypein classDBColumnExpr- Returns:
- the java type
-
setCaseSensitive
Sets the case sensitivity of the columnExpr- Parameters:
caseSensitiv- the character casing. This may be true, false or null (default)- Returns:
- self (this)
-
setCaseInsensitive
Sets the case sensitivity of the column to insensitive Text columns are case sensitive by default- Returns:
- self (this)
-
setNumberType
Sets the number type to a given value- Parameters:
numberType- the number type. See Column.NUMTYPE_... constants- Returns:
- self (this)
-
getRegExPattern
Returns the maximum allowed value- Returns:
- the minimum length
-
setRegExPattern
Set the regular expression to validate the columnExpr value- Parameters:
regex- the regular expression- Returns:
- self (this)
-
getNormalizedColumn
Returns the normalized column for the columnExpr (if any)- Returns:
- the normalized column or null
-
setNormalizedColumn
Sets a normalized columnExpr for this columnExpr- Parameters:
normalizedColumn- the normalized columnExpr- Returns:
- self (this)
-
getSortExpr
Returns the sort expression for a given column If no sort expression is explicitly set then the column itself is returned The returned expression should be assigned to an DBCommand.orderBy() function.- Returns:
- the sort expression or the column itself if not sort expression is set
-
setSortExpr
Sets a sort function expression for a given column- Parameters:
sortExpression- the expression which to use for sorting- Returns:
- self (this)
-
decodeEnum
Creates and returns a sql-expression that maps enum values by name or ordinal to their string representation- Returns:
- a DBDecodeExpr object
-
decodeSort
Creates and returns a sql-expression that maps enum values from name to ordinal- Parameters:
defaultToEnd- flag whether to put the default item to the end- Returns:
- a DBDecodeExpr object
-
setSortExpr
Sets a sort function template for a given column- Parameters:
sortFunctionTemplate- the template which must contain a ? which will be replaced with the column name- Returns:
- return the column
-
to
Creates and returns a new DBSetExpr object.- Parameters:
value- the Object value- Returns:
- the new DBSetExpr object
- See Also:
-
toString
Override the toString method.- Overrides:
toStringin classDBColumnExpr- Returns:
- the table name and the column name (e.g. CUSTOMER.ID)
-
getComment
Returns a comment describing the column in the data scheme.- Returns:
- Returns the comment.
-
setComment
Sets a comment describing the current column.- Parameters:
comment- the column comment
-