Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins')
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java59
-rw-r--r--jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/EntityGenerator.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/GenTable.java6
5 files changed, 97 insertions, 18 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java
index e631a6da75..b502f61ca6 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/Column.java
@@ -30,15 +30,32 @@ public interface Column
*/
Table getTable();
+
+ // ********** constraints **********
+
/**
* Return whether the column is part of it's table's primary key.
*/
- boolean isPrimaryKeyColumn();
+ boolean isPartOfPrimaryKey();
/**
* Return whether the column is part of one of it's table's foreign keys.
*/
- boolean isForeignKeyColumn();
+ boolean isPartOfForeignKey();
+
+ /**
+ * Return whether the column is part of a unique constraint defined for its
+ * table.
+ */
+ boolean isPartOfUniqueConstraint();
+
+ /**
+ * Return whether the column is nullable.
+ */
+ boolean isNullable();
+
+
+ // ********** data type **********
/**
* Return the name of the column's datatype.
@@ -46,10 +63,33 @@ public interface Column
String getDataTypeName();
/**
+ * Return whether the column's type is numeric.
+ */
+ boolean isNumeric();
+
+ /**
+ * Return the column's precision if it is a NumericalDataType;
+ * otherwise, return -1.
+ */
+ public int getPrecision();
+
+ /**
+ * Return the column's scale if it is an ExactNumericDataType;
+ * otherwise, return -1.
+ */
+ public int getScale();
+
+ /**
+ * If the column is a CharacterStringDataType, return its length;
+ * otherwise, return -1.
+ */
+ public int getLength();
+
+ /**
* Return whether the column's datatype is a LOB type
* (i.e. BLOB, CLOB, or NCLOB).
*/
- boolean dataTypeIsLOB();
+ boolean isLOB();
// ********** Java type **********
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
index 709d8d1736..6caf00bffd 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPColumnWrapper.java
@@ -12,7 +12,10 @@ package org.eclipse.jpt.db.internal;
import java.text.Collator;
import org.eclipse.datatools.modelbase.dbdefinition.PredefinedDataTypeDefinition;
+import org.eclipse.datatools.modelbase.sql.datatypes.CharacterStringDataType;
import org.eclipse.datatools.modelbase.sql.datatypes.DataType;
+import org.eclipse.datatools.modelbase.sql.datatypes.ExactNumericDataType;
+import org.eclipse.datatools.modelbase.sql.datatypes.NumericalDataType;
import org.eclipse.datatools.modelbase.sql.datatypes.PredefinedDataType;
import org.eclipse.datatools.modelbase.sql.datatypes.PrimitiveType;
import org.eclipse.jpt.db.Column;
@@ -58,19 +61,63 @@ final class DTPColumnWrapper
return (DTPTableWrapper) this.getParent();
}
- public boolean isPrimaryKeyColumn() {
+ public boolean isPartOfPrimaryKey() {
return this.getTable().primaryKeyColumnsContains(this);
}
- public boolean isForeignKeyColumn() {
+ public boolean isPartOfForeignKey() {
return this.getTable().foreignKeyBaseColumnsContains(this);
}
+ public boolean isPartOfUniqueConstraint() {
+ return this.dtpColumn.isPartOfUniqueConstraint();
+ }
+
+ public boolean isNullable() {
+ return this.dtpColumn.isNullable();
+ }
+
public String getDataTypeName() {
DataType dataType = this.dtpColumn.getDataType();
return (dataType == null) ? null : dataType.getName();
}
+ public boolean isLOB() {
+ DataType dataType = this.dtpColumn.getDataType();
+ return (dataType instanceof PredefinedDataType) ?
+ primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType())
+ :
+ false;
+ }
+
+ public boolean isNumeric() {
+ return this.dtpColumn.getDataType() instanceof NumericalDataType;
+ }
+
+ public int getPrecision() {
+ DataType dataType = this.dtpColumn.getDataType();
+ return (dataType instanceof NumericalDataType) ?
+ ((NumericalDataType) dataType).getPrecision()
+ :
+ -1;
+ }
+
+ public int getScale(){
+ DataType dataType = this.dtpColumn.getDataType();
+ return (dataType instanceof ExactNumericDataType) ?
+ ((ExactNumericDataType) dataType).getScale()
+ :
+ -1;
+ }
+
+ public int getLength() {
+ DataType dataType = this.dtpColumn.getDataType();
+ return (dataType instanceof CharacterStringDataType) ?
+ ((CharacterStringDataType) dataType).getLength()
+ :
+ -1;
+ }
+
public String getJavaTypeDeclaration() {
return this.getJavaType().declaration();
}
@@ -101,14 +148,6 @@ final class DTPColumnWrapper
return this.getDatabase().getDTPDefinition().getPredefinedDataTypeDefinition(dataType.getName());
}
- public boolean dataTypeIsLOB() {
- DataType dataType = this.dtpColumn.getDataType();
- return (dataType instanceof PredefinedDataType) ?
- primitiveTypeIsLob(((PredefinedDataType) dataType).getPrimitiveType())
- :
- false;
- }
-
// ********** Comparable implementation **********
diff --git a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
index 8317bb926e..6e2e375569 100644
--- a/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.db/src/org/eclipse/jpt/db/internal/DTPForeignKeyWrapper.java
@@ -168,7 +168,7 @@ final class DTPForeignKeyWrapper
return new FilteringIterator<Column, Column>(this.baseColumns()) {
@Override
protected boolean accept(Column column) {
- return ! column.isPrimaryKeyColumn();
+ return ! column.isPartOfPrimaryKey();
}
};
}
diff --git a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/EntityGenerator.java b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/EntityGenerator.java
index c63fdf764b..4e33b493b1 100644
--- a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/EntityGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/EntityGenerator.java
@@ -292,7 +292,7 @@ public class EntityGenerator {
String columnName = this.config.getDatabaseAnnotationNameBuilder().buildColumnAnnotationName(fieldName, column);
this.printColumnAnnotationOn(columnName, pw);
}
- if (column.dataTypeIsLOB()) {
+ if (column.isLOB()) {
pw.printAnnotation(JPA.LOB);
pw.println();
}
diff --git a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/GenTable.java b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/GenTable.java
index bef44e9842..71ba1177b2 100644
--- a/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/GenTable.java
+++ b/jpa/plugins/org.eclipse.jpt.gen/src/org/eclipse/jpt/gen/internal/GenTable.java
@@ -173,7 +173,7 @@ class GenTable {
return new FilteringIterator<Column, Column>(this.table.primaryKeyColumns()) {
@Override
protected boolean accept(Column pkColumn) {
- return pkColumn.isForeignKeyColumn();
+ return pkColumn.isPartOfForeignKey();
}
};
}
@@ -186,7 +186,7 @@ class GenTable {
return new FilteringIterator<Column, Column>(this.table.primaryKeyColumns()) {
@Override
protected boolean accept(Column pkColumn) {
- return ! pkColumn.isForeignKeyColumn();
+ return ! pkColumn.isPartOfForeignKey();
}
};
}
@@ -199,7 +199,7 @@ class GenTable {
return new FilteringIterator<Column, Column>(this.table.columns()) {
@Override
protected boolean accept(Column column) {
- return ! (column.isPrimaryKeyColumn() || column.isForeignKeyColumn());
+ return ! (column.isPartOfPrimaryKey() || column.isPartOfForeignKey());
}
};
}

Back to the top