Package org.apache.openjpa.meta

Examples of org.apache.openjpa.meta.FieldMetaData


    /**
     * Write the stored field or its default value to the given stream.
     */
    public void serialize(ObjectOutput out, boolean def)
        throws IOException {
        FieldMetaData fmd = _sm.getMetaData().getField(field);
        switch (fmd.getDeclaredTypeCode()) {
            case JavaTypes.BOOLEAN:
                out.writeBoolean(!def && longval == 1);
                break;
            case JavaTypes.BYTE:
                out.writeByte((def) ? (byte) 0 : (byte) longval);
View Full Code Here


     * If using property access, see if there is a different backing field
     * name for the persistent attribute <code>name</code>.
     */
    private String toBackingFieldName(String name) {
        // meta is null when enhancing persistence-aware
      FieldMetaData fmd = _meta == null ? null : _meta.getField(name);
        if (_meta != null && isPropertyAccess(fmd)
            && _attrsToFields != null && _attrsToFields.containsKey(name))
            name = (String)_attrsToFields.get(name);
        return name;
    }
View Full Code Here

     * If using property access, see if there is a different persistent
     * attribute name for the backing field <code>name</code>.
     */
    private String fromBackingFieldName(String name) {
        // meta is null when enhancing persistence-aware
      FieldMetaData fmd = _meta == null ? null : _meta.getField(name);
        if (_meta != null && isPropertyAccess(fmd)
            && _fieldsToAttrs != null && _fieldsToAttrs.containsKey(name))
            return (String)_fieldsToAttrs.get(name);
        else
            return name;
View Full Code Here

        if (StringUtils.equals(_directRelationOwner, fm.getFullName(false)))
            clone._load = false;
        else
            clone._load = _load;

        FieldMetaData owner = fm.getMappedByMetaData();
        if (owner != null && owner.getTypeCode() == JavaTypes.PC)
            clone._directRelationOwner = owner.getFullName(false);
       
        return clone;
    }
View Full Code Here

    /**
     * Proxy the held field if needed. Return true if the field needs to
     * be replaced with the now-proxied instance.
     */
    public boolean proxy(boolean reset, boolean replaceNull) {
        FieldMetaData fmd = _sm.getMetaData().getField(field);
        Proxy proxy = null;
        boolean ret = false;
        switch (fmd.getDeclaredTypeCode()) {
            case JavaTypes.DATE:
                if (objval == null)
                    return false;
                proxy = checkProxy(fmd);
                if (proxy == null) {
                    proxy = (Proxy) _sm.newFieldProxy(field);
                    ((Date) proxy).setTime(((Date) objval).getTime());
                    if (proxy instanceof Timestamp && objval instanceof Timestamp)
                        ((Timestamp) proxy).setNanos(((Timestamp) objval).getNanos());
                    ret = true;
                }
                break;
            case JavaTypes.CALENDAR:
                if (objval == null)
                    return false;
                proxy = checkProxy(fmd);
                if (proxy == null) {
                    proxy = (Proxy) _sm.newFieldProxy(field);
                    ((Calendar) proxy).setTime(((Calendar) objval).getTime());
                    ret = true;
                } else {
                    Object init = fmd.getInitializer();
                    if (init != null && init instanceof TimeZone) {
                        ((Calendar) proxy).setTimeZone((TimeZone)init);
                    }
                }
                break;
            case JavaTypes.COLLECTION:
                if (objval == null && !replaceNull)
                    return false;
                proxy = checkProxy(fmd);
                if (proxy == null) {
                    proxy = (Proxy) _sm.newFieldProxy(field);
                    if (objval != null)
                        ((Collection) proxy).addAll((Collection) objval);
                    ret = true;
                }
                break;
            case JavaTypes.MAP:
                if (objval == null && !replaceNull)
                    return false;
                proxy = checkProxy(fmd);
                if (proxy == null) {
                    proxy = (Proxy) _sm.newFieldProxy(field);
                    if (objval != null)
                        ((Map) proxy).putAll((Map) objval);
                    ret = true;
                }
                break;
            case JavaTypes.OBJECT:
                if (objval == null)
                    return false;
                proxy = checkProxy(fmd);
                if (proxy == null) {
                    proxy = getProxyManager().newCustomProxy(objval,
                        _sm.getBroker().getConfiguration().
                        getCompatibilityInstance().getAutoOff());
                    ret = proxy != null;
                }
                break;
        }

        if (proxy != null) {
            proxy.setOwner(_sm, field);
            ChangeTracker tracker = proxy.getChangeTracker();
            if (reset && tracker != null) {
                if (fmd.getDeclaredTypeCode() == JavaTypes.MAP) {
                    // track values if key is derived from value, else keys
                    boolean keys = fmd.getKey().getValueMappedBy() == null;
                    ((MapChangeTracker) tracker).setTrackKeys(keys);
                }
                tracker.startTracking();
            }
            objval = proxy;
View Full Code Here

     */
    public void unproxy() {
        if (objval == null)
            return;

        FieldMetaData fmd = _sm.getMetaData().getField(field);
        switch (fmd.getDeclaredTypeCode()) {
            case JavaTypes.COLLECTION:
            case JavaTypes.MAP:
            case JavaTypes.DATE:
            case JavaTypes.OBJECT:
                if (objval instanceof Proxy) {
View Full Code Here

     * loaded if it is being set by the user.
     */
    protected void loadField(int field, int lockLevel, boolean forWrite,
        boolean fgs) {
        FetchConfiguration fetch = _broker.getFetchConfiguration();
        FieldMetaData fmd = _meta.getField(field);
        BitSet fields = null;
        boolean unloadedDFGFieldMarked = false;

        // if this is a dfg field or we need to load our dfg, do so
        if (fgs && (_flags & FLAG_LOADED) == 0){
            fields = getUnloadedInternal(fetch, LOAD_FGS, null);
            unloadedDFGFieldMarked = true;
        }
        // check for load fetch group
        String lfg = fmd.getLoadFetchGroup();
        boolean lfgAdded = false;
        if (lfg != null) { 
            FieldMetaData[] fmds = _meta.getFields();
            for (int i = 0; i < fmds.length; i++) {
                if (!_loaded.get(i) && (i == field
                    || fmds[i].isInFetchGroup(lfg))) {
                    if (fields == null)
                        fields = new BitSet(fmds.length);
                    fields.set(i);
                }
            }

            // relation field is loaded with the load-fetch-group
            // but this addition must be reverted once the load is over
            if (!fetch.hasFetchGroup(lfg)) {
                fetch.addFetchGroup(lfg);
                lfgAdded = true;
            }
        } else if (fmd.isInDefaultFetchGroup() && fields == null) {
            // no load group but dfg: add dfg fields if we haven't already
            if (!unloadedDFGFieldMarked)
                fields = getUnloadedInternal(fetch, LOAD_FGS, null);
        } else if (!_loaded.get(fmd.getIndex())) {
            // no load group or dfg: load individual field
            if (fields == null)
                fields = new BitSet();
            fields.set(fmd.getIndex());
        }

        // call this method even if there are no unloaded fields; loadFields
        // takes care of things like loading version info and setting PC flags
        try {
View Full Code Here

        if (fetch == null)
            fetch = _broker.getFetchConfiguration();
        // is this field a post-load field?
        if (field != -1) {
            FieldMetaData fmd = _meta.getField(field);
            if (fmd.isInDefaultFetchGroup()
                && fetch.hasFetchGroup(FetchGroup.NAME_DEFAULT)
                && postLoad(FetchGroup.NAME_DEFAULT, fetch))
                return;
            String[] fgs = fmd.getCustomFetchGroups();
            for (int i = 0; i < fgs.length; i++)
                if (fetch.hasFetchGroup(fgs[i]) && postLoad(fgs[i], fetch))
                    return;
        } else {
            for (Iterator itr = fetch.getFetchGroups().iterator();
View Full Code Here

            // back up to the matched instruction
            fi = (FieldInstruction) code.previous();
            name = fi.getFieldName();
            typeName = fi.getFieldTypeName();
            owner = getPersistenceCapableOwner(name, fi.getFieldDeclarerType());
            FieldMetaData fmd = owner == null ? null : owner.getField(name);
            if (isPropertyAccess(fmd)) {
                // if we're directly accessing a field in another class
                // hierarchy that uses property access, something is wrong
                if (owner != _meta && owner.getDeclaredField(name) != null &&
                    _meta != null && !owner.getDescribedType()
View Full Code Here

        // if (pcStateManager == null)
        loadManagedInstance(code, false);
        code.getfield().setField(SM, SMTYPE);
        JumpInstruction ifins = code.ifnonnull();
        FieldMetaData versionField = _meta.getVersionField();

        if (versionField == null)
            code.constant().setNull(); // return null;
        else {
            // return <versionField>;
            Class wrapper = toPrimitiveWrapper(versionField);
            if (wrapper != versionField.getDeclaredType()) {
                code.anew().setType(wrapper);
                code.dup();
            }
            loadManagedInstance(code, false);
            addGetManagedValueCode(code, versionField);
            if (wrapper != versionField.getDeclaredType())
                code.invokespecial().setMethod(wrapper, "<init>", void.class,
                    new Class[]{ versionField.getDeclaredType() });
        }
        code.areturn();

        // return pcStateManager.getVersion ();
        ifins.setTarget(loadManagedInstance(code, false));
View Full Code Here

TOP

Related Classes of org.apache.openjpa.meta.FieldMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.