Remove Validation and LDAP features

This commit is contained in:
Robin Bygrave
2013-04-09 00:05:42 +12:00
parent fb28c641d0
commit 9f624ec2bf
27 changed files with 132 additions and 609 deletions
@@ -32,7 +32,6 @@ import com.avaje.ebean.Filter;
import com.avaje.ebean.FutureIds;
import com.avaje.ebean.FutureList;
import com.avaje.ebean.FutureRowCount;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.Query;
import com.avaje.ebean.QueryIterator;
@@ -119,11 +118,6 @@ public final class DefaultServer implements SpiEbeanServer {
private static final Logger logger = Logger.getLogger(DefaultServer.class.getName());
/**
* Used when no errors are found validating a property.
*/
private static final InvalidValue[] EMPTY_INVALID_VALUES = new InvalidValue[0];
private final String serverName;
private final DatabasePlatform databasePlatform;
@@ -521,35 +515,6 @@ public final class DefaultServer implements SpiEbeanServer {
beanLoader.loadBean(ebi);
}
public InvalidValue validate(Object bean) {
if (bean == null) {
return null;
}
BeanDescriptor<?> beanDescriptor = getBeanDescriptor(bean.getClass());
return beanDescriptor.validate(true, bean);
}
public InvalidValue[] validate(Object bean, String propertyName, Object value) {
if (bean == null) {
return null;
}
BeanDescriptor<?> beanDescriptor = getBeanDescriptor(bean.getClass());
BeanProperty prop = beanDescriptor.getBeanProperty(propertyName);
if (prop == null) {
String msg = "property " + propertyName + " was not found?";
throw new PersistenceException(msg);
}
if (value == null) {
value = prop.getValue(bean);
}
List<InvalidValue> errors = prop.validate(true, value);
if (errors == null) {
return EMPTY_INVALID_VALUES;
} else {
return InvalidValue.toArray(errors);
}
}
public Map<String, ValuePair> diff(Object a, Object b) {
if (a == null) {
return null;
@@ -176,7 +176,7 @@ public class InternalConfiguration {
public Persister createPersister(SpiEbeanServer server) {
return new DefaultPersister(server, serverConfig.isValidateOnSave(), binder, beanDescriptorManager, pstmtBatch);
return new DefaultPersister(server, binder, beanDescriptorManager, pstmtBatch);
}
public PstmtBatch getPstmtBatch() {
@@ -6,8 +6,6 @@ import java.util.Set;
import javax.persistence.OptimisticLockException;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.ValidationException;
import com.avaje.ebean.annotation.ConcurrencyMode;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
@@ -452,17 +450,6 @@ public class PersistRequestBean<T> extends PersistRequest implements BeanPersist
return intercept;
}
/**
* Validate the bean. This is not recursive and only runs the 'local'
* validation rules.
*/
public void validate() {
InvalidValue errs = beanDescriptor.validate(false, bean);
if (errs != null) {
throw new ValidationException(errs);
}
}
/**
* Return true if this property is loaded (full bean or included in partial
* bean).
@@ -1,10 +1,8 @@
package com.avaje.ebeaninternal.server.deploy;
import java.util.ArrayList;
import java.util.Iterator;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.bean.BeanCollection;
@@ -50,11 +48,6 @@ public interface BeanCollectionHelp<T> {
*/
public BeanCollection<T> createReference(Object parentBean, String propertyName);
/**
* Validate the List Set or Map.
*/
public ArrayList<InvalidValue> validate(Object manyValue);
/**
* Refresh the List Set or Map.
*/
@@ -17,7 +17,6 @@ import java.util.logging.Logger;
import javax.persistence.PersistenceException;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.Query.UseIndex;
import com.avaje.ebean.SqlUpdate;
@@ -38,7 +37,6 @@ import com.avaje.ebean.event.BeanPersistListener;
import com.avaje.ebean.event.BeanQueryAdapter;
import com.avaje.ebean.text.TextException;
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
import com.avaje.ebean.validation.factory.Validator;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.api.SpiUpdatePlan;
@@ -303,28 +301,6 @@ public class BeanDescriptor<T> {
private final Map<String, DeployNamedUpdate> namedUpdates;
/**
* Has local validation rules.
*/
private final boolean hasLocalValidation;
/**
* Has local or recursive validation rules.
*/
private final boolean hasCascadeValidation;
/**
* Properties with local validation rules.
*/
private final BeanProperty[] propertiesValidationLocal;
/**
* Properties with local or cascade validation rules.
*/
private final BeanProperty[] propertiesValidationCascade;
private final Validator[] beanValidators;
/**
* Flag used to determine if saves can be skipped.
*/
@@ -483,13 +459,7 @@ public class BeanDescriptor<T> {
// Check if there are no cascade delete associated beans (also subject to
// change in initialiseOther()).
deleteRecurseSkippable = (0 == (propertiesOneExportedDelete.length + propertiesOneImportedDelete.length + propertiesManyDelete.length));
this.propertiesValidationLocal = listHelper.getPropertiesWithValidators(false);
this.propertiesValidationCascade = listHelper.getPropertiesWithValidators(true);
this.beanValidators = listHelper.getBeanValidators();
this.hasLocalValidation = (propertiesValidationLocal.length > 0 || beanValidators.length > 0);
this.hasCascadeValidation = (propertiesValidationCascade.length > 0 || beanValidators.length > 0);
// object used to handle Id values
this.idBinder = owner.createIdBinder(propertiesId);
}
@@ -1260,88 +1230,6 @@ public class BeanDescriptor<T> {
return deleteRecurseSkippable;
}
/**
* Return true if this type has local validation rules.
*/
public boolean hasLocalValidation() {
return hasLocalValidation;
}
/**
* Return true if this type has local or cascading validation rules.
*/
public boolean hasCascadeValidation() {
return hasCascadeValidation;
}
public InvalidValue validate(boolean cascade, Object bean) {
if (!hasCascadeValidation) {
// no validation rules at all on this bean
return null;
}
List<InvalidValue> errList = null;
Set<String> loadedProps = null;
if (bean instanceof EntityBean) {
EntityBeanIntercept ebi = ((EntityBean) bean)._ebean_getIntercept();
loadedProps = ebi.getLoadedProps();
}
if (loadedProps != null) {
// validate just the loaded properties
Iterator<String> propIt = loadedProps.iterator();
while (propIt.hasNext()) {
String propName = (String) propIt.next();
BeanProperty property = getBeanProperty(propName);
// check if we should fire validation on this property
if (property != null && property.hasValidationRules(cascade)) {
Object value = property.getValue(bean);
List<InvalidValue> errs = property.validate(cascade, value);
if (errs != null) {
if (errList == null) {
errList = new ArrayList<InvalidValue>();
}
errList.addAll(errs);
}
}
}
} else {
// get appropriate list of properties with validation rules
BeanProperty[] props = cascade ? propertiesValidationCascade : propertiesValidationLocal;
// validate all the properties
for (int i = 0; i < props.length; i++) {
BeanProperty prop = props[i];
Object value = prop.getValue(bean);
List<InvalidValue> errs = prop.validate(cascade, value);
if (errs != null) {
if (errList == null) {
errList = new ArrayList<InvalidValue>();
}
errList.addAll(errs);
}
}
}
for (int i = 0; i < beanValidators.length; i++) {
if (!beanValidators[i].isValid(bean)) {
if (errList == null) {
errList = new ArrayList<InvalidValue>();
}
Validator v = beanValidators[i];
errList.add(new InvalidValue(v.getKey(), v.getAttributes(), getFullName(), null, bean));
}
}
if (errList == null) {
return null;
}
return new InvalidValue(null, getFullName(), bean, InvalidValue.toArray(errList));
}
/**
* Return the many property included in the query or null if one is not.
*/
@@ -31,8 +31,6 @@ import com.avaje.ebean.config.dbplatform.DbIdentity;
import com.avaje.ebean.config.dbplatform.IdGenerator;
import com.avaje.ebean.config.dbplatform.IdType;
import com.avaje.ebean.event.BeanFinder;
import com.avaje.ebean.validation.factory.LengthValidatorFactory;
import com.avaje.ebean.validation.factory.NotNullValidatorFactory;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.TransactionEventTable;
import com.avaje.ebeaninternal.server.core.BootupClasses;
@@ -1052,8 +1050,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
setConcurrencyMode(desc);
}
autoAddValidators(desc);
// generate the byte code
createByteCode(desc);
}
@@ -1142,35 +1138,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
setBeanReflect(deploy);
}
/**
* Add Length and NotNull validators based on Column annotation etc.
*/
private void autoAddValidators(DeployBeanDescriptor<?> deployDesc) {
for (DeployBeanProperty prop : deployDesc.propertiesBase()) {
autoAddValidators(prop);
}
}
/**
* Add Length and NotNull validators based on Column annotation etc.
*/
private void autoAddValidators(DeployBeanProperty prop) {
if (String.class.equals(prop.getPropertyType()) && prop.getDbLength() > 0) {
// check if the property already has the LengthValidator
if (!prop.containsValidatorType(LengthValidatorFactory.LengthValidator.class)) {
prop.addValidator(LengthValidatorFactory.create(0, prop.getDbLength()));
}
}
if (!prop.isNullable() && !prop.isId() && !prop.isGenerated()) {
// check if the property already has the NotNullValidator
if (!prop.containsValidatorType(NotNullValidatorFactory.NotNullValidator.class)) {
prop.addValidator(NotNullValidatorFactory.NOT_NULL);
}
}
}
/**
* Set the Scalar Types on all the simple types. This is done AFTER transients
* have been identified. This is because a non-transient field MUST have a
@@ -5,7 +5,6 @@ import java.util.Iterator;
import java.util.List;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.bean.BeanCollection;
@@ -86,24 +85,6 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
return new BeanList<T>(loader, parentBean, propertyName);
}
public ArrayList<InvalidValue> validate(Object manyValue) {
ArrayList<InvalidValue> errs = null;
List<?> l = (List<?>) manyValue;
for (int i = 0; i < l.size(); i++) {
Object detailBean = l.get(i);
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
if (invalid != null) {
if (errs == null) {
errs = new ArrayList<InvalidValue>();
}
errs.add(invalid);
}
}
return errs;
}
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
BeanList<?> newBeanList = (BeanList<?>) server.findList(query, t);
@@ -1,13 +1,11 @@
package com.avaje.ebeaninternal.server.deploy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.bean.BeanCollection;
@@ -121,26 +119,6 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
return new BeanMap(loader, parentBean, propertyName);
}
public ArrayList<InvalidValue> validate(Object manyValue) {
ArrayList<InvalidValue> errs = null;
Map<?, ?> m = (Map<?, ?>) manyValue;
Iterator<?> it = m.values().iterator();
while (it.hasNext()) {
Object detailBean = (Object) it.next();
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
if (invalid != null) {
if (errs == null) {
errs = new ArrayList<InvalidValue>();
}
errs.add(invalid);
}
}
return errs;
}
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) server.findMap(query, t);
refresh(newBeanMap, parentBean);
@@ -7,13 +7,11 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.persistence.PersistenceException;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.config.EncryptKey;
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
@@ -21,7 +19,6 @@ import com.avaje.ebean.config.dbplatform.DbType;
import com.avaje.ebean.text.StringFormatter;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebean.text.TextException;
import com.avaje.ebean.validation.factory.Validator;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
@@ -228,10 +225,6 @@ public class BeanProperty implements ElPropertyValue {
@SuppressWarnings("rawtypes")
final ScalarType scalarType;
final Validator[] validators;
final boolean hasLocalValidators;
boolean cascadeValidate;
/**
@@ -336,9 +329,7 @@ public class BeanProperty implements ElPropertyValue {
this.lob = isLobType(dbType);
this.propertyType = deploy.getPropertyType();
this.field = deploy.getField();
this.validators = deploy.getValidators();
this.hasLocalValidators = (validators.length > 0);
EntityType et = descriptor == null ? null : descriptor.getEntityType();
this.elPlaceHolder = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), false, null);
this.elPlaceHolderEncrypted = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), dbEncrypted, dbColumn);
@@ -421,9 +412,7 @@ public class BeanProperty implements ElPropertyValue {
this.lob = isLobType(dbType);
this.propertyType = source.getPropertyType();
this.field = source.getField();
this.validators = source.getValidators();
this.hasLocalValidators = validators.length > 0;
this.elPlaceHolder = override.replace(source.elPlaceHolder, source.dbColumn);
this.elPlaceHolderEncrypted = override.replace(source.elPlaceHolderEncrypted, source.dbColumn);
@@ -650,22 +639,10 @@ public class BeanProperty implements ElPropertyValue {
return scalarType.readData(dataInput);
}
Validator[] getValidators() {
return validators;
}
public boolean isCascadeValidate() {
return cascadeValidate;
}
public boolean hasLocalValidators() {
return hasLocalValidators;
}
public boolean hasValidationRules(boolean cascade) {
return hasLocalValidators || (cascade && cascadeValidate);
}
/**
* Checks to see if a bean is a reference (will be lazy loaded) or a
* BeanCollection that has not yet been populated.
@@ -677,50 +654,6 @@ public class BeanProperty implements ElPropertyValue {
return true;
}
/**
* Cascade the validation to the associated bean or collection.
*/
public InvalidValue validateCascade(Object value) {
return null;
}
/**
* Validate the property with the given value.
*
* @param cascade
* if true cascade for assoc beans and collections.
* @param value
* the value to validate
* @return the list of errors that occurred.
*/
public final List<InvalidValue> validate(boolean cascade, Object value) {
if (!isValueLoaded(value)) {
return null;
}
ArrayList<InvalidValue> list = null;
for (int i = 0; i < validators.length; i++) {
if (!validators[i].isValid(value)) {
if (list == null) {
list = new ArrayList<InvalidValue>();
}
Validator v = validators[i];
list.add(new InvalidValue(v.getKey(), v.getAttributes(), descriptor.getFullName(), name, value));
}
}
if (list == null && cascade && cascadeValidate) {
// cascade the validation for assoc beans
InvalidValue recursive = validateCascade(value);
if (recursive != null) {
return InvalidValue.toList(recursive);
}
}
return list;
}
public BeanProperty getBeanProperty() {
return this;
}
@@ -9,7 +9,6 @@ import javax.persistence.PersistenceException;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Expression;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.SqlUpdate;
import com.avaje.ebean.Transaction;
@@ -314,18 +313,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
help.add(collection, bean);
}
@Override
public InvalidValue validateCascade(Object manyValue) {
ArrayList<InvalidValue> errs = help.validate(manyValue);
if (errs == null){
return null;
} else {
return new InvalidValue("recurse.many", targetDescriptor.getFullName(), manyValue, InvalidValue.toArray(errs));
}
}
/**
* Refresh the appropriate list set or map.
*/
@@ -8,7 +8,6 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.SqlUpdate;
import com.avaje.ebean.Transaction;
@@ -271,13 +270,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return true;
}
@Override
public InvalidValue validateCascade(Object value) {
BeanDescriptor<?> target = getTargetDescriptor();
return target.validate(true, value);
}
private boolean hasChangedEmbedded(Object bean, Object oldValues) {
Object embValue = getValue(oldValues);
@@ -1,12 +1,10 @@
package com.avaje.ebeaninternal.server.deploy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.InvalidValue;
import com.avaje.ebean.Query;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.bean.BeanCollection;
@@ -91,25 +89,6 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
return new BeanSet<T>(loader, parentBean, propertyName);
}
public ArrayList<InvalidValue> validate(Object manyValue) {
ArrayList<InvalidValue> errs = null;
Set<?> set = (Set<?>)manyValue;
Iterator<?> i = set.iterator();
while (i.hasNext()) {
Object detailBean = i.next();
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
if (invalid != null){
if (errs == null){
errs = new ArrayList<InvalidValue>();
}
errs.add(invalid);
}
}
return errs;
}
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
@@ -3,10 +3,7 @@ package com.avaje.ebeaninternal.server.deploy.meta;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.persistence.EmbeddedId;
@@ -19,7 +16,6 @@ import com.avaje.ebean.annotation.UpdatedTimestamp;
import com.avaje.ebean.config.ScalarTypeConverter;
import com.avaje.ebean.config.dbplatform.DbEncrypt;
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
import com.avaje.ebean.validation.factory.Validator;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
@@ -211,8 +207,6 @@ public class DeployBeanProperty {
*/
private GeneratedProperty generatedProperty;
private List<Validator> validators = new ArrayList<Validator>();
private final DeployBeanDescriptor<?> desc;
private boolean undirectionalShadow;
@@ -404,39 +398,6 @@ public class DeployBeanProperty {
return null;
}
/**
* Add a validator to this property.
*/
public void addValidator(Validator validator) {
validators.add(validator);
}
/**
* Return true if the property contains a validator of a given type.
* <p>
* Used to detect if a validator has already been assigned when trying to
* automatically add validators such as Length and NotNull.
* </p>
*/
public boolean containsValidatorType(Class<?> type) {
Iterator<Validator> it = validators.iterator();
while (it.hasNext()) {
Validator validator = (Validator) it.next();
if (validator.getClass().equals(type)) {
return true;
}
}
return false;
}
/**
* Return the validators for this property.
*/
public Validator[] getValidators() {
return validators.toArray(new Validator[validators.size()]);
}
/**
* Return the scalarType. This returns null for native JDBC types, otherwise
* it is used to convert between logical types and jdbc types.
@@ -6,7 +6,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import com.avaje.ebean.bean.BeanCollection.ModifyListenMode;
import com.avaje.ebean.validation.factory.Validator;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorMap;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -157,23 +156,6 @@ public class DeployBeanPropertyLists {
return derivedFirstVersionProp;
}
public BeanProperty[] getPropertiesWithValidators(boolean recurse) {
ArrayList<BeanProperty> list = new ArrayList<BeanProperty>();
Iterator<BeanProperty> it = propertyMap.values().iterator();
while (it.hasNext()) {
BeanProperty property = (BeanProperty) it.next();
if (property.hasValidationRules(recurse)) {
list.add(property);
}
}
return list.toArray(new BeanProperty[list.size()]);
}
public Validator[] getBeanValidators() {
return new Validator[0];
}
public LinkedHashMap<String, BeanProperty> getPropertyMap() {
return propertyMap;
}
@@ -15,11 +15,11 @@ import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import com.avaje.ebean.annotation.EmbeddedColumns;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebean.validation.NotNull;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
import com.avaje.ebeaninternal.server.deploy.BeanTable;
import com.avaje.ebeaninternal.server.deploy.TableJoin;
@@ -1,8 +1,5 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Types;
import java.util.Iterator;
import java.util.Map;
@@ -23,6 +20,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.EmbeddedColumns;
@@ -36,11 +35,6 @@ import com.avaje.ebean.config.GlobalProperties;
import com.avaje.ebean.config.dbplatform.DbEncrypt;
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
import com.avaje.ebean.config.dbplatform.IdType;
import com.avaje.ebean.validation.Length;
import com.avaje.ebean.validation.NotNull;
import com.avaje.ebean.validation.Pattern;
import com.avaje.ebean.validation.Patterns;
import com.avaje.ebean.validation.ValidatorMeta;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
@@ -92,7 +86,6 @@ public class AnnotationFields extends AnnotationParser {
readField(prop);
}
readValidations(prop);
}
}
@@ -214,11 +207,11 @@ public class AnnotationFields extends AnnotationParser {
prop.setNullable(false);
}
Length length = get(prop, Length.class);
if (length != null) {
if (length.max() < Integer.MAX_VALUE) {
Size size = get(prop, Size.class);
if (size != null) {
if (size.max() < Integer.MAX_VALUE) {
// explicitly specify a version column
prop.setDbLength(length.max());
prop.setDbLength(size.max());
}
}
@@ -460,41 +453,4 @@ public class AnnotationFields extends AnnotationParser {
}
}
private void readValidations(DeployBeanProperty prop) {
Field field = prop.getField();
if (field != null) {
Annotation[] fieldAnnotations = field.getAnnotations();
for (int i = 0; i < fieldAnnotations.length; i++) {
readValidations(prop, fieldAnnotations[i]);
}
}
Method readMethod = prop.getReadMethod();
if (readMethod != null) {
Annotation[] methAnnotations = readMethod.getAnnotations();
for (int i = 0; i < methAnnotations.length; i++) {
readValidations(prop, methAnnotations[i]);
}
}
}
private void readValidations(DeployBeanProperty prop, Annotation ann) {
Class<?> type = ann.annotationType();
if (type.equals(Patterns.class)) {
// treating this as a special case for now...
Patterns patterns = (Patterns) ann;
Pattern[] patternsArray = patterns.patterns();
for (int i = 0; i < patternsArray.length; i++) {
util.createValidator(prop, patternsArray[i]);
}
} else {
ValidatorMeta meta = type.getAnnotation(ValidatorMeta.class);
if (meta != null) {
util.createValidator(prop, ann);
}
}
}
}
@@ -1,8 +1,6 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import java.lang.annotation.Annotation;
import java.sql.Types;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EnumType;
@@ -17,7 +15,6 @@ import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.TableName;
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
import com.avaje.ebean.validation.factory.Validator;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
import com.avaje.ebeaninternal.server.type.DataEncryptSupport;
@@ -50,8 +47,6 @@ public class DeployUtil {
private final TypeManager typeManager;
private final ValidatorFactoryManager validatorFactoryManager;
private final String manyToManyAlias;
private final DatabasePlatform dbPlatform;
@@ -75,8 +70,6 @@ public class DeployUtil {
// this alias is used for ManyToMany lazy loading queries
this.manyToManyAlias = "zzzzzz";
this.validatorFactoryManager = new ValidatorFactoryManager();
}
public TypeManager getTypeManager() {
@@ -119,18 +112,6 @@ public class DeployUtil {
return manyToManyAlias;
}
public void createValidator(DeployBeanProperty prop, Annotation ann) {
try {
Validator validator = validatorFactoryManager.create(ann, prop.getPropertyType());
if (validator != null){
prop.addValidator(validator);
}
} catch (Exception e){
String msg = "Error creating a validator on "+prop.getFullBeanName();
logger.log(Level.SEVERE, msg, e);
}
}
public ScalarType<?> setEnumScalarType(Enumerated enumerated, DeployBeanProperty prop) {
Class<?> enumType = prop.getPropertyType();
@@ -17,119 +17,109 @@ import com.avaje.ebeaninternal.server.deploy.BeanManager;
* </p>
*/
public final class DefaultPersistExecute implements PersistExecute {
private final ExeCallableSql exeCallableSql;
private final ExeUpdateSql exeUpdateSql;
private final ExeOrmUpdate exeOrmUpdate;
/**
* The default batch size.
*/
private final int defaultBatchSize;
/**
* Default for whether to call getGeneratedKeys after batch insert.
*/
private final boolean defaultBatchGenKeys;
private final boolean validate;
/**
* Construct this DmlPersistExecute.
*/
public DefaultPersistExecute(boolean validate, Binder binder, PstmtBatch pstmtBatch) {
this.validate = validate;
this.exeOrmUpdate = new ExeOrmUpdate(binder, pstmtBatch);
this.exeUpdateSql = new ExeUpdateSql(binder, pstmtBatch);
this.exeCallableSql = new ExeCallableSql(binder, pstmtBatch);
this.defaultBatchGenKeys = GlobalProperties.getBoolean("batch.getgeneratedkeys", true);
this.defaultBatchSize = GlobalProperties.getInt("batch.size", 20);
}
private final ExeCallableSql exeCallableSql;
public BatchControl createBatchControl(SpiTransaction t) {
private final ExeUpdateSql exeUpdateSql;
// create a BatchControl and set its defaults
return new BatchControl(t, defaultBatchSize, defaultBatchGenKeys);
}
/**
* execute the bean insert request.
*/
public <T> void executeInsertBean(PersistRequestBean<T> request) {
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preInsert(request)) {
if (validate){
request.validate();
}
persister.insert(request);
// NOTE: the persister fires the postInsert so that this
// occurs before ebeanIntercept.setLoaded(true)
}
}
/**
* execute the bean update request.
*/
public <T> void executeUpdateBean(PersistRequestBean<T> request) {
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preUpdate(request)) {
if (validate){
request.validate();
}
persister.update(request);
// NOTE: the persister fires the postUpdate so that this
// occurs before ebeanIntercept.setLoaded(true)
}
}
private final ExeOrmUpdate exeOrmUpdate;
/**
* execute the bean delete request.
*/
public <T> void executeDeleteBean(PersistRequestBean<T> request) {
/**
* The default batch size.
*/
private final int defaultBatchSize;
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preDelete(request)) {
persister.delete(request);
// NOTE: the persister fires the postDelete
}
}
/**
* Default for whether to call getGeneratedKeys after batch insert.
*/
private final boolean defaultBatchGenKeys;
/**
* Execute the updateSqlRequest
*/
public int executeOrmUpdate(PersistRequestOrmUpdate request) {
return exeOrmUpdate.execute(request);
/**
* Construct this DmlPersistExecute.
*/
public DefaultPersistExecute(Binder binder, PstmtBatch pstmtBatch) {
this.exeOrmUpdate = new ExeOrmUpdate(binder, pstmtBatch);
this.exeUpdateSql = new ExeUpdateSql(binder, pstmtBatch);
this.exeCallableSql = new ExeCallableSql(binder, pstmtBatch);
this.defaultBatchGenKeys = GlobalProperties.getBoolean("batch.getgeneratedkeys", true);
this.defaultBatchSize = GlobalProperties.getInt("batch.size", 20);
}
public BatchControl createBatchControl(SpiTransaction t) {
// create a BatchControl and set its defaults
return new BatchControl(t, defaultBatchSize, defaultBatchGenKeys);
}
/**
* execute the bean insert request.
*/
public <T> void executeInsertBean(PersistRequestBean<T> request) {
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preInsert(request)) {
persister.insert(request);
// NOTE: the persister fires the postInsert so that this
// occurs before ebeanIntercept.setLoaded(true)
}
/**
* Execute the updateSqlRequest
*/
public int executeSqlUpdate(PersistRequestUpdateSql request) {
return exeUpdateSql.execute(request);
}
/**
* execute the bean update request.
*/
public <T> void executeUpdateBean(PersistRequestBean<T> request) {
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preUpdate(request)) {
persister.update(request);
// NOTE: the persister fires the postUpdate so that this
// occurs before ebeanIntercept.setLoaded(true)
}
/**
* Execute the CallableSqlRequest.
*/
public int executeSqlCallable(PersistRequestCallableSql request) {
return exeCallableSql.execute(request);
}
/**
* execute the bean delete request.
*/
public <T> void executeDeleteBean(PersistRequestBean<T> request) {
BeanManager<T> mgr = request.getBeanManager();
BeanPersister persister = mgr.getBeanPersister();
BeanPersistController controller = request.getBeanController();
if (controller == null || controller.preDelete(request)) {
persister.delete(request);
// NOTE: the persister fires the postDelete
}
}
/**
* Execute the updateSqlRequest
*/
public int executeOrmUpdate(PersistRequestOrmUpdate request) {
return exeOrmUpdate.execute(request);
}
/**
* Execute the updateSqlRequest
*/
public int executeSqlUpdate(PersistRequestUpdateSql request) {
return exeUpdateSql.execute(request);
}
/**
* Execute the CallableSqlRequest.
*/
public int executeSqlCallable(PersistRequestCallableSql request) {
return exeCallableSql.execute(request);
}
}
@@ -73,12 +73,11 @@ public final class DefaultPersister implements Persister {
private final boolean defaultUpdateNullProperties;
private final boolean defaultDeleteMissingChildren;
public DefaultPersister(SpiEbeanServer server, boolean validate,
Binder binder, BeanDescriptorManager descMgr, PstmtBatch pstmtBatch) {
public DefaultPersister(SpiEbeanServer server, Binder binder, BeanDescriptorManager descMgr, PstmtBatch pstmtBatch) {
this.server = server;
this.beanDescriptorManager = descMgr;
this.persistExecute = new DefaultPersistExecute(validate, binder, pstmtBatch);
this.persistExecute = new DefaultPersistExecute(binder, pstmtBatch);
this.defaultUpdateNullProperties = server.isDefaultUpdateNullProperties();
this.defaultDeleteMissingChildren = server.isDefaultDeleteMissingChildren();