Example usage for javax.persistence AccessType PROPERTY

List of usage examples for javax.persistence AccessType PROPERTY

Introduction

In this page you can find the example usage for javax.persistence AccessType PROPERTY.

Prototype

AccessType PROPERTY

To view the source code for javax.persistence AccessType PROPERTY.

Click Source Link

Document

Property-based access is used.

Usage

From source file:com.nuevebit.miroculus.mrna.core.MiRNA.java

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "SeqGen-MiRNA")
@TableGenerator(name = "SeqGen-MiRNA", table = "ID_GEN", pkColumnName = "ID_NAME", valueColumnName = "ID_VAL", pkColumnValue = "mirnaId", initialValue = 1, allocationSize = 500)
@Access(AccessType.PROPERTY)
@Override//from w  w w .j  av  a2  s.  com
public Long getId() {
    return super.getId();
}

From source file:com.sample.domain.entities.anagrafica.Tutore.java

@Access(AccessType.PROPERTY)
@Column(name = "QUALIFICA")
String getTipologiaTutoreCode() {
    return (tipologiaTutore != null) ? tipologiaTutore.getCodiceTipologiaTutore() : null;
}

From source file:com.sample.domain.entities.anagrafica.Contratto.java

@Access(AccessType.PROPERTY)
@Column(name = "COD_STATO")
String getCodiceStatoCode() {
    return (codiceStato != null) ? codiceStato.getCodiceStato() : null;
}

From source file:com.sample.domain.entities.anagrafica.Contratto.java

@Access(AccessType.PROPERTY)
@Column(name = "FLAG_RENDICONTAZIONE")
String getTipologiaRendicontazioneCode() {
    return (rendicontazione != null) ? rendicontazione.getTipologiaRendicontazione() : null;
}

From source file:com.sample.domain.entities.anagrafica.Contratto.java

@Access(AccessType.PROPERTY)
@Column(name = "FLAG_ALERT")
String getFlagAlertCode() {
    return (flagAlert != null) ? flagAlert.getFlagAlert() : null;
}

From source file:es.uvigo.ei.sing.gc.model.entities.ExpertResult.java

@Column(name = "abortCause", length = 1048576, nullable = true)
@Lob/*from   w w  w.  j a  v  a 2 s .co  m*/
@Access(AccessType.PROPERTY)
private void setSerializedAbortCause(byte[] abortCause) {
    this.abortCause = abortCause;
}

From source file:com.sample.domain.entities.anagrafica.Cliente.java

@Access(AccessType.PROPERTY)
@Column(name = "COD_TIPOCLIENTE")
String getTipologiaClienteCode() {
    return (tipologiaCliente != null) ? tipologiaCliente.getCodiceTipologiaCliente() : "";
}

From source file:org.apache.openjpa.persistence.PersistenceMetaDataDefaults.java

protected boolean isDefaultPersistent(ClassMetaData meta, Member member, String name, boolean ignoreTransient) {
    int mods = member.getModifiers();
    if (Modifier.isTransient(mods))
        return false;
    int access = meta.getAccessType();

    if (member instanceof Field) {
        // If mixed or unknown, default property access, keep explicit 
        // field members
        if (AccessCode.isProperty(access)) {
            if (!isAnnotatedAccess(member, AccessType.FIELD))
                return false;
        }//  w ww  .  j ava 2 s .  c om
    } else if (member instanceof Method) {
        // If mixed or unknown, field default access, keep explicit property
        // members
        if (AccessCode.isField(access)) {
            if (!isAnnotatedAccess(member, AccessType.PROPERTY))
                return false;
        }
        try {
            // check for setters for methods
            Method setter = (Method) AccessController.doPrivileged(J2DoPrivHelper.getDeclaredMethodAction(
                    meta.getDescribedType(), "set" + StringUtils.capitalize(name),
                    new Class[] { ((Method) member).getReturnType() }));
            if (setter == null && !isAnnotatedTransient(member)) {
                logNoSetter(meta, name, null);
                return false;
            }
        } catch (Exception e) {
            // e.g., NoSuchMethodException
            if (!isAnnotatedTransient(member))
                logNoSetter(meta, name, e);
            return false;
        }
    }

    PersistenceStrategy strat = getPersistenceStrategy(null, member, ignoreTransient);
    if (strat == null) {
        warn(meta, _loc.get("no-pers-strat", name));
        return false;
    } else if (strat == PersistenceStrategy.TRANSIENT) {
        return false;
    } else {
        return true;
    }
}

From source file:org.apache.openjpa.persistence.PersistenceMetaDataDefaults.java

/**
 * Gets either the instance field or the getter method depending upon the 
 * access style of the given meta-data.//from   w w w .j av  a2s  . com
 */
public Member getMemberByProperty(ClassMetaData meta, String property, int access, boolean applyDefaultRule) {
    Class<?> cls = meta.getDescribedType();
    Field field = Reflection.findField(cls, property, false);
    ;
    Method getter = Reflection.findGetter(cls, property, false);
    Method setter = Reflection.findSetter(cls, property, false);
    int accessCode = AccessCode.isUnknown(access) ? meta.getAccessType() : access;
    if (field == null && getter == null)
        error(meta, _loc.get("access-no-property", cls, property));
    if ((isNotTransient(getter) && isAnnotated(getter)) && isNotTransient(field) && isAnnotated(field))
        throw new IllegalStateException(_loc.get("access-duplicate", field, getter).toString());

    if (AccessCode.isField(accessCode)) {
        if (isAnnotatedAccess(getter, AccessType.PROPERTY)) {
            meta.setAccessType(AccessCode.MIXED | meta.getAccessType());
            return getter;
        }
        return field == null ? getter : field;
    } else if (AccessCode.isProperty(accessCode)) {
        if (isAnnotatedAccess(field, AccessType.FIELD)) {
            meta.setAccessType(AccessCode.MIXED | meta.getAccessType());
            return field;
        }
        return getter == null ? field : getter;
    } else if (AccessCode.isUnknown(accessCode)) {
        if (isAnnotated(field)) {
            meta.setAccessType(AccessCode.FIELD);
            return field;
        } else if (isAnnotated(getter)) {
            meta.setAccessType(AccessCode.PROPERTY);
            return getter;
        } else {
            warn(meta, _loc.get("access-none", meta, property));
            throw new IllegalStateException(_loc.get("access-none", meta, property).toString());
        }
    } else {
        throw new InternalException(meta + " " + AccessCode.toClassString(meta.getAccessType()));
    }
}

From source file:org.batoo.jpa.parser.impl.metadata.type.ManagedTypeMetadatImpl.java

/**
 * Infers and returns the access type based on all persistence annotations being on fields or methods and parent parent access type.
 * /*from  ww  w .j a  v  a2s  .  c  o m*/
 * @param parentAccessType
 *            the parent access type
 * @return the inferred access type
 * 
 * @since 2.0.0
 */
private AccessType inferAccessType(AccessType parentAccessType) {
    boolean methodsHasAnnotations = false;
    boolean fieldsHasAnnotations = false;

    final List<String> alternated = Lists.newArrayList();

    final Field[] fields = this.clazz.getDeclaredFields();
    final Method[] methods = this.clazz.getDeclaredMethods();

    // find the alternated ones with @Access
    for (final Method m : methods) {
        // skip static and private methods.
        final int mods = m.getModifiers();
        if (Modifier.isStatic(mods) || !Modifier.isPublic(mods) || m.isBridge() || m.isSynthetic()) {
            continue;
        }

        if ((m.getParameterTypes().length != 0) || (m.getReturnType() == null)) {
            continue;
        }

        final Access access = m.getAnnotation(Access.class);
        if (access != null) {
            final String name = m.getName();
            if ((m.getReturnType() == boolean.class) && name.startsWith("is")) {
                alternated.add(StringUtils.capitalize(name.substring(2)));
            } else if (name.startsWith("get")) {
                alternated.add(StringUtils.capitalize(name.substring(3)));
            }
        }
    }

    for (final Field f : fields) {
        final Access access = f.getAnnotation(Access.class);

        if (access != null) {
            alternated.add(StringUtils.capitalize(f.getName()));
        }
    }

    // check methods
    for (final Method m : methods) {
        for (final Annotation a : m.getAnnotations()) {
            // ignore @Access(PROPERTY)
            if (a instanceof Access) {
                if (((Access) a).value() != AccessType.PROPERTY) {
                    continue;
                }
            }

            // ignore @Transient
            if (a instanceof Transient) {
                continue;
            }

            if ((m.getReturnType() == null) || (m.getParameterTypes().length > 0)) {
                continue;
            }

            String name = a.annotationType().getName();
            // ignore the listener annotations
            if (name.startsWith("javax.persistence.Post") || name.startsWith("javax.persistence.Pre")) {
                continue;
            }

            if (name.startsWith("javax.persistence") || name.startsWith("org.batoo.jpa.annotation")) {
                name = m.getName();

                if ((boolean.class == m.getReturnType()) || name.startsWith("is")) {
                    name = name.substring(2);
                } else if (name.startsWith("get")) {
                    name = name.substring(3);
                }

                if (alternated.contains(StringUtils.capitalize(name))) {
                    continue;
                }

                methodsHasAnnotations = true;
                break;
            }
        }
    }

    // check fields
    for (final Field f : fields) {
        for (final Annotation a : f.getAnnotations()) {
            // ignore @Access(FIELD)
            if (a instanceof Access) {
                if (((Access) a).value() != AccessType.FIELD) {
                    continue;
                }
            }

            // ignore @Transient
            if (a instanceof Transient) {
                continue;
            }

            final String name = a.annotationType().getName();
            if (name.startsWith("javax.persistence") || name.startsWith("org.batoo.jpa.annotation")) {
                if (alternated.contains(StringUtils.capitalize(f.getName()))) {
                    continue;
                }

                fieldsHasAnnotations = true;
                break;
            }
        }
    }

    if (fieldsHasAnnotations && methodsHasAnnotations) {
        throw new PersistenceException(
                "At least one field and one method has persistence annotations: " + this.clazz.getName());
    }

    if (methodsHasAnnotations) {
        return AccessType.PROPERTY;
    }

    if (fieldsHasAnnotations) {
        return AccessType.FIELD;
    }

    if (parentAccessType != null) {
        return parentAccessType;
    }

    return AccessType.FIELD;
}