org.sormula.annotation
Annotation Type Column


@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface Column

Defines column attributes for a row class variable. If no Column annotaion is used for a row class variable, that is equivalent to "@Column" (all defaults are used). Annotates a class variable.

Since:
1.0
Author:
Jeff Miller

Optional Element Summary
 boolean identity
          Indicates that column is declared as "GENERATED ...
 java.lang.String name
          SQL name of column.
 boolean primaryKey
          Indicates that column is the primary key for row.
 java.lang.Class<? extends ColumnTranslator> translator
          Defines class that will read/write row members from/to database.
 

name

public abstract java.lang.String name
SQL name of column. If not specified then name is Field.getName() or is obtained from NameTranslator.translate(String, Class) if translator is configured for table.

Returns:
name of column
Default:
""

primaryKey

public abstract boolean primaryKey
Indicates that column is the primary key for row. A composite primary key may be defined if key is composed of more than one column by annotation each key field and setting this true.

This must be set to true for all columns needed with Table.select(Object...) or if update or delete operations are to be performed.

Returns:
true if column is primary key
Default:
false

identity

public abstract boolean identity
Indicates that column is declared as "GENERATED ... AS IDENTITY ...". Column gets generated by the databases when rows are inserted. Upon insert, row object will be updated with the auto generated key.

When identity==true, implies that primaryKey==true so that primaryKey does not need to be specified. Only one identity column is allowed per row class.

If true, Connection.prepareStatement(String, int) will be used to prepare insert statements to return auto generated keys. Some JDBC drivers do not support auto generated keys even though the database may allow "GENERATED ... AS IDENTITY ..." in column declaration. Your driver will report operation not supported or function not supported exceptions if it does not support auto generated keys.

If false, Connection.prepareStatement(String) will be used to prepare insert statements. Connection.prepareStatement(String) is supported by most JDBC drivers.

Returns:
true to set field with value from Statement.getGeneratedKeys()
Default:
false

translator

public abstract java.lang.Class<? extends ColumnTranslator> translator
Defines class that will read/write row members from/to database.

Returns:
translator to use for reading and writing values from/to the database
Default:
org.sormula.translator.standard.StandardColumnTranslator.class