Package org.apache.openjpa.util

Examples of org.apache.openjpa.util.Proxy


     * 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();
                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();
                if (proxy == null) {
                    proxy = (Proxy) _sm.newFieldProxy(field);
                    ((Calendar) proxy).setTime(((Calendar) objval).getTime());
                    ret = true;
                }
                break;
            case JavaTypes.COLLECTION:
                if (objval == null && !replaceNull)
                    return false;
                proxy = checkProxy();
                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();
                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();
                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);
View Full Code Here


     */
    private Proxy checkProxy() {
        if (!(objval instanceof Proxy))
            return null;

        Proxy proxy = (Proxy) objval;
        if (proxy.getOwner() == null || Proxies.isOwner(proxy, _sm, field))
            return proxy;
        return null;
    }
View Full Code Here

            case JavaTypes.COLLECTION:
            case JavaTypes.MAP:
            case JavaTypes.DATE:
            case JavaTypes.OBJECT:
                if (objval instanceof Proxy) {
                    Proxy proxy = (Proxy) objval;
                    proxy.setOwner(null, -1);
                    if (proxy.getChangeTracker() != null)
                        proxy.getChangeTracker().stopTracking();
                }
        }
    }
View Full Code Here

            return;

        Object obj = sm.fetchObject(field.getIndex());
        ChangeTracker ct = null;
        if (obj instanceof Proxy) {
            Proxy proxy = (Proxy) obj;
            if (Proxies.isOwner(proxy, sm, field.getIndex()))
                ct = proxy.getChangeTracker();
        }

        Column order = field.getOrderColumn();

        // if no fine-grained change tracking or if an item was removed
View Full Code Here

    public void load(final OpenJPAStateManager sm, final JDBCStore store,
        final JDBCFetchConfiguration fetch)
        throws SQLException {
        if (field.isLRS()) {
            Proxy coll = newLRSProxy();

            // if this is ordered we need to know the next seq to use in case
            // objects are added to the collection
            if (field.getOrderColumn() != null) {
                // we don't allow ordering table per class one-many's, so
                // we know we don't need a union
                Select sel = store.getSQLFactory().newSelect();
                sel.setAggregate(true);
                StringBuilder sql = new StringBuilder();
                sql.append("MAX(").
                    append(sel.getColumnAlias(field.getOrderColumn())).
                    append(")");
                sel.select(sql.toString(), field);
                ClassMapping rel = getDefaultElementMapping(false);
                sel.whereForeignKey(getJoinForeignKey(rel),
                    sm.getObjectId(), field.getDefiningMapping(), store);

                Result res = sel.execute(store, fetch);
                try {
                    res.next();
                    coll.getChangeTracker().setNextSequence
                        (res.getInt(field) + 1);
                } finally {
                    res.close();
                }
            }
View Full Code Here

            return;

        Object obj = sm.fetchObject(field.getIndex());
        ChangeTracker ct = null;
        if (obj instanceof Proxy) {
            Proxy proxy = (Proxy) obj;
            if (Proxies.isOwner(proxy, sm, field.getIndex()))
                ct = proxy.getChangeTracker();
        }
        Column order = field.getOrderColumn();

        // if no fine-grained change tracking then just delete and reinsert
        // if no fine-grained change tracking or if an item was removed
View Full Code Here

        assertNotNull(proxy.getDeclaredMethod("setElementAt",
            new Class[] {Object.class, int.class}));
    }

    public void testListChangeTracker() {
        Proxy coll = _mgr.newCollectionProxy(ArrayList.class, null, null,true);
        assertNotNull(coll);
        assertNotNull(coll.getChangeTracker());
        assertTrue(coll.getChangeTracker()
            instanceof CollectionChangeTrackerImpl);
        CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl)
            coll.getChangeTracker();
        assertTrue(ct.allowsDuplicates());
        assertTrue(ct.isOrdered());
    }
View Full Code Here

        assertTrue(ct.allowsDuplicates());
        assertTrue(ct.isOrdered());
    }
   
    public void testSetChangeTracker() {
        Proxy coll = _mgr.newCollectionProxy(HashSet.class, null, null,true);
        assertNotNull(coll);
        assertNotNull(coll.getChangeTracker());
        assertTrue(coll.getChangeTracker()
            instanceof CollectionChangeTrackerImpl);
        CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl)
            coll.getChangeTracker();
        assertFalse(ct.allowsDuplicates());
        assertFalse(ct.isOrdered());
    }
View Full Code Here

        assertFalse(ct.allowsDuplicates());
        assertFalse(ct.isOrdered());
    }
    public void testCollectionInterfaceProxy() {
        Proxy coll = _mgr.newCollectionProxy(Collection.class, null, null,true);
        assertNotNull(coll);
    }
View Full Code Here

        Proxy coll = _mgr.newCollectionProxy(Collection.class, null, null,true);
        assertNotNull(coll);
    }

    public void testListInterfaceProxy() {
        Proxy coll = _mgr.newCollectionProxy(List.class, null, null,true);
        assertNotNull(coll);
        assertTrue(coll instanceof List);
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.util.Proxy

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.