Package org.apache.cayenne.util

Examples of org.apache.cayenne.util.GenericResponse


    public void testSerialization() throws Exception {
        List list = new ArrayList();
        list.add(new HashMap());

        GenericResponse r = new GenericResponse();
        r.addBatchUpdateCount(new int[] {
                1, 2, 3
        });
        r.addResultList(list);

        GenericResponse sr = (GenericResponse) Util.cloneViaSerialization(r);
        assertNotNull(sr);
        assertEquals(2, sr.size());

        assertTrue(sr.next());
        assertFalse(sr.isList());

        int[] srInt = sr.currentUpdateCount();
        assertEquals(3, srInt.length);
        assertEquals(2, srInt[1]);

        assertTrue(sr.next());
        assertTrue(sr.isList());

        assertEquals(list, sr.currentList());

        assertFalse(sr.next());
    }
View Full Code Here


   
    public void testSerializationWithHessian() throws Exception {
        List list = new ArrayList();
        list.add(new HashMap());

        GenericResponse r = new GenericResponse();
        r.addBatchUpdateCount(new int[] {
                1, 2, 3
        });
        r.addResultList(list);

        GenericResponse sr = (GenericResponse) HessianUtil.cloneViaClientServerSerialization(r, new EntityResolver());
        assertNotNull(sr);
        assertEquals(2, sr.size());

        assertTrue(sr.next());
        assertFalse(sr.isList());

        int[] srInt = sr.currentUpdateCount();
        assertEquals(3, srInt.length);
        assertEquals(2, srInt[1]);

        assertTrue(sr.next());
        assertTrue(sr.isList());

        assertEquals(list, sr.currentList());

        assertFalse(sr.next());
    }
View Full Code Here

                    relationship.getTargetEntityName(),
                    dbRelationship);

            // null id means that FK is null...
            if (targetId == null) {
                this.response = new GenericResponse(Collections.EMPTY_LIST);
                return DONE;
            }

            DataRow targetRow = cache.getCachedSnapshot(targetId);

            if (targetRow != null) {
                this.response = new GenericResponse(Collections.singletonList(targetRow));
                return DONE;
            }

            // check whether a non-null FK is enough to assume non-null target, and if so,
            // create a fault
            if (context != null
                    && relationship.isSourceDefiningTargetPrecenseAndType(domain
                            .getEntityResolver())) {

                // prevent passing partial snapshots to ObjectResolver per CAY-724.
                // Create a hollow object right here and skip object conversion downstream
                this.noObjectConversion = true;
                Object object = context.findOrCreateObject(targetId);

                this.response = new GenericResponse(Collections.singletonList(object));
                return DONE;
            }
        }

        return !DONE;
View Full Code Here

                if (domain.getSharedSnapshotCache() != null) {
                    domain.getSharedSnapshotCache().clear();
                }
                context.getQueryCache().clear();

                GenericResponse response = new GenericResponse();
                response.addUpdateCount(1);
                this.response = response;
                return DONE;
            }

            Collection<Persistent> objects = (Collection<Persistent>) refreshQuery
                    .getObjects();
            if (objects != null && !objects.isEmpty()) {

                Collection<ObjectId> ids = new ArrayList<ObjectId>(objects.size());
                for (final Persistent object : objects) {
                    ids.add(object.getObjectId());
                }

                if (domain.getSharedSnapshotCache() != null) {
                    // send an event for removed snapshots
                    domain.getSharedSnapshotCache().processSnapshotChanges(
                            context.getObjectStore(),
                            Collections.EMPTY_MAP,
                            Collections.EMPTY_LIST,
                            ids,
                            Collections.EMPTY_LIST);
                }

                GenericResponse response = new GenericResponse();
                response.addUpdateCount(1);
                this.response = response;
                return DONE;
            }

            // 3. refresh query - this shouldn't normally happen as child datacontext
            // usually does a cascading refresh
            if (refreshQuery.getQuery() != null) {
                Query cachedQuery = refreshQuery.getQuery();

                String cacheKey = cachedQuery
                        .getMetaData(context.getEntityResolver())
                        .getCacheKey();
                context.getQueryCache().remove(cacheKey);

                this.response = domain.onQuery(context, cachedQuery);
                return DONE;
            }

            // 4. refresh groups...
            if (refreshQuery.getGroupKeys() != null
                    && refreshQuery.getGroupKeys().length > 0) {

                String[] groups = refreshQuery.getGroupKeys();
                for (String group : groups) {
                    domain.getQueryCache().removeGroup(group);
                }

                GenericResponse response = new GenericResponse();
                response.addUpdateCount(1);
                this.response = response;
                return DONE;
            }
        }
View Full Code Here

        });
    }

    private void runQuery() {
        // reset
        this.fullResponse = new GenericResponse();
        this.response = this.fullResponse;
        this.queriesByNode = null;
        this.queriesByExecutedQueries = null;

        // whether this is null or not will driver further decisions on how to process
View Full Code Here

    @Override
    public QueryResponse performGenericQuery(Query query) {

        query = nonNullDelegate().willPerformGenericQuery(this, query);
        if (query == null) {
            return new GenericResponse();
        }

        if (this.getChannel() == null) {
            throw new CayenneRuntimeException(
                    "Can't run query - parent DataChannel is not set.");
View Full Code Here

    public MockDataChannel(GraphDiff commitResponse) {
        this.commitResponse = commitResponse;
    }

    public MockDataChannel(List selectResponse) {
        this.response = new GenericResponse(selectResponse);
    }
View Full Code Here

        this.resolver = entityResolver;
        this.response = response;
    }

    public MockDataChannel(EntityResolver resolver) {
        this(resolver, new GenericResponse());
    }
View Full Code Here

                        if (arg instanceof BootstrapMessage) {
                            return new EntityResolver();
                        }
                        else {
                            return new GenericResponse(Arrays.asList(inflated));
                        }
                    }
                });

        ClientChannel channel = new ClientChannel(
View Full Code Here

                        if (arg instanceof BootstrapMessage) {
                            return new EntityResolver();
                        }
                        else {
                            return new GenericResponse(Arrays.asList(inflated));
                        }
                    }
                });
        ClientChannel channel = new ClientChannel(
                connection,
View Full Code Here

TOP

Related Classes of org.apache.cayenne.util.GenericResponse

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.