mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1747 - Refactor tidy on DeployUtil and AnnotationAssocMany
This commit is contained in:
1 parent
52398317bc
commit
d3b3a79342
2 files changed
+41
-76
No files matched your search
@@ -10,7 +10,6 @@ import io.ebean.config.BeanNotRegisteredException;
|
||||
import io.ebean.config.NamingConvention;
|
||||
import io.ebean.config.TableName;
|
||||
import io.ebean.util.CamelCaseHelper;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanTable;
|
||||
@@ -41,6 +40,8 @@ import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebean.util.StringHelper.isNull;
|
||||
|
||||
/**
|
||||
* Read the deployment annotation for Assoc Many beans.
|
||||
*/
|
||||
@@ -164,7 +165,6 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!prop.getTableJoin().hasJoinColumns() && beanTable != null) {
|
||||
|
||||
// use naming convention to define join (based on the bean name for this side of relationship)
|
||||
@@ -340,14 +340,18 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
* Return the full table name
|
||||
*/
|
||||
private String getFullTableName(JoinTable joinTable) {
|
||||
return append(joinTable.catalog(), joinTable.schema(), joinTable.name());
|
||||
}
|
||||
|
||||
private String append(String catalog, String schema, String name) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!StringHelper.isNull(joinTable.catalog())) {
|
||||
sb.append(joinTable.catalog()).append(".");
|
||||
if (!isNull(catalog)) {
|
||||
sb.append(catalog).append(".");
|
||||
}
|
||||
if (!StringHelper.isNull(joinTable.schema())) {
|
||||
sb.append(joinTable.schema()).append(".");
|
||||
if (!isNull(schema)) {
|
||||
sb.append(schema).append(".");
|
||||
}
|
||||
sb.append(joinTable.name());
|
||||
sb.append(name);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -358,15 +362,7 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
if (collectionTable == null || collectionTable.name().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!StringHelper.isNull(collectionTable.catalog())) {
|
||||
sb.append(collectionTable.catalog()).append(".");
|
||||
}
|
||||
if (!StringHelper.isNull(collectionTable.schema())) {
|
||||
sb.append(collectionTable.schema()).append(".");
|
||||
}
|
||||
sb.append(collectionTable.name());
|
||||
return sb.toString();
|
||||
return append(collectionTable.catalog(), collectionTable.schema(), collectionTable.name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,26 +440,11 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
|
||||
Class<?> targetType = propAnn.targetEntity();
|
||||
if (targetType.equals(void.class)) {
|
||||
// via reflection of generics type
|
||||
targetType = manyProp.getTargetType();
|
||||
} else {
|
||||
manyProp.setTargetType(targetType);
|
||||
}
|
||||
|
||||
// find the other many table (not intersection)
|
||||
BeanTable assoc = factory.getBeanTable(targetType);
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()));
|
||||
}
|
||||
|
||||
setTargetType(propAnn.targetEntity(), manyProp);
|
||||
setBeanTable(manyProp);
|
||||
manyProp.setManyToMany();
|
||||
manyProp.setModifyListenMode(ModifyListenMode.ALL);
|
||||
manyProp.setBeanTable(assoc);
|
||||
manyProp.getTableJoin().setType(SqlJoinType.OUTER);
|
||||
}
|
||||
|
||||
@@ -471,34 +452,31 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
|
||||
Class<?> targetType = propAnn.targetEntity();
|
||||
if (targetType.equals(void.class)) {
|
||||
// via reflection of generics type
|
||||
targetType = manyProp.getTargetType();
|
||||
} else {
|
||||
manyProp.setTargetType(targetType);
|
||||
}
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(targetType);
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()));
|
||||
}
|
||||
|
||||
manyProp.setBeanTable(assoc);
|
||||
setTargetType(propAnn.targetEntity(), manyProp);
|
||||
setBeanTable(manyProp);
|
||||
manyProp.getTableJoin().setType(SqlJoinType.OUTER);
|
||||
}
|
||||
|
||||
private void setTargetType(Class<?> targetType, DeployBeanPropertyAssocMany<?> prop) {
|
||||
if (!targetType.equals(void.class)) {
|
||||
prop.setTargetType(targetType);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBeanTable(DeployBeanPropertyAssocMany<?> manyProp) {
|
||||
BeanTable assoc = factory.getBeanTable(manyProp.getTargetType());
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(manyProp.getTargetType(), manyProp.getFullBeanName()));
|
||||
}
|
||||
manyProp.setBeanTable(assoc);
|
||||
}
|
||||
|
||||
private String getM2MJoinTableName(BeanTable lhsTable, BeanTable rhsTable) {
|
||||
|
||||
TableName lhs = new TableName(lhsTable.getBaseTable());
|
||||
TableName rhs = new TableName(rhsTable.getBaseTable());
|
||||
|
||||
TableName joinTable = namingConvention.getM2MJoinTableName(lhs, rhs);
|
||||
|
||||
return joinTable.getQualifiedName();
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import io.ebeaninternal.server.type.ScalarTypeArray;
|
||||
import io.ebeaninternal.server.type.ScalarTypeWrapper;
|
||||
import io.ebeaninternal.server.type.SimpleAesEncryptor;
|
||||
import io.ebeaninternal.server.type.TypeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
@@ -34,8 +32,6 @@ import java.sql.Types;
|
||||
*/
|
||||
public class DeployUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeployUtil.class);
|
||||
|
||||
/**
|
||||
* Assumes CLOB rather than LONGVARCHAR.
|
||||
*/
|
||||
@@ -91,26 +87,26 @@ public class DeployUtil {
|
||||
/**
|
||||
* Check that the EncryptKeyManager has been defined.
|
||||
*/
|
||||
public void checkEncryptKeyManagerDefined(String fullPropName) {
|
||||
void checkEncryptKeyManagerDefined(String fullPropName) {
|
||||
if (encryptKeyManager == null) {
|
||||
String msg = "Using encryption on " + fullPropName + " but no EncryptKeyManager defined!";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public EncryptDeploy getEncryptDeploy(TableName table, String column) {
|
||||
EncryptDeploy getEncryptDeploy(TableName table, String column) {
|
||||
if (encryptDeployManager == null) {
|
||||
return EncryptDeploy.ANNOTATION;
|
||||
}
|
||||
return encryptDeployManager.getEncryptDeploy(table, column);
|
||||
}
|
||||
|
||||
public DataEncryptSupport createDataEncryptSupport(String table, String column) {
|
||||
DataEncryptSupport createDataEncryptSupport(String table, String column) {
|
||||
return new DataEncryptSupport(encryptKeyManager, bytesEncryptor, table, column);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setEnumScalarType(Enumerated enumerated, DeployBeanProperty prop) {
|
||||
void setEnumScalarType(Enumerated enumerated, DeployBeanProperty prop) {
|
||||
|
||||
Class<?> enumType = prop.getPropertyType();
|
||||
if (!enumType.isEnum()) {
|
||||
@@ -159,19 +155,10 @@ public class DeployUtil {
|
||||
Class<?> propType = property.getPropertyType();
|
||||
try {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(propType, property.getDbType());
|
||||
if (scalarType != null) {
|
||||
if (scalarType != null || property.isTransient()) {
|
||||
return scalarType;
|
||||
}
|
||||
|
||||
String msg = property.getFullBeanName() + " has no ScalarType - type[" + propType.getName() + "]";
|
||||
if (!property.isTransient()) {
|
||||
throw new PersistenceException(msg);
|
||||
|
||||
} else {
|
||||
// this is ok...
|
||||
logger.trace("... transient property {}", msg);
|
||||
return null;
|
||||
}
|
||||
throw new PersistenceException(property.getFullBeanName() + " has no ScalarType - type[" + propType.getName() + "]");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (property.isTransient()) {
|
||||
// expected for transient properties with unknown/non-mapped types
|
||||
@@ -184,7 +171,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
||||
*/
|
||||
public void setDbHstore(DeployBeanProperty prop, DbHstore dbHstore) {
|
||||
void setDbHstore(DeployBeanProperty prop, DbHstore dbHstore) {
|
||||
|
||||
ScalarType<?> scalarType = typeManager.getHstoreScalarType();
|
||||
int dbType = scalarType.getJdbcType();
|
||||
@@ -201,7 +188,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* Set the DbArray type (effectively Postgres only).
|
||||
*/
|
||||
public void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||
void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||
|
||||
Class<?> type = prop.getPropertyType();
|
||||
ScalarType<?> scalarType = typeManager.getArrayScalarType(type, dbArray, prop.getGenericType());
|
||||
@@ -227,13 +214,13 @@ public class DeployUtil {
|
||||
/**
|
||||
* This property is marked as a Lob object.
|
||||
*/
|
||||
public void setDbJsonType(DeployBeanProperty prop, DbJson dbJsonType) {
|
||||
void setDbJsonType(DeployBeanProperty prop, DbJson dbJsonType) {
|
||||
|
||||
int dbType = getDbJsonStorage(dbJsonType.storage());
|
||||
setDbJsonType(prop, dbType, dbJsonType.length());
|
||||
}
|
||||
|
||||
public void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) {
|
||||
void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) {
|
||||
setDbJsonType(prop, DbPlatformType.JSONB, dbJsonB.length());
|
||||
}
|
||||
|
||||
@@ -276,7 +263,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* This property is marked as a Lob object.
|
||||
*/
|
||||
public void setLobType(DeployBeanProperty prop) {
|
||||
void setLobType(DeployBeanProperty prop) {
|
||||
|
||||
ScalarType<?> scalarType = prop.getScalarType();
|
||||
|
||||
@@ -303,7 +290,7 @@ public class DeployUtil {
|
||||
return type.equals(String.class);
|
||||
}
|
||||
|
||||
public boolean isUseJavaxValidationNotNull() {
|
||||
boolean isUseJavaxValidationNotNull() {
|
||||
return useJavaxValidationNotNull;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user