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:org.dcm4chee.xds2.persistence.RegistryObject.java

/**
 * The blob /*from   w  ww  .  j  a  v a 2 s.  c  o  m*/
 */
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "xmlBlob")
@Access(AccessType.PROPERTY)
public byte[] getXml() throws JAXBException {
    log.debug("getXml called (id {})", getId());

    // if fullObject was not used - no need to serialize it
    if (fullObject == null)
        return blobXml;

    // if fullObject was initialized, we have to serialize it to persist any
    // changes that could have been made
    log.debug("Marshalling fullObject in getXml (id {})", getId());
    ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
    marshallerThreadLocal.get().marshal((new ObjectFactory()).createRegistryObject(fullObject), xmlStream);
    byte[] xml = xmlStream.toByteArray();

    return xml;
}

From source file:org.dcm4chee.xds2.persistence.RegistryObject.java

/**
 * Indexed properties that are used in queries. 
 * Do not use the setter - the update is fully seamless - when object is merged/persisted - indexes are re/-created and updated if needed  
 * @return//from w  w  w . j ava  2 s  . c o m
 */
@OneToMany(mappedBy = "subject", cascade = CascadeType.ALL, orphanRemoval = true)
@Access(AccessType.PROPERTY)
@SuppressWarnings("unchecked")
public Set<RegistryObjectIndex> getIndexedValues() {
    log.debug("getIndexedValues called for object with id {}", getId());

    // TODO: OPTIMIZATION - if marshalling is fast - can check whether the object has already changed first

    // if fullObject was not initialized - nothing has changed and we could just return old value 
    // (except if reindexing is forced)
    if (fullObject == null && !FORCE_REINDEX)
        return currIndexedValues;

    if (getIndexes() == null)
        return currIndexedValues;

    // validate/update searchIndex table
    // iterate over all enabled indexes
    Set<RegistryObjectIndex> newIndexValues = new HashSet<RegistryObjectIndex>();
    for (XDSSearchIndexKey key : getIndexes()) {
        // run xpath expr on fullobject
        JXPathContext context = JXPathContext.newContext(getFullObject());
        Iterator<String> valueIterator = (Iterator<String>) context.iterate(INDEX_XPATHS.get(key));

        // add to newIndexValues
        while (valueIterator.hasNext()) {
            RegistryObjectIndex ind = new RegistryObjectIndex();
            ind.setSubject(this);
            ind.setKey(key);
            ind.setValue((String) valueIterator.next());
            newIndexValues.add(ind);
        }
    }

    // Retain what we have there already, and add new ones.
    // Note thats retain makes use of a custom equals for RegistryObjectIndex that does not consider the pk.
    currIndexedValues.retainAll(newIndexValues);
    currIndexedValues.addAll(newIndexValues);

    return currIndexedValues;
}

From source file:org.guzz.builder.JPA2AnnotationsBuilder.java

protected static void parseClassForAttributes(GuzzContextImpl gf, POJOBasedObjectMapping map, Business business,
        DBGroup dbGroup, SimpleTable st, Class domainClass) {
    //???//from  www  .j  a v  a  2  s .  c  o m
    Class parentCls = domainClass.getSuperclass();
    if (parentCls != null && parentCls.isAnnotationPresent(MappedSuperclass.class)) {
        parseClassForAttributes(gf, map, business, dbGroup, st, parentCls);
    }

    javax.persistence.Access access = (javax.persistence.Access) domainClass
            .getAnnotation(javax.persistence.Access.class);
    AccessType accessType = null;

    if (access == null) {
        //@Id@Idfieldproperty
        boolean hasColumnAOnField = false;
        boolean hasColumnAOnProperty = false;

        //detect from @Id, field first.
        Field[] fs = domainClass.getDeclaredFields();

        for (Field f : fs) {
            if (f.isAnnotationPresent(Transient.class))
                continue;
            if (f.isAnnotationPresent(javax.persistence.Id.class)) {
                accessType = AccessType.FIELD;
                break;
            } else if (f.isAnnotationPresent(javax.persistence.Column.class)) {
                hasColumnAOnField = true;
            } else if (f.isAnnotationPresent(org.guzz.annotations.Column.class)) {
                hasColumnAOnField = true;
            }
        }

        if (accessType == null) {
            Method[] ms = domainClass.getDeclaredMethods();
            for (Method m : ms) {
                if (m.isAnnotationPresent(Transient.class))
                    continue;
                if (m.isAnnotationPresent(javax.persistence.Id.class)) {
                    accessType = AccessType.PROPERTY;
                    break;
                } else if (m.isAnnotationPresent(javax.persistence.Column.class)) {
                    hasColumnAOnProperty = true;
                } else if (m.isAnnotationPresent(org.guzz.annotations.Column.class)) {
                    hasColumnAOnProperty = true;
                }
            }
        }

        //@Id@Column@Columnfield?
        if (accessType == null) {
            if (hasColumnAOnField) {
                accessType = AccessType.FIELD;
            } else if (hasColumnAOnProperty) {
                accessType = AccessType.PROPERTY;
            } else {
                accessType = AccessType.FIELD;
            }
        }
    } else {
        accessType = access.value();
    }

    //orm by field
    if (accessType == AccessType.FIELD) {
        Field[] fs = domainClass.getDeclaredFields();

        for (Field f : fs) {
            if (f.isAnnotationPresent(Transient.class))
                continue;
            if (Modifier.isTransient(f.getModifiers()))
                continue;
            if (Modifier.isStatic(f.getModifiers()))
                continue;

            if (f.isAnnotationPresent(javax.persistence.Id.class)) {
                addIdMapping(gf, map, st, dbGroup, f.getName(), domainClass, f);
            } else {
                addPropertyMapping(gf, map, st, f.getName(), f, f.getType());
            }
        }
    } else {
        Method[] ms = domainClass.getDeclaredMethods();
        for (Method m : ms) {
            if (m.isAnnotationPresent(Transient.class))
                continue;
            if (Modifier.isTransient(m.getModifiers()))
                continue;
            if (Modifier.isStatic(m.getModifiers()))
                continue;
            if (Modifier.isPrivate(m.getModifiers()))
                continue;

            String methodName = m.getName();
            String fieldName = null;

            if (m.getParameterTypes().length != 0) {
                continue;
            } else if (Void.TYPE.equals(m.getReturnType())) {
                continue;
            }

            if (methodName.startsWith("get")) {
                fieldName = methodName.substring(3);
            } else if (methodName.startsWith("is")) {//is boolean?
                Class retType = m.getReturnType();

                if (boolean.class.isAssignableFrom(retType)) {
                    fieldName = methodName.substring(2);
                } else if (Boolean.class.isAssignableFrom(retType)) {
                    fieldName = methodName.substring(2);
                }
            }

            //not a javabean read method
            if (fieldName == null) {
                continue;
            }

            fieldName = java.beans.Introspector.decapitalize(fieldName);

            if (m.isAnnotationPresent(javax.persistence.Id.class)) {
                addIdMapping(gf, map, st, dbGroup, fieldName, domainClass, m);
            } else {
                addPropertyMapping(gf, map, st, fieldName, m, m.getReturnType());
            }
        }
    }

    //?attribute override
    AttributeOverride gao = (AttributeOverride) domainClass.getAnnotation(AttributeOverride.class);
    AttributeOverrides gaos = (AttributeOverrides) domainClass.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] aos = gao == null ? new AttributeOverride[0] : new AttributeOverride[] { gao };
    if (gaos != null) {
        ArrayUtil.addToArray(aos, gaos.value());
    }

    for (AttributeOverride ao : aos) {
        String name = ao.name();
        Column col = ao.column();

        TableColumn tc = st.getColumnByPropName(name);
        Assert.assertNotNull(tc,
                "@AttributeOverride cann't override a attribute that doesn't exist. The attribute is:" + name);

        //update is remove and add
        st.removeColumn(tc);

        //change the column name in the database.
        tc.setColName(col.name());

        st.addColumn(tc);
    }
}

From source file:ru.jts_dev.gameserver.model.GameCharacter.java

/**
 * this method only for hibernate mapping!!! NOT FOR USE!!!
 *
 * @return x coordinate of vector3D//w ww  . j  a  va 2s .c  o m
 */
@Access(AccessType.PROPERTY)
@Column(name = "x")
private double getX() {
    return vector3D.getX();
}

From source file:ru.jts_dev.gameserver.model.GameCharacter.java

/**
 * this method only for hibernate mapping!!! NOT FOR USE!!!
 *
 * @return y coordinate of vector3D/*  w w w  . j  a  va 2 s.com*/
 */
@Access(AccessType.PROPERTY)
@Column(name = "y")
private double getY() {
    return vector3D.getY();
}

From source file:ru.jts_dev.gameserver.model.GameCharacter.java

/**
 * this method only for hibernate mapping!!! NOT FOR USE!!!
 *
 * @return z coordinate of vector3D/*from   w  w  w.  j  a  va 2  s . c o  m*/
 */
@Access(AccessType.PROPERTY)
@Column(name = "z")
private double getZ() {
    return vector3D.getZ();
}