// Generated by Together
package oisoft.togetherx.scripts.SQL.impl;
import java.util.Enumeration;
import java.sql.Types;
import oisoft.togetherx.scriptapi.UML.UMLAttribute;
import oisoft.togetherx.scripts.SQL.SQLTable;
import oisoft.togetherx.scripts.SQL.SQLColumn;
class ColumnImpl implements SQLColumn {
private TableImpl myTable;
private UMLAttribute myAttribute;
private String myName = null;
private boolean myNullable;
private boolean myForcePrimaryKey;
private boolean myForeignKey;
public SQLTable getTable(){
return myTable;
}
public String getName(){
if( myName == null ){
myName = myTable.createColumnName(this);
}
return myName;
}
/**
@todo Implement it!
*/
public short getType(){
return 0;
}
/**
@todo Create real implementation using getType and type-mapping settings
*/
public String getTypeName(){
return myAttribute.getProperty(tagNameSQLType());
}
public int getSize(){
String tagValue = myAttribute.getProperty(tagNameSQLSize());
if(tagValue != null){
try{
return Integer.parseInt(tagValue);
}
catch(NumberFormatException err){
err.printStackTrace();
}
}
// Size not set by some reason.
return 0;
}
public boolean isNullAllowed(){
return myNullable;
}
public int getDecimalDigits(){
String tagValue = myAttribute.getProperty(tagNameSQLDigits());
if(tagValue != null){
try{
return Integer.parseInt(tagValue);
}
catch(NumberFormatException err){
err.printStackTrace();
}
}
// Size not set by some reason.
return 0;
}
public String getRemarks(){
return "";
}
/**
@todo Implement it!
*/
public Enumeration getConstraints(){
return new EmptyEnumeration();
}
ColumnImpl(UMLAttribute attribute, boolean nullable, boolean forcePrimaryKey, TableImpl table){
this( attribute, nullable, forcePrimaryKey, table,
!attribute.getContainingClass().equals(table.getUMLClass())
);
}
ColumnImpl(UMLAttribute attribute, boolean nullable, boolean forcePrimaryKey, TableImpl table, boolean foreignKey){
myAttribute = attribute;
myNullable = nullable;
myForcePrimaryKey = forcePrimaryKey;
myTable = table;
myForeignKey = foreignKey;
}
UMLAttribute getAttribute(){
return myAttribute;
}
boolean isForeignKey(){
//return !myAttribute.getContainingClass().equals(myTable.getUMLClass());
return myForeignKey;
}
boolean isPrimaryKey(){
return myForcePrimaryKey
|| (!isForeignKey() && getAttribute().hasProperty(getTags().attributePrimaryKey()));
}
SQLDiagramTags getTags(){
return myTable.getTags();
}
private String tagNameSQLType(){
return getTags().attributeSQLType();
}
private String tagNameSQLSize(){
return getTags().attributeLength();
}
private String tagNameSQLDigits(){
return getTags().attributePrecision();
}
}
|