mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#696 - ENH: Add fallback for @DbHstore ... fallback to JSON storage in VARCHAR
This commit is contained in:
1 parent
b197d8a637
commit
17042a9faf
7 files changed
+178
-10
No files matched your search
@@ -175,8 +175,9 @@ public class AnnotationFields extends AnnotationParser {
|
||||
if (comment != null) {
|
||||
prop.setDbComment(comment.value());
|
||||
}
|
||||
if (get(prop, DbHstore.class) != null) {
|
||||
util.setDbHstore(prop);
|
||||
DbHstore dbHstore = get(prop, DbHstore.class);
|
||||
if (dbHstore != null) {
|
||||
util.setDbHstore(prop, dbHstore);
|
||||
}
|
||||
DbJson dbJson = get(prop, DbJson.class);
|
||||
if (dbJson != null) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.persistence.Enumerated;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.annotation.DbArray;
|
||||
import com.avaje.ebean.annotation.DbHstore;
|
||||
import com.avaje.ebean.annotation.DbJson;
|
||||
import com.avaje.ebean.annotation.DbJsonB;
|
||||
import com.avaje.ebean.annotation.DbJsonType;
|
||||
@@ -203,15 +204,20 @@ public class DeployUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map to Postgres HSTORE type.
|
||||
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
||||
*/
|
||||
public void setDbHstore(DeployBeanProperty prop) {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(DbType.HSTORE);
|
||||
if (scalarType == null) {
|
||||
throw new RuntimeException("No ScalarType found for HSTORE on [" + prop.getFullBeanName() + "] ?");
|
||||
}
|
||||
prop.setDbType(DbType.HSTORE);
|
||||
public void setDbHstore(DeployBeanProperty prop, DbHstore dbHstore) {
|
||||
|
||||
ScalarType<?> scalarType = typeManager.getHstoreScalarType();
|
||||
int dbType = scalarType.getJdbcType();
|
||||
prop.setDbType(dbType);
|
||||
prop.setScalarType(scalarType);
|
||||
if (dbType == Types.VARCHAR) {
|
||||
// this is actually the fallback of JSON storage into VARCHAR
|
||||
int dbLength = dbHstore.length();
|
||||
int columnLength = (dbLength > 0) ? dbLength : DEFAULT_JSON_VARCHAR_LENGTH;
|
||||
prop.setDbLength(columnLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user