mirror of https://github.com/apache/openjpa.git
Expand Column.isCompatible method parameters to also take type name and
decimal digits so that DynamicSchemaFactory can set this information when building up its internal schema representation. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@497866 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6b78680b27
commit
fd0e25dae6
|
@ -608,7 +608,8 @@ public abstract class MappingInfo
|
||||||
// the expected column type
|
// the expected column type
|
||||||
if (given.getType() != Types.OTHER) {
|
if (given.getType() != Types.OTHER) {
|
||||||
ttype = false;
|
ttype = false;
|
||||||
if (compat && !given.isCompatible(type, size)) {
|
if (compat && !given.isCompatible(type, typeName, size,
|
||||||
|
decimals)) {
|
||||||
Log log = repos.getLog();
|
Log log = repos.getLog();
|
||||||
if (log.isWarnEnabled())
|
if (log.isWarnEnabled())
|
||||||
log.warn(_loc.get(prefix + "-incompat-col",
|
log.warn(_loc.get(prefix + "-incompat-col",
|
||||||
|
@ -643,7 +644,8 @@ public abstract class MappingInfo
|
||||||
if (col == null) {
|
if (col == null) {
|
||||||
col = table.addColumn(colName);
|
col = table.addColumn(colName);
|
||||||
col.setType(type);
|
col.setType(type);
|
||||||
} else if ((compat || !ttype) && !col.isCompatible(type, size)) {
|
} else if ((compat || !ttype) && !col.isCompatible(type, typeName,
|
||||||
|
size, decimals)) {
|
||||||
// if existing column isn't compatible with desired type, die if
|
// if existing column isn't compatible with desired type, die if
|
||||||
// can't adapt, else warn and change the existing column type
|
// can't adapt, else warn and change the existing column type
|
||||||
Message msg = _loc.get(prefix + "-bad-col", context,
|
Message msg = _loc.get(prefix + "-bad-col", context,
|
||||||
|
|
|
@ -1085,7 +1085,7 @@ public class ReverseMappingTool
|
||||||
Column[] pks = table.getPrimaryKey().getColumns();
|
Column[] pks = table.getPrimaryKey().getColumns();
|
||||||
cls.setPrimaryKeyColumns(pks);
|
cls.setPrimaryKeyColumns(pks);
|
||||||
if (pks.length == 1 && _datastore
|
if (pks.length == 1 && _datastore
|
||||||
&& pks[0].isCompatible(Types.BIGINT, 0)) {
|
&& pks[0].isCompatible(Types.BIGINT, null, 0, 0)) {
|
||||||
cls.setObjectIdType(null, false);
|
cls.setObjectIdType(null, false);
|
||||||
cls.setIdentityType(ClassMapping.ID_DATASTORE);
|
cls.setIdentityType(ClassMapping.ID_DATASTORE);
|
||||||
} else if (pks.length == 1 && _builtin)
|
} else if (pks.length == 1 && _builtin)
|
||||||
|
|
|
@ -548,7 +548,8 @@ public class Column
|
||||||
* Return true if this column is compatible with the given JDBC type
|
* Return true if this column is compatible with the given JDBC type
|
||||||
* from {@link Types} and size.
|
* from {@link Types} and size.
|
||||||
*/
|
*/
|
||||||
public boolean isCompatible(int type, int size) {
|
public boolean isCompatible(int type, String typeName, int size,
|
||||||
|
int decimals) {
|
||||||
if (type == Types.OTHER || getType() == Types.OTHER)
|
if (type == Types.OTHER || getType() == Types.OTHER)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -662,7 +663,8 @@ public class Column
|
||||||
|
|
||||||
if (!getFullName().equalsIgnoreCase(col.getFullName()))
|
if (!getFullName().equalsIgnoreCase(col.getFullName()))
|
||||||
return false;
|
return false;
|
||||||
if (!isCompatible(col.getType(), col.getSize()))
|
if (!isCompatible(col.getType(), col.getTypeName(), col.getSize(),
|
||||||
|
col.getDecimalDigits()))
|
||||||
return false;
|
return false;
|
||||||
if (getType() == Types.VARCHAR && getSize() > 0 && col.getSize() > 0
|
if (getType() == Types.VARCHAR && getSize() > 0 && col.getSize() > 0
|
||||||
&& getSize() != col.getSize())
|
&& getSize() != col.getSize())
|
||||||
|
|
|
@ -129,14 +129,19 @@ public class DynamicSchemaFactory
|
||||||
super(name, table);
|
super(name, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(int type, int size) {
|
public boolean isCompatible(int type, String typeName, int size,
|
||||||
|
int decimals) {
|
||||||
if (getType() != Types.OTHER)
|
if (getType() != Types.OTHER)
|
||||||
return super.isCompatible(type, size);
|
return super.isCompatible(type, typeName, size, decimals);
|
||||||
|
|
||||||
if (type == Types.VARCHAR && size <= 0)
|
if (type == Types.VARCHAR && size <= 0)
|
||||||
size = _dict.characterColumnSize;
|
size = _dict.characterColumnSize;
|
||||||
setType(type);
|
setType(type);
|
||||||
setSize(size);
|
setSize(size);
|
||||||
|
if (typeName != null)
|
||||||
|
setTypeName(typeName);
|
||||||
|
if (decimals >= 0)
|
||||||
|
setDecimalDigits(decimals);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -751,7 +751,7 @@ public class DBDictionary
|
||||||
public void setBigDecimal(PreparedStatement stmnt, int idx, BigDecimal val,
|
public void setBigDecimal(PreparedStatement stmnt, int idx, BigDecimal val,
|
||||||
Column col)
|
Column col)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
if ((col != null && col.isCompatible(Types.VARCHAR, 0))
|
if ((col != null && col.isCompatible(Types.VARCHAR, null, 0, 0))
|
||||||
|| (col == null && storeLargeNumbersAsStrings))
|
|| (col == null && storeLargeNumbersAsStrings))
|
||||||
setString(stmnt, idx, val.toString(), col);
|
setString(stmnt, idx, val.toString(), col);
|
||||||
else
|
else
|
||||||
|
@ -764,7 +764,7 @@ public class DBDictionary
|
||||||
public void setBigInteger(PreparedStatement stmnt, int idx, BigInteger val,
|
public void setBigInteger(PreparedStatement stmnt, int idx, BigInteger val,
|
||||||
Column col)
|
Column col)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
if ((col != null && col.isCompatible(Types.VARCHAR, 0))
|
if ((col != null && col.isCompatible(Types.VARCHAR, null, 0, 0))
|
||||||
|| (col == null && storeLargeNumbersAsStrings))
|
|| (col == null && storeLargeNumbersAsStrings))
|
||||||
setString(stmnt, idx, val.toString(), col);
|
setString(stmnt, idx, val.toString(), col);
|
||||||
else
|
else
|
||||||
|
@ -833,7 +833,7 @@ public class DBDictionary
|
||||||
*/
|
*/
|
||||||
public void setChar(PreparedStatement stmnt, int idx, char val, Column col)
|
public void setChar(PreparedStatement stmnt, int idx, char val, Column col)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
if ((col != null && col.isCompatible(Types.INTEGER, 0))
|
if ((col != null && col.isCompatible(Types.INTEGER, null, 0, 0))
|
||||||
|| (col == null && storeCharsAsNumbers))
|
|| (col == null && storeCharsAsNumbers))
|
||||||
setInt(stmnt, idx, (int) val, col);
|
setInt(stmnt, idx, (int) val, col);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue