
com.draagon.meta.manager.db.defs.TableDef Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metaobjects-omdb Show documentation
Show all versions of metaobjects-omdb Show documentation
Relational Database ObjectManager libraries for MetaData-driven development.
The newest version!
package com.draagon.meta.manager.db.defs;
import java.util.ArrayList;
import java.util.List;
public class TableDef extends BaseTableDef {
private List primaryKeys = new ArrayList();
private List indexes = new ArrayList();
private List foreignKeys = new ArrayList();
private InheritenceDef inheritence = null;
public TableDef( NameDef name ) { // , List cols ) {
super( name ); //, cols );
}
@Override
public void addColumn( ColumnDef col ) {
// Set the columns
super.addColumn( col );
// Pull out the primary keys
if ( col.isPrimaryKey() ) {
addPrimaryKey( col );
}
}
public InheritenceDef getInheritence() {
return inheritence;
}
public void setInheritence(InheritenceDef inheritence) {
this.inheritence = inheritence;
}
public boolean hasInheritence() {
return ( inheritence != null );
}
protected void addPrimaryKey( ColumnDef primaryKey ) {
// Don't have the same primary key more than once
for ( ColumnDef col : getPrimaryKeys() ) {
if ( col.getName().equals( primaryKey.getName() )) return;
}
// Add the primary key
primaryKeys.add( primaryKey );
}
public List getPrimaryKeys() {
return primaryKeys;
}
public void addIndex( IndexDef index ) {
// Don't have the same primary key more than once
for ( IndexDef ind : getIndexes() ) {
if ( ind.getName().equals( index.getName() )) return;
}
// Set this as the table
index.setTable( this );
// Add the primary key
indexes.add( index );
}
public List getIndexes() {
return indexes;
}
protected void addForeignKey( ForeignKeyDef foreignKey ) {
// Don't have the same foreign key more than once
for ( ForeignKeyDef key : getForeignKeys() ) {
if ( key.getName().equals( foreignKey.getName() )) return;
}
// Set this as the table
foreignKey.setTable( this );
// Add the primary key
foreignKeys.add( foreignKey );
}
public List getForeignKeys() {
return foreignKeys;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy