public class BasicSchema extends java.lang.Object implements RelationalSchema
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.util.Map<SchemaAttr,java.lang.String>> |
columns |
protected java.util.Map<java.lang.String,DataObject.ObjectType> |
columnTypes
Maps column names to a nested map of properties or attributes about the column.
|
protected java.util.Set<SchemaForeignKey> |
fks |
protected java.util.Set<SchemaKey> |
keys |
protected java.lang.String |
name |
protected SchemaKey |
primaryKey |
Constructor and Description |
---|
BasicSchema(BasicSchema other)
Copies the schema without the events
|
BasicSchema(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
RelationalSchema |
addAttr(java.lang.String column,
SchemaAttr attr,
java.lang.String attrVal)
Add an arbitrary attribute to the schema.
|
RelationalSchema |
addColumn(java.lang.String column,
DataObject.ObjectType type)
add a column to the AbstractSchema
|
RelationalSchema |
addColumn(java.lang.String column,
DataObject.ObjectType type,
java.util.Map<SchemaAttr,java.lang.String> attrs)
add a column to the schema with the given attributes
|
RelationalSchema |
addDefaultColumn(java.lang.String column) |
DataManagerEventListener |
addEventListener(DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener)
Adds an event listener using a default priority
|
DataManagerEventListener |
addEventListenerWithPriority(DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener,
int priority)
Add an event listener with a specified execution priority.
|
RelationalSchema |
addForeignKey(SchemaForeignKey fk)
manually add the foreign key relationship, this would be used to link schemas if the database engine doesn't support foreign keys.
|
RelationalSchema |
addForeignKey(java.lang.String localColumn,
java.lang.String parentSchema,
java.lang.String parentColumn)
manually add the foreign key relationship, this would be used to link schemas if the database engine doesn't support foreign keys.
|
RelationalSchema |
addIndex(SchemaKey key)
Set a column as a key column in the schema
|
boolean |
containsAllColumns(java.util.Set<java.lang.String> columns)
returns whether the Schema contains the specified column, case insensitive
|
boolean |
containsColumn(java.lang.String column)
returns whether the Schema contains the specified column, case insensitive
|
java.util.Map<java.lang.String,DataObject> |
convertToDataObject(java.util.Map<java.lang.String,java.lang.Object> data) |
DataObject |
convertToDataObject(java.lang.String column,
java.lang.Object o)
convert an Object to a DataObject.
|
boolean |
equals(java.lang.Object o) |
void |
fireEvent(DataManagerEventSource.EventFireTime when,
DataManagerEvent evt)
Fires an event
|
java.lang.String |
getAttr(java.lang.String column,
SchemaAttr attr)
retrieve an attribute value from the schema
|
java.util.Map<SchemaAttr,java.lang.String> |
getAttrs(java.lang.String column)
retrieve all the attribute values for a specific column
|
java.util.Set<java.lang.String> |
getAutoGeneratedColumns()
retrieve the columns whose values are Auto-generated (don't need to be added via the DataManager.addData method)
|
java.util.Set<java.lang.String> |
getColumns()
retrieve all the columns in the Schema
|
java.util.Map<SchemaAttr,java.lang.String> |
getDefaultAttrs() |
java.util.Map<java.lang.String,DataObject> |
getDefaultValues()
returns a map with the default values for columns
|
java.util.List<DataManagerEventListener> |
getEventListeners(DataManagerEventSource.EventFireTime when)
Returns all the event listeners for this schema that fire at the specified time
|
java.util.Set<SchemaForeignKey> |
getForeignKeys()
retrieve the foreign keys associated with this schema.
|
java.util.Set<SchemaForeignKey> |
getForeignKeys(java.lang.String parentTable)
Retrieve the column that points to the Foreign table
|
java.util.Set<java.lang.String> |
getForeignTables()
returns all of the tables that the schema has foreign keys for
|
java.util.Set<SchemaKey> |
getKeys() |
java.lang.String |
getName()
returns the name of the schema, for databases this corresponds to the table name
|
DataObject.ObjectType |
getObjectType(java.lang.String column)
Returns the ObjectType corresponding to the column.
|
DataObject.ValueParser |
getParser(java.lang.String column) |
SchemaKey |
getPrimaryKey()
retrieve the primary key associated with this schema.
|
java.util.Set<SchemaKey> |
getUniqueIndexes()
retrieve the non-primary key unique index's associated with the schema
|
int |
hashCode() |
RelationalSchema |
removeEventListener(DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener)
Removes an event listener
|
void |
removeParser(java.lang.String column) |
void |
setDateFormat(java.lang.String column,
java.text.DateFormat dateFormat)
Sets the date format used for a column to parse strings to dates
|
void |
setDateFormat(java.lang.String column,
java.time.format.DateTimeFormatter dateFormat)
Sets the date format used for a column to parse strings to dates
|
RelationalSchema |
setObjectType(java.lang.String column,
DataObject.ObjectType type)
Sets the object type of the column.
|
void |
setParser(java.lang.String column,
DataObject.ValueParser parser)
Sets a custom parser used to parse the data for the specified column
|
RelationalSchema |
setPrimaryKey(SchemaKey primary)
Sets the primary key for this schema
|
java.lang.String |
toString()
Prints (effectively) debug information about the this AbstractSchema.
|
protected java.util.Map<java.lang.String,DataObject.ObjectType> columnTypes
protected java.util.Map<java.lang.String,java.util.Map<SchemaAttr,java.lang.String>> columns
protected java.util.Set<SchemaKey> keys
@NotNull protected final java.util.Set<SchemaForeignKey> fks
protected SchemaKey primaryKey
protected java.lang.String name
public BasicSchema(java.lang.String name)
public BasicSchema(@NotNull BasicSchema other)
other
- The schema to copy@NotNull public RelationalSchema addColumn(java.lang.String column, @NotNull DataObject.ObjectType type)
addColumn
in interface RelationalSchema
column
- The column to addtype
- The data type of the column@NotNull public RelationalSchema addColumn(java.lang.String column, @NotNull DataObject.ObjectType type, @Nullable java.util.Map<SchemaAttr,java.lang.String> attrs)
addColumn
in interface RelationalSchema
column
- The column to addtype
- The type of the columnattrs
- Any attributes of the columnpublic java.util.Map<SchemaAttr,java.lang.String> getDefaultAttrs()
@NotNull public RelationalSchema addDefaultColumn(java.lang.String column)
@NotNull public RelationalSchema setObjectType(java.lang.String column, @NotNull DataObject.ObjectType type)
RelationalSchema
setObjectType
in interface RelationalSchema
column
- The column to set a type fortype
- The type to set as being in the column@NotNull public RelationalSchema addAttr(@Nullable java.lang.String column, @Nullable SchemaAttr attr, java.lang.String attrVal)
addAttr
in interface RelationalSchema
column
- The name of the columnattr
- The attribute to addattrVal
- The value of the attribute@NotNull public RelationalSchema addForeignKey(SchemaForeignKey fk)
addForeignKey
in interface RelationalSchema
fk
- The foreign key to add@NotNull public RelationalSchema addForeignKey(java.lang.String localColumn, java.lang.String parentSchema, java.lang.String parentColumn)
localColumn
- The name of the column on this schema that references the parent tableparentSchema
- The schema name of the parentparentColumn
- The column name on the parent schema@NotNull public java.util.Map<java.lang.String,DataObject> convertToDataObject(@NotNull java.util.Map<java.lang.String,java.lang.Object> data)
@NotNull public java.util.Set<java.lang.String> getForeignTables()
@NotNull public java.util.Set<java.lang.String> getAutoGeneratedColumns()
RelationalSchema
getAutoGeneratedColumns
in interface RelationalSchema
public boolean containsColumn(@NotNull java.lang.String column)
RelationalSchema
containsColumn
in interface RelationalSchema
column
- The column to check forpublic boolean containsAllColumns(@NotNull java.util.Set<java.lang.String> columns)
RelationalSchema
containsAllColumns
in interface RelationalSchema
columns
- The columns to check for@NotNull public java.util.Set<java.lang.String> getColumns()
RelationalSchema
getColumns
in interface RelationalSchema
public java.util.Map<SchemaAttr,java.lang.String> getAttrs(java.lang.String column)
RelationalSchema
getAttrs
in interface RelationalSchema
column
- The column to get information forpublic DataObject.ObjectType getObjectType(java.lang.String column)
RelationalSchema
getObjectType
in interface RelationalSchema
column
- The column to get information forpublic void setDateFormat(@NotNull java.lang.String column, @NotNull java.text.DateFormat dateFormat)
RelationalSchema
setDateFormat
in interface RelationalSchema
column
- The column to set the format fordateFormat
- The date format used to convert strings to dates for this columnpublic void setDateFormat(@NotNull java.lang.String column, @NotNull java.time.format.DateTimeFormatter dateFormat)
RelationalSchema
setDateFormat
in interface RelationalSchema
column
- The column to set the format fordateFormat
- The date format used to convert strings to dates for this column@Nullable public java.lang.String getAttr(@NotNull java.lang.String column, SchemaAttr attr)
RelationalSchema
getAttr
in interface RelationalSchema
column
- The column to get information forattr
- The attribute to get the value for@NotNull public java.util.Map<java.lang.String,DataObject> getDefaultValues()
getDefaultValues
in interface RelationalSchema
@Nullable public DataObject convertToDataObject(java.lang.String column, @Nullable java.lang.Object o)
RelationalSchema
convertToDataObject
in interface RelationalSchema
column
- The column the object will be added too
- The object given that should be converted to the type of the columnpublic java.lang.String getName()
getName
in interface RelationalSchema
@NotNull public java.lang.String toString()
toString
in class java.lang.Object
@NotNull public DataManagerEventListener addEventListener(@NotNull DataManagerEventSource.EventFireTime when, @NotNull DataManagerEventListener listener)
RelationalSchema
addEventListener
in interface RelationalSchema
when
- The time when the event should firelistener
- The listener that will handle the event@NotNull public DataManagerEventListener addEventListenerWithPriority(@NotNull DataManagerEventSource.EventFireTime when, @NotNull DataManagerEventListener listener, int priority)
RelationalSchema
addEventListenerWithPriority
in interface RelationalSchema
when
- The time when the event should firelistener
- The listener that will handle the eventpriority
- The priority for the event, with lower numbers being higher priority. Should be greater than Integer.MIN_VALUE + 100 (the first 100 values are
reserved for internal use)@NotNull public java.util.List<DataManagerEventListener> getEventListeners(@NotNull DataManagerEventSource.EventFireTime when)
RelationalSchema
getEventListeners
in interface RelationalSchema
when
- The time the events fire@NotNull public RelationalSchema removeEventListener(@NotNull DataManagerEventSource.EventFireTime when, @NotNull DataManagerEventListener listener)
RelationalSchema
removeEventListener
in interface RelationalSchema
when
- The time the event would firelistener
- The listener to removepublic void fireEvent(@NotNull DataManagerEventSource.EventFireTime when, @NotNull DataManagerEvent evt)
RelationalSchema
fireEvent
in interface RelationalSchema
when
- The time to fire all events forevt
- The data of the event that will be fired@NotNull public java.util.Set<SchemaForeignKey> getForeignKeys()
RelationalSchema
getForeignKeys
in interface RelationalSchema
@NotNull public RelationalSchema setPrimaryKey(@NotNull SchemaKey primary)
RelationalSchema
setPrimaryKey
in interface RelationalSchema
primary
- The primary key for the schema@NotNull public RelationalSchema addIndex(SchemaKey key)
RelationalSchema
addIndex
in interface RelationalSchema
key
- The key to add as an indexpublic SchemaKey getPrimaryKey()
RelationalSchema
getPrimaryKey
in interface RelationalSchema
@NotNull public java.util.Set<SchemaKey> getUniqueIndexes()
RelationalSchema
getUniqueIndexes
in interface RelationalSchema
@NotNull public java.util.Set<SchemaForeignKey> getForeignKeys(java.lang.String parentTable)
RelationalSchema
getForeignKeys
in interface RelationalSchema
parentTable
- The name of the parent tablepublic void removeParser(java.lang.String column)
public void setParser(@NotNull java.lang.String column, @NotNull DataObject.ValueParser parser)
RelationalSchema
setParser
in interface RelationalSchema
column
- The column to set a parser forparser
- The parser to use for converting extracted strings to the required typepublic DataObject.ValueParser getParser(java.lang.String column)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object