Implemented the ColumnTyper interface for our various builders.
This commit is contained in:
@@ -246,62 +246,51 @@ public class HSQLBuilder
|
||||
@Override
|
||||
protected <T> String getColumnType (FieldMarshaller<?> fm, int length)
|
||||
{
|
||||
if (fm instanceof FieldMarshaller.ByteMarshaller) {
|
||||
return "TINYINT";
|
||||
} else if (fm instanceof FieldMarshaller.ShortMarshaller) {
|
||||
return "SMALLINT";
|
||||
} else if (fm instanceof FieldMarshaller.IntMarshaller) {
|
||||
return "INTEGER";
|
||||
} else if (fm instanceof FieldMarshaller.LongMarshaller) {
|
||||
return "BIGINT";
|
||||
} else if (fm instanceof FieldMarshaller.FloatMarshaller) {
|
||||
return "REAL";
|
||||
} else if (fm instanceof FieldMarshaller.DoubleMarshaller) {
|
||||
return "DOUBLE PRECISION";
|
||||
} else if (fm instanceof FieldMarshaller.ObjectMarshaller) {
|
||||
Class<?> ftype = fm.getField().getType();
|
||||
if (ftype.equals(Byte.class)) {
|
||||
return "TINYINT";
|
||||
} else if (ftype.equals(Short.class)) {
|
||||
return "SMALLINT";
|
||||
} else if (ftype.equals(Integer.class)) {
|
||||
return "INTEGER";
|
||||
} else if (ftype.equals(Long.class)) {
|
||||
return "BIGINT";
|
||||
} else if (ftype.equals(Float.class)) {
|
||||
return "FLOAT";
|
||||
} else if (ftype.equals(Double.class)) {
|
||||
return "DOUBLE PRECISION";
|
||||
} else if (ftype.equals(String.class)) {
|
||||
return "VARCHAR(" + length + ")";
|
||||
} else if (ftype.equals(Date.class)) {
|
||||
return "DATE";
|
||||
} else if (ftype.equals(Time.class)) {
|
||||
return "TIME";
|
||||
} else if (ftype.equals(Timestamp.class)) {
|
||||
return "TIMESTAMP";
|
||||
} else if (ftype.equals(Blob.class)) {
|
||||
return "VARBINARY";
|
||||
} else if (ftype.equals(Clob.class)) {
|
||||
return "VARCHAR";
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Don't know how to create SQL for " + ftype + ".");
|
||||
}
|
||||
} else if (fm instanceof FieldMarshaller.ByteArrayMarshaller) {
|
||||
return "VARBINARY";
|
||||
} else if (fm instanceof FieldMarshaller.IntArrayMarshaller) {
|
||||
return "VARBINARY";
|
||||
} else if (fm instanceof FieldMarshaller.ByteEnumMarshaller<?>) {
|
||||
return "TINYINT";
|
||||
} else if (fm instanceof FieldMarshaller.BooleanMarshaller) {
|
||||
return "BOOLEAN";
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown field marshaller type: " + fm.getClass());
|
||||
}
|
||||
return fm.getColumnType(TYPER, length);
|
||||
}
|
||||
|
||||
/** Holds the Full Text Seach condition between build and bind phases. */
|
||||
protected SQLExpression _ftsCondition;
|
||||
}
|
||||
|
||||
protected static final FieldMarshaller.ColumnTyper TYPER = new FieldMarshaller.ColumnTyper() {
|
||||
public String getBooleanType (int length) {
|
||||
return "BOOLEAN";
|
||||
}
|
||||
public String getByteType (int length) {
|
||||
return "TINYINT";
|
||||
}
|
||||
public String getShortType (int length) {
|
||||
return "SMALLINT";
|
||||
}
|
||||
public String getIntType (int length) {
|
||||
return "INTEGER";
|
||||
}
|
||||
public String getLongType (int length) {
|
||||
return "BIGINT";
|
||||
}
|
||||
public String getFloatType (int length) {
|
||||
return "REAL";
|
||||
}
|
||||
public String getDoubleType (int length) {
|
||||
return "DOUBLE PRECISION";
|
||||
}
|
||||
public String getStringType (int length) {
|
||||
return "VARCHAR(" + length + ")";
|
||||
}
|
||||
public String getDateType (int length) {
|
||||
return "DATE";
|
||||
}
|
||||
public String getTimeType (int length) {
|
||||
return "TIME";
|
||||
}
|
||||
public String getTimestampType (int length) {
|
||||
return "TIMESTAMP";
|
||||
}
|
||||
public String getBlobType (int length) {
|
||||
return "VARBINARY";
|
||||
}
|
||||
public String getClobType (int length) {
|
||||
return "VARCHAR";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -268,56 +268,44 @@ public class MySQLBuilder
|
||||
@Override
|
||||
protected <T> String getColumnType (FieldMarshaller<?> fm, int length)
|
||||
{
|
||||
if (fm instanceof ByteMarshaller) {
|
||||
return fm.getColumnType(TYPER, length);
|
||||
}
|
||||
|
||||
protected static final FieldMarshaller.ColumnTyper TYPER = new FieldMarshaller.ColumnTyper() {
|
||||
public String getBooleanType (int length) {
|
||||
return "TINYINT";
|
||||
} else if (fm instanceof ShortMarshaller) {
|
||||
}
|
||||
public String getByteType (int length) {
|
||||
return "TINYINT";
|
||||
}
|
||||
public String getShortType (int length) {
|
||||
return "SMALLINT";
|
||||
} else if (fm instanceof IntMarshaller) {
|
||||
}
|
||||
public String getIntType (int length) {
|
||||
return "INTEGER";
|
||||
} else if (fm instanceof LongMarshaller) {
|
||||
}
|
||||
public String getLongType (int length) {
|
||||
return "BIGINT";
|
||||
} else if (fm instanceof FloatMarshaller) {
|
||||
}
|
||||
public String getFloatType (int length) {
|
||||
return "FLOAT";
|
||||
} else if (fm instanceof DoubleMarshaller) {
|
||||
}
|
||||
public String getDoubleType (int length) {
|
||||
return "DOUBLE";
|
||||
} else if (fm instanceof ObjectMarshaller) {
|
||||
Class<?> ftype = fm.getField().getType();
|
||||
if (ftype.equals(Byte.class)) {
|
||||
return "SMALLINT";
|
||||
} else if (ftype.equals(Short.class)) {
|
||||
return "SMALLINT";
|
||||
} else if (ftype.equals(Integer.class)) {
|
||||
return "INTEGER";
|
||||
} else if (ftype.equals(Long.class)) {
|
||||
return "BIGINT";
|
||||
} else if (ftype.equals(Float.class)) {
|
||||
return "FLOAT";
|
||||
} else if (ftype.equals(Double.class)) {
|
||||
return "DOUBLE";
|
||||
} else if (ftype.equals(String.class)) {
|
||||
if (length < (1 << 15)) {
|
||||
return "VARCHAR(" + length + ")";
|
||||
}
|
||||
return "TEXT";
|
||||
} else if (ftype.equals(Date.class)) {
|
||||
return "DATE";
|
||||
} else if (ftype.equals(Time.class)) {
|
||||
return "DATETIME";
|
||||
} else if (ftype.equals(Timestamp.class)) {
|
||||
return "DATETIME";
|
||||
} else if (ftype.equals(Blob.class)) {
|
||||
return "BYTEA";
|
||||
} else if (ftype.equals(Clob.class)) {
|
||||
return "TEXT";
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Don't know how to create SQL for " + ftype + ".");
|
||||
}
|
||||
} else if (fm instanceof ByteArrayMarshaller ||
|
||||
fm instanceof IntArrayMarshaller) {
|
||||
if (fm instanceof IntArrayMarshaller) {
|
||||
length *= 4;
|
||||
}
|
||||
}
|
||||
public String getStringType (int length) {
|
||||
return (length < (1 << 15)) ? "VARCHAR(" + length + ")" : "TEXT";
|
||||
}
|
||||
public String getDateType (int length) {
|
||||
return "DATE";
|
||||
}
|
||||
public String getTimeType (int length) {
|
||||
return "DATETIME";
|
||||
}
|
||||
public String getTimestampType (int length) {
|
||||
return "DATETIME";
|
||||
}
|
||||
public String getBlobType (int length) {
|
||||
// semi-arbitrarily use VARBINARY() up to 32767
|
||||
if (length < (1 << 15)) {
|
||||
return "VARBINARY(" + length + ")";
|
||||
@@ -330,12 +318,9 @@ public class MySQLBuilder
|
||||
return "MEDIUMBLOB";
|
||||
}
|
||||
return "LONGBLOB";
|
||||
} else if (fm instanceof ByteEnumMarshaller<?>) {
|
||||
return "TINYINT";
|
||||
} else if (fm instanceof BooleanMarshaller) {
|
||||
return "TINYINT";
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown field marshaller type: " + fm.getClass());
|
||||
}
|
||||
}
|
||||
public String getClobType (int length) {
|
||||
return "TEXT";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -263,62 +263,7 @@ public class PostgreSQLBuilder
|
||||
@Override
|
||||
protected <T> String getColumnType (FieldMarshaller<?> fm, int length)
|
||||
{
|
||||
if (fm instanceof FieldMarshaller.ByteMarshaller) {
|
||||
return "SMALLINT";
|
||||
} else if (fm instanceof FieldMarshaller.ShortMarshaller) {
|
||||
return "SMALLINT";
|
||||
} else if (fm instanceof FieldMarshaller.IntMarshaller) {
|
||||
return "INTEGER";
|
||||
} else if (fm instanceof FieldMarshaller.LongMarshaller) {
|
||||
return "BIGINT";
|
||||
} else if (fm instanceof FieldMarshaller.FloatMarshaller) {
|
||||
return "REAL";
|
||||
} else if (fm instanceof FieldMarshaller.DoubleMarshaller) {
|
||||
return "DOUBLE PRECISION";
|
||||
} else if (fm instanceof FieldMarshaller.ObjectMarshaller) {
|
||||
Class<?> ftype = fm.getField().getType();
|
||||
if (ftype.equals(Byte.class)) {
|
||||
return "SMALLINT";
|
||||
} else if (ftype.equals(Short.class)) {
|
||||
return "SMALLINT";
|
||||
} else if (ftype.equals(Integer.class)) {
|
||||
return "INTEGER";
|
||||
} else if (ftype.equals(Long.class)) {
|
||||
return "BIGINT";
|
||||
} else if (ftype.equals(Float.class)) {
|
||||
return "FLOAT";
|
||||
} else if (ftype.equals(Double.class)) {
|
||||
return "DOUBLE";
|
||||
} else if (ftype.equals(String.class)) {
|
||||
if (length < (1 << 15)) {
|
||||
return "VARCHAR(" + length + ")";
|
||||
}
|
||||
return "TEXT";
|
||||
} else if (ftype.equals(Date.class)) {
|
||||
return "DATE";
|
||||
} else if (ftype.equals(Time.class)) {
|
||||
return "TIME";
|
||||
} else if (ftype.equals(Timestamp.class)) {
|
||||
return "TIMESTAMP";
|
||||
} else if (ftype.equals(Blob.class)) {
|
||||
return "BYTEA";
|
||||
} else if (ftype.equals(Clob.class)) {
|
||||
return "TEXT";
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Don't know how to create SQL for " + ftype + ".");
|
||||
}
|
||||
} else if (fm instanceof FieldMarshaller.ByteArrayMarshaller) {
|
||||
return "BYTEA";
|
||||
} else if (fm instanceof FieldMarshaller.IntArrayMarshaller) {
|
||||
return "BYTEA";
|
||||
} else if (fm instanceof FieldMarshaller.ByteEnumMarshaller<?>) {
|
||||
return "SMALLINT";
|
||||
} else if (fm instanceof FieldMarshaller.BooleanMarshaller) {
|
||||
return "BOOLEAN";
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown field marshaller type: " + fm.getClass());
|
||||
}
|
||||
return fm.getColumnType(TYPER, length);
|
||||
}
|
||||
|
||||
protected static String massageFTQuery (FullText match)
|
||||
@@ -354,4 +299,52 @@ public class PostgreSQLBuilder
|
||||
"Unknown full text configuration: " + configuration);
|
||||
}
|
||||
}
|
||||
|
||||
protected static final FieldMarshaller.ColumnTyper TYPER = new FieldMarshaller.ColumnTyper() {
|
||||
public String getBooleanType (int length) {
|
||||
return "BOOLEAN";
|
||||
}
|
||||
public String getByteType (int length) {
|
||||
return "SMALLINT";
|
||||
}
|
||||
public String getShortType (int length) {
|
||||
return "SMALLINT";
|
||||
}
|
||||
public String getIntType (int length) {
|
||||
return "INTEGER";
|
||||
}
|
||||
public String getLongType (int length) {
|
||||
return "BIGINT";
|
||||
}
|
||||
public String getFloatType (int length) {
|
||||
return "REAL";
|
||||
}
|
||||
public String getDoubleType (int length) {
|
||||
return "DOUBLE PRECISION";
|
||||
}
|
||||
public String getByteArrayType (int length) {
|
||||
return "BYTEA";
|
||||
}
|
||||
public String getIntArrayType (int length) {
|
||||
return "BYTEA";
|
||||
}
|
||||
public String getStringType (int length) {
|
||||
return "VARCHAR(" + length + ")";
|
||||
}
|
||||
public String getDateType (int length) {
|
||||
return "DATE";
|
||||
}
|
||||
public String getTimeType (int length) {
|
||||
return "TIME";
|
||||
}
|
||||
public String getTimestampType (int length) {
|
||||
return "TIMESTAMP";
|
||||
}
|
||||
public String getBlobType (int length) {
|
||||
return "BYTEA";
|
||||
}
|
||||
public String getClobType (int length) {
|
||||
return "TEXT";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user