/** * Get the name of the Specification only (not the version or other * information) or an empty String if not set. * */ public String getSpecification() { Specification spec = getSpecificationInstance(); return spec == null ? "" : spec.getName(); }
/** * Set a value from the given String after validating. * * @param str can be null to set the Specification to null. * If non-null, then the String must be in Specification format * @see Specification#create(String) */ @Override public void setString(String str) { this.set(str == null ? null : new Specification(str)); }
/** * Construct from a String that encodes name and version fields. * * @param fullName a encoded string in the following prescribed format. * <code>name major.minor</code> e.g. <code>JPA 2.0-draft</code> * Only the 'name' field is mandatory. * 'major' version defaults to 1 and must be an integer. * 'minor' version defaults to 0 and can be a String. */ public Specification(String fullName) { try { Object[] tokens = parse(fullName); _name = tokens[0].toString(); _major = tokens.length > 1 ? Integer.parseInt(tokens[1].toString()) : 1; _minor = tokens.length > 2 ? tokens[2].toString() : "0"; } catch (Exception e) { throw new UserException(_loc.get("spec-wrong-format", fullName)); } }
@Override public boolean afterSpecificationSet(Configuration c) { if (!OpenJPAConfigurationImpl.class.isInstance(c) && !SPEC_JPA.isSame(((OpenJPAConfiguration) c).getSpecification())) return false; OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c; conf.metaFactoryPlugin.setDefault(SPEC_JPA.getName()); conf.metaFactoryPlugin.setString(SPEC_JPA.getName()); conf.nontransactionalWrite.setDefault("true"); conf.nontransactionalWrite.set(true); Specification spec = ((OpenJPAConfiguration) c).getSpecificationInstance(); int specVersion = spec.getVersion(); Compatibility compatibility = conf.getCompatibilityInstance(); spec.setCompatibility(compatibility); if (specVersion < 2) { compatibility.setFlushBeforeDetach(true); compatibility.setCopyOnDetach(true); compatibility.setPrivatePersistentProperties(true); compatibility.setIgnoreDetachedStateFieldForProxySerialization(true); // Disable bean validation for spec level < 2 configurations conf.validationMode.set(String.valueOf(ValidationMode.NONE)); } else { compatibility.setAbstractMappingUniDirectional(true); compatibility.setNonDefaultMappingAllowed(true); } return true; }
/** * Validates if the given Specification can overwrite the current * Specification. If the given Specification is not same as the * current one, then it is valid to overwrite. * If the given Specification is same as the current Specification then * it must have a major version number equal or less than the current one. * * @exception fatal UserException if the given Specification is same as * the current Specification but has a higher major version. * * @see Specification#equals(Object) */ protected void validateOverwrite(Specification newSpec) { Specification current = (Specification)get(); if (current != null) { Log log = _conf.getConfigurationLog(); if (!current.isSame(newSpec)) { log.warn(_loc.get("spec-different", newSpec, current)); return; } if (current.compareVersion(newSpec) < 0) { throw new UserException(_loc.get("spec-version-higher", newSpec, current)).setFatal(true); } if (current.compareVersion(newSpec) > 0) { log.warn(_loc.get("spec-version-lower", newSpec, current)); } } }
/** * If a Compatibility instance is associated with the Specification, * we will configure this Compatibility instance instead of instantiating a * new one so that the compatibility flags set in compliance with the * Specification can be preserved. */ public Compatibility getCompatibilityInstance() { if (compatibilityPlugin.get() == null) { Specification spec = getSpecificationInstance(); Compatibility comp = spec != null ? spec.getCompatibility() : null; if (comp == null) compatibilityPlugin.instantiate(Compatibility.class, this); else compatibilityPlugin.configure(comp, this); } return (Compatibility) compatibilityPlugin.get(); }
if (conf.getSpecificationInstance().getVersion() < 2) { if (log.isTraceEnabled()) { log.trace("Not creating a ValidatorImpl because " +
@Override public boolean afterSpecificationSet(Configuration c) { if (!OpenJPAConfigurationImpl.class.isInstance(c) && !SPEC_JPA.isSame(((OpenJPAConfiguration) c).getSpecification())) return false; OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c; conf.metaFactoryPlugin.setDefault(SPEC_JPA.getName()); conf.metaFactoryPlugin.setString(SPEC_JPA.getName()); conf.nontransactionalWrite.setDefault("true"); conf.nontransactionalWrite.set(true); Specification spec = ((OpenJPAConfiguration) c).getSpecificationInstance(); int specVersion = spec.getVersion(); Compatibility compatibility = conf.getCompatibilityInstance(); spec.setCompatibility(compatibility); if (specVersion < 2) { compatibility.setFlushBeforeDetach(true); compatibility.setCopyOnDetach(true); compatibility.setPrivatePersistentProperties(true); compatibility.setIgnoreDetachedStateFieldForProxySerialization(true); // Disable bean validation for spec level < 2 configurations conf.validationMode.set(String.valueOf(ValidationMode.NONE)); } else { compatibility.setAbstractMappingUniDirectional(true); compatibility.setNonDefaultMappingAllowed(true); } return true; }
/** * Validates if the given Specification can overwrite the current * Specification. If the given Specification is not same as the * current one, then it is valid to overwrite. * If the given Specification is same as the current Specification then * it must have a major version number equal or less than the current one. * * @exception fatal UserException if the given Specification is same as * the current Specification but has a higher major version. * * @see Specification#equals(Object) */ protected void validateOverwrite(Specification newSpec) { Specification current = (Specification)get(); if (current != null) { Log log = _conf.getConfigurationLog(); if (!current.isSame(newSpec)) { log.warn(_loc.get("spec-different", newSpec, current)); return; } if (current.compareVersion(newSpec) < 0) { throw new UserException(_loc.get("spec-version-higher", newSpec, current)).setFatal(true); } if (current.compareVersion(newSpec) > 0) { log.warn(_loc.get("spec-version-lower", newSpec, current)); } } }
/** * If a Compatibility instance is associated with the Specification, * we will configure this Compatibility instance instead of instantiating a * new one so that the compatibility flags set in compliance with the * Specification can be preserved. */ public Compatibility getCompatibilityInstance() { if (compatibilityPlugin.get() == null) { Specification spec = getSpecificationInstance(); Compatibility comp = spec != null ? spec.getCompatibility() : null; if (comp == null) compatibilityPlugin.instantiate(Compatibility.class, this); else compatibilityPlugin.configure(comp, this); } return (Compatibility) compatibilityPlugin.get(); }
if (conf.getSpecificationInstance().getVersion() < 2) { if (log.isTraceEnabled()) { log.trace("Not creating a ValidatorImpl because " +
@Override public boolean afterSpecificationSet(Configuration c) { if (!OpenJPAConfigurationImpl.class.isInstance(c) && !SPEC_JPA.isSame(((OpenJPAConfiguration) c).getSpecification())) return false; OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c; conf.metaFactoryPlugin.setDefault(SPEC_JPA.getName()); conf.metaFactoryPlugin.setString(SPEC_JPA.getName()); conf.nontransactionalWrite.setDefault("true"); conf.nontransactionalWrite.set(true); Specification spec = ((OpenJPAConfiguration) c).getSpecificationInstance(); int specVersion = spec.getVersion(); Compatibility compatibility = conf.getCompatibilityInstance(); spec.setCompatibility(compatibility); if (specVersion < 2) { compatibility.setFlushBeforeDetach(true); compatibility.setCopyOnDetach(true); compatibility.setPrivatePersistentProperties(true); compatibility.setIgnoreDetachedStateFieldForProxySerialization(true); // Disable bean validation for spec level < 2 configurations conf.validationMode.set(String.valueOf(ValidationMode.NONE)); } else { compatibility.setAbstractMappingUniDirectional(true); compatibility.setNonDefaultMappingAllowed(true); } return true; }
/** * Get the name of the Specification only (not the version or other * information) or an empty String if not set. * */ public String getSpecification() { Specification spec = getSpecificationInstance(); return spec == null ? "" : spec.getName(); }
/** * Validates if the given Specification can overwrite the current * Specification. If the given Specification is not same as the * current one, then it is valid to overwrite. * If the given Specification is same as the current Specification then * it must have a major version number equal or less than the current one. * * @exception fatal UserException if the given Specification is same as * the current Specification but has a higher major version. * * @see Specification#equals(Object) */ protected void validateOverwrite(Specification newSpec) { Specification current = (Specification)get(); if (current != null) { Log log = _conf.getConfigurationLog(); if (!current.isSame(newSpec)) { log.warn(_loc.get("spec-different", newSpec, current)); return; } if (current.compareVersion(newSpec) < 0) { throw new UserException(_loc.get("spec-version-higher", newSpec, current)).setFatal(true); } if (current.compareVersion(newSpec) > 0) { log.warn(_loc.get("spec-version-lower", newSpec, current)); } } }
/** * Set a value from the given String after validating. * * @param str can be null to set the Specification to null. * If non-null, then the String must be in Specification format * @see Specification#create(String) */ @Override public void setString(String str) { this.set(str == null ? null : new Specification(str)); }
/** * If a Compatibility instance is associated with the Specification, * we will configure this Compatibility instance instead of instantiating a * new one so that the compatibility flags set in compliance with the * Specification can be preserved. */ public Compatibility getCompatibilityInstance() { if (compatibilityPlugin.get() == null) { Specification spec = getSpecificationInstance(); Compatibility comp = spec != null ? spec.getCompatibility() : null; if (comp == null) compatibilityPlugin.instantiate(Compatibility.class, this); else compatibilityPlugin.configure(comp, this); } return (Compatibility) compatibilityPlugin.get(); }
/** * Construct from a String that encodes name and version fields. * * @param fullName a encoded string in the following prescribed format. * <code>name major.minor</code> e.g. <code>JPA 2.0-draft</code> * Only the 'name' field is mandatory. * 'major' version defaults to 1 and must be an integer. * 'minor' version defaults to 0 and can be a String. */ public Specification(String fullName) { try { Object[] tokens = parse(fullName); _name = tokens[0].toString(); _major = tokens.length > 1 ? Integer.parseInt(tokens[1].toString()) : 1; _minor = tokens.length > 2 ? tokens[2].toString() : "0"; } catch (Exception e) { throw new UserException(_loc.get("spec-wrong-format", fullName)); } }
if (conf.getSpecificationInstance().getVersion() < 2) { if (log.isTraceEnabled()) { log.trace("Not creating a ValidatorImpl because " +
@Override public boolean afterSpecificationSet(Configuration c) { if (!OpenJPAConfigurationImpl.class.isInstance(c) && !SPEC_JPA.isSame(((OpenJPAConfiguration) c).getSpecification())) return false; OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c; conf.metaFactoryPlugin.setDefault(SPEC_JPA.getName()); conf.metaFactoryPlugin.setString(SPEC_JPA.getName()); conf.nontransactionalWrite.setDefault("true"); conf.nontransactionalWrite.set(true); Specification spec = ((OpenJPAConfiguration) c).getSpecificationInstance(); int specVersion = spec.getVersion(); Compatibility compatibility = conf.getCompatibilityInstance(); spec.setCompatibility(compatibility); if (specVersion < 2) { compatibility.setFlushBeforeDetach(true); compatibility.setCopyOnDetach(true); compatibility.setPrivatePersistentProperties(true); compatibility.setIgnoreDetachedStateFieldForProxySerialization(true); // Disable bean validation for spec level < 2 configurations conf.validationMode.set(String.valueOf(ValidationMode.NONE)); } else { compatibility.setAbstractMappingUniDirectional(true); compatibility.setNonDefaultMappingAllowed(true); } return true; }
/** * Get the name of the Specification only (not the version or other * information) or an empty String if not set. * */ public String getSpecification() { Specification spec = getSpecificationInstance(); return spec == null ? "" : spec.getName(); }