From Zell: select text and binary column types based on the @Column(length)
annotation.
This commit is contained in:
@@ -173,7 +173,7 @@ public class MySQLBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> String getColumnType (FieldMarshaller fm)
|
protected <T> String getColumnType (FieldMarshaller fm, int length)
|
||||||
{
|
{
|
||||||
if (fm instanceof ByteMarshaller) {
|
if (fm instanceof ByteMarshaller) {
|
||||||
return "TINYINT";
|
return "TINYINT";
|
||||||
@@ -202,7 +202,10 @@ public class MySQLBuilder
|
|||||||
} else if (ftype.equals(Double.class)) {
|
} else if (ftype.equals(Double.class)) {
|
||||||
return "DOUBLE";
|
return "DOUBLE";
|
||||||
} else if (ftype.equals(String.class)) {
|
} else if (ftype.equals(String.class)) {
|
||||||
return "VARCHAR";
|
if (length < (1 << 15)) {
|
||||||
|
return "VARCHAR(" + length + ")";
|
||||||
|
}
|
||||||
|
return "TEXT";
|
||||||
} else if (ftype.equals(Date.class)) {
|
} else if (ftype.equals(Date.class)) {
|
||||||
return "DATE";
|
return "DATE";
|
||||||
} else if (ftype.equals(Time.class)) {
|
} else if (ftype.equals(Time.class)) {
|
||||||
@@ -218,7 +221,19 @@ public class MySQLBuilder
|
|||||||
"Don't know how to create SQL for " + ftype + ".");
|
"Don't know how to create SQL for " + ftype + ".");
|
||||||
}
|
}
|
||||||
} else if (fm instanceof ByteArrayMarshaller) {
|
} else if (fm instanceof ByteArrayMarshaller) {
|
||||||
return "VARBINARY";
|
// semi-arbitrarily use VARBINARY() up to 32767
|
||||||
|
if (length < (1 << 15)) {
|
||||||
|
return "VARBINARY(" + length + ")";
|
||||||
|
}
|
||||||
|
// use BLOB to 65535
|
||||||
|
if (length < (1 << 16)) {
|
||||||
|
return "BLOB";
|
||||||
|
}
|
||||||
|
if (length < (1 << 24)) {
|
||||||
|
return "MEDIUMBLOB";
|
||||||
|
}
|
||||||
|
return "LONGBLOB";
|
||||||
|
|
||||||
} else if (fm instanceof IntArrayMarshaller) {
|
} else if (fm instanceof IntArrayMarshaller) {
|
||||||
return "BLOB";
|
return "BLOB";
|
||||||
} else if (fm instanceof ByteEnumMarshaller) {
|
} else if (fm instanceof ByteEnumMarshaller) {
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class PostgreSQLBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> String getColumnType (FieldMarshaller fm)
|
protected <T> String getColumnType (FieldMarshaller fm, int length)
|
||||||
{
|
{
|
||||||
if (fm instanceof ByteMarshaller) {
|
if (fm instanceof ByteMarshaller) {
|
||||||
return "SMALLINT";
|
return "SMALLINT";
|
||||||
@@ -215,7 +215,10 @@ public class PostgreSQLBuilder
|
|||||||
} else if (ftype.equals(Double.class)) {
|
} else if (ftype.equals(Double.class)) {
|
||||||
return "DOUBLE";
|
return "DOUBLE";
|
||||||
} else if (ftype.equals(String.class)) {
|
} else if (ftype.equals(String.class)) {
|
||||||
return "VARCHAR";
|
if (length < (1 << 15)) {
|
||||||
|
return "VARCHAR(" + length + ")";
|
||||||
|
}
|
||||||
|
return "TEXT";
|
||||||
} else if (ftype.equals(Date.class)) {
|
} else if (ftype.equals(Date.class)) {
|
||||||
return "DATE";
|
return "DATE";
|
||||||
} else if (ftype.equals(Time.class)) {
|
} else if (ftype.equals(Time.class)) {
|
||||||
|
|||||||
@@ -145,15 +145,10 @@ public abstract class SQLBuilder
|
|||||||
|
|
||||||
if (!typeDone) {
|
if (!typeDone) {
|
||||||
if (type.length() == 0) {
|
if (type.length() == 0) {
|
||||||
type = getColumnType(fm);
|
type = getColumnType(fm, length);
|
||||||
}
|
}
|
||||||
builder.append(" ").append(type);
|
builder.append(" ").append(type);
|
||||||
|
|
||||||
// if this is a VARCHAR field, add the length
|
|
||||||
if (type.equals("VARCHAR") || type.equals("VARBINARY")) {
|
|
||||||
builder.append("(").append(length).append(")");
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: handle precision and scale
|
// TODO: handle precision and scale
|
||||||
|
|
||||||
// handle nullability and uniqueness
|
// handle nullability and uniqueness
|
||||||
@@ -196,8 +191,9 @@ public abstract class SQLBuilder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overridden by subclasses to figure the dialect-specific SQL type of the given field.
|
* Overridden by subclasses to figure the dialect-specific SQL type of the given field.
|
||||||
|
* @param length
|
||||||
*/
|
*/
|
||||||
protected abstract <T> String getColumnType (FieldMarshaller fm);
|
protected abstract <T> String getColumnType (FieldMarshaller fm, int length);
|
||||||
|
|
||||||
/** The class that maps persistent classes to marshallers. */
|
/** The class that maps persistent classes to marshallers. */
|
||||||
protected DepotTypes _types;
|
protected DepotTypes _types;
|
||||||
|
|||||||
Reference in New Issue
Block a user