Package org.apache.openjpa.util

Examples of org.apache.openjpa.util.Proxy


        assertNotNull(coll);
        assertTrue(coll instanceof List);
    }

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


        assertTrue(coll instanceof Set);
        assertFalse(coll instanceof SortedSet);
    }

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

    public void testQueueInterfaceProxy() {
        Class queue = getQueueClass();
        if (queue == null)
            return;

        Proxy coll = _mgr.newCollectionProxy(queue, null, null,true);
        assertNotNull(coll);
        assertTrue(queue.isInstance(coll));
    }
View Full Code Here

        populate(cal);
        assertCalendarsEquals(cal, (Calendar)orig.clone());
    }

    public void testCalendarAbstractClassProxy() {
        Proxy cal = _mgr.newCalendarProxy(Calendar.class, null);
        assertNotNull(cal);
    }
View Full Code Here

                case JavaTypes.CALENDAR:
                case JavaTypes.DATE:
                case JavaTypes.OBJECT:
                    sm.provideField(getDetachedPersistenceCapable(), this, i);
                    if (objval instanceof Proxy) {
                        Proxy proxy = (Proxy) objval;
                        if (proxy.getChangeTracker() != null)
                            proxy.getChangeTracker().stopTracking();
                        proxy.setOwner(dsm, (dsm == null) ? -1 : i);
                    }
                }
            }
            clear();
        }
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);
                StringBuffer sql = new StringBuffer();
                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

            nullField(fieldIndex, pc, sm, fm);
        } else {
            Object o = sm.fetchObject(fieldIndex);
            if (o instanceof Proxy) {
                // Get unproxied object and replace
                Proxy proxy = (Proxy) o;
                if (!_detachProxies) {
                    // Even if we're not detaching proxies, we need to remove the reference to the SM.
                    proxy.setOwner(null, -1);
                    return;
                }
                Object unproxied = proxy.copy(proxy);
                fm.storeObjectField(fieldIndex, unproxied);
                sm.replaceField(pc, fm, fieldIndex);
                fm.clear();
                // clean up old proxy
                proxy.setOwner(null, -1);
                if (proxy.getChangeTracker() != null) {
                    proxy.getChangeTracker().stopTracking();
                }
            }
        }
    }
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);
View Full Code Here

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

        Proxy proxy = (Proxy) objval;
        if (proxy.getOwner() == null || Proxies.isOwner(proxy, _sm, field)) {
            if (fmd.getProxyType().isAssignableFrom(proxy.getClass())
                    || (fmd.isLRS() && (objval instanceof LRSProxy))) {
                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

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.