de.mguennewig.pobjects.metadata
Class ClassDecl

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.Declaration
      extended by de.mguennewig.pobjects.metadata.TableExpr
          extended by de.mguennewig.pobjects.metadata.ClassDecl
All Implemented Interfaces:
SqlEntity

public class ClassDecl
extends TableExpr

A class declaration describes both an application class and an SQL table.

There are three kinds of information:

Author:
Michael Günnewig

Field Summary
 
Fields inherited from class de.mguennewig.pobjects.metadata.Declaration
ARGUMENT_CONSTRUCTOR, CLASS_NAME, DESCRIPTOR, GENERATED_CLASS_NAME, POINTER_TYPE, SQL_ARG_COLON, SQL_ARG_DOLLAR, SQL_ARG_NONE, SQL_ARG_QUESTION_MARK
 
Constructor Summary
ClassDecl(java.lang.String name, java.lang.String schemaName, java.lang.String label, IdField idField, ClassDecl baseClass, boolean extensible, Field[] fields, Join[] joins, Constraint[] constraints, Index[] indices, Field visualField)
          Creates a new class declaration.
 
Method Summary
 void createImplicitConstraints()
          Creates explicit constraints for structures that represent them only implicit.
 ClassDecl getBaseClass()
          If the class is an extension, then this method returns the base class, otherwise null.
 ClassDecl getBottomClass()
           
 Column getColumn(int index)
          
 Column getColumnByName(java.lang.String name)
          Return class field with name name.
 Constraint getConstraint(int n)
           
 Constraint getConstraint(java.lang.String name)
          Returns the Constraint with the given schema name.
 Field getField(int index)
          Return class field for index.
 ForeignKeyConstraint getForeignKeyConstraint(Field field)
          Returns the first found ForeignKeyConstraint that has the given field as one of its source fields.
 IdField getIdField()
          Returns the field which defines the sequence from which the primary keys of this table are taken.
 Index getIndex(int n)
           
 Join getJoinByName(java.lang.String name)
           
 java.lang.String getLabel()
          Returns the string used to refer to this table in the user interface.
 Field[] getLocalFields(boolean includeIdField)
           
 Join[] getLocalJoins()
           
 int getNumColumns()
          Returns number of fields local to this class.
 int getNumConstraints()
           
 int getNumFields()
          Returns number of fields of this class.
 int getNumIndices()
           
 PrimaryKeyConstraint getPrimaryKeyConstraint()
          Returns the PrimaryKeyConstraint of the class.
 java.lang.String getSchemaName()
          Returns the table name within the database schema.
 Field getSortByField()
          Returns the field which should be used to sort a list of objects of this class.
 java.lang.String getSqlFromClause(int sqlArgVariant)
          
 Field getVisualField()
          Returns the field which should be used by the application to render a reference to objects of this class.
 boolean isExtensible()
          Returns true if this class can be used as another class's base type.
 boolean isExtensionOf(TableExpr te)
          Tests whether this table expression is an extension of te.
 boolean isMaterializedTable()
          true iff this class is associated with an existing database table.
 boolean isWritableClass()
          Tests whether this table expression is an ClassDecl that can also be updated.
 java.lang.String name(int variant)
          Returns different names depending on variant for the code generator.
 void setModule(Module module)
          Sets the owning module and resolves the type name.
 
Methods inherited from class de.mguennewig.pobjects.metadata.TableExpr
getClassName
 
Methods inherited from class de.mguennewig.pobjects.metadata.Declaration
getDescription, getModule, getName, setDescription, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjects.metadata.SqlEntity
getModule
 

Constructor Detail

ClassDecl

public ClassDecl(java.lang.String name,
                 java.lang.String schemaName,
                 java.lang.String label,
                 IdField idField,
                 ClassDecl baseClass,
                 boolean extensible,
                 Field[] fields,
                 Join[] joins,
                 Constraint[] constraints,
                 Index[] indices,
                 Field visualField)
Creates a new class declaration. A null in fields, joins, constraints, or indices is expanded into an empty array.

Parameters:
name - The Java class name used for the table.
schemaName - The database schema name used for the table.
label - A label used to describe this class.
idField - Optional ID field. This is required if this table is extensible or a base class is given.
baseClass - Optional base class for this class. If given implies extensible.
extensible - If true this class can be extended.
fields -
joins -
constraints -
indices -
visualField - Optionally specifies a field used for visualizing instances of the described class. If not given the one from the baseClass is used if there is any or the idField. In case the class has no ID field then this must be given.
Throws:
java.lang.IllegalArgumentException - in case any of the following occurs:
  • a baseClass is given and its Id field is not the same as given one
  • no Id field is given but class is extensible or has base class
  • if neither Id field nor visual field is given
  • null has been passed in constraints array
  • an implicit constraint has been passed
Method Detail

setModule

public void setModule(Module module)
Sets the owning module and resolves the type name.

Specified by:
setModule in interface SqlEntity
Overrides:
setModule in class TableExpr

isExtensionOf

public boolean isExtensionOf(TableExpr te)
Tests whether this table expression is an extension of te.

Overrides:
isExtensionOf in class TableExpr
Returns:
true if te either equals this, or is a base table of this, otherwise false.

isWritableClass

public boolean isWritableClass()
Tests whether this table expression is an ClassDecl that can also be updated. Only these tables are mapped onto PObject instances, all others are read-only and retrieved as Record objects.

Overrides:
isWritableClass in class TableExpr

getSchemaName

public final java.lang.String getSchemaName()
Returns the table name within the database schema.


getLabel

public final java.lang.String getLabel()
Returns the string used to refer to this table in the user interface.


getIdField

public final IdField getIdField()
Returns the field which defines the sequence from which the primary keys of this table are taken.

If base class is set, then this field is a copy of the base class's idField. Classes with an id field will be derived from PObject.

If null, then the class cannot be extended and must have a primary key declaration instead. Classes without an id field will be derived from Record.


getBaseClass

public final ClassDecl getBaseClass()
If the class is an extension, then this method returns the base class, otherwise null.

The base class's extensible flag must be true to support extensions. The base class relationship must create a hierarchy. A cyclic dependency, where a class uses itself as a base class, is invalid.


isExtensible

public final boolean isExtensible()
Returns true if this class can be used as another class's base type.

If base class is set, then this is always true. On the SQL level, `extensible' means that the type of rows of this table must be stored explicitly in a separate attribute.


getNumConstraints

public final int getNumConstraints()

getConstraint

public final Constraint getConstraint(int n)

getConstraint

public final Constraint getConstraint(java.lang.String name)
Returns the Constraint with the given schema name.

Parameters:
name - The schema name of the constraint which should be found.
Returns:
The searched constraint or null if no such exists.

getForeignKeyConstraint

public ForeignKeyConstraint getForeignKeyConstraint(Field field)
Returns the first found ForeignKeyConstraint that has the given field as one of its source fields.

Parameters:
field - The field for which a foreign key constraint should be found.
Returns:
the searched constraint or null if no such exists.
Throws:
java.lang.IllegalArgumentException - if field == null.

getPrimaryKeyConstraint

public final PrimaryKeyConstraint getPrimaryKeyConstraint()
Returns the PrimaryKeyConstraint of the class.


getNumIndices

public final int getNumIndices()

getIndex

public final Index getIndex(int n)

getVisualField

public final Field getVisualField()
Returns the field which should be used by the application to render a reference to objects of this class.

The visual field may be null, to indicate that there is no suitable field. In this case, the string representation is undefined. It should be some combination of class name and internal address or external id.


getSortByField

public final Field getSortByField()
Returns the field which should be used to sort a list of objects of this class.

This method returns by defaults the visual field, if missing the id field), or lacking that one null.

See Also:
getPrimaryKeyConstraint()

getNumColumns

public int getNumColumns()
Returns number of fields local to this class. This excludes the class's id field and also all fields from any base class.

Specified by:
getNumColumns in class TableExpr
See Also:
getNumFields()

getColumn

public Column getColumn(int index)

Specified by:
getColumn in class TableExpr

getColumnByName

public final Column getColumnByName(java.lang.String name)
Return class field with name name. If no such field exists, result is null.

Specified by:
getColumnByName in class TableExpr

getNumFields

public final int getNumFields()
Returns number of fields of this class. This excludes the class's id field, but includes all fields inherited from any base classes.

See Also:
getNumColumns()

getField

public final Field getField(int index)
Return class field for index. If the class has no base class, this is equivalent to getColumn(index).


getLocalFields

public final Field[] getLocalFields(boolean includeIdField)

getLocalJoins

public final Join[] getLocalJoins()

getJoinByName

public final Join getJoinByName(java.lang.String name)

getSqlFromClause

public java.lang.String getSqlFromClause(int sqlArgVariant)

Specified by:
getSqlFromClause in class TableExpr

getBottomClass

public final ClassDecl getBottomClass()

isMaterializedTable

public boolean isMaterializedTable()
true iff this class is associated with an existing database table.


createImplicitConstraints

public void createImplicitConstraints()
Creates explicit constraints for structures that represent them only implicit.

Currently only ForeignKeyConstraints will be generated for Fields which refer to another table.


name

public java.lang.String name(int variant)
Returns different names depending on variant for the code generator.

Overrides:
name in class TableExpr
Returns:
variant return value
Declaration.POINTER_TYPE <JavaPackage>.<Name>
Declaration.CLASS_NAME <Name>
Declaration.GENERATED_CLASS_NAME PClass<Name>