/** * Returns a prefetch tree that follows this property path, potentially * spanning a number of phantom nodes, and having a single leaf with * "disjoint" prefetch semantics. */ public PrefetchTreeNode disjoint() { return PrefetchTreeNode.withPath(getName(), PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); }
/** * Returns a prefetch tree that follows this property path, potentially * spanning a number of phantom nodes, and having a single leaf with "joint" * prefetch semantics. */ public PrefetchTreeNode joint() { return PrefetchTreeNode.withPath(getName(), PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS); }
/** * @since 1.2 */ @Override public SimpleResponse unrelate(Class<?> type, Object sourceId, Property<?> relationship, Object targetId) { return unrelate(type, sourceId, relationship.getName(), targetId); }
/** * Constructs a property path by appending the argument to the existing property separated by a dot. * * @return a newly created Property object. */ public Property<Object> dot(String property) { return create(getName() + "." + property, null); }
@Override public SelectBuilder<T> toManyParent(Class<?> parentType, Map<String, Object> parentIds, Property<? extends Collection<T>> relationshipFromParent) { return parent(parentType, parentIds, relationshipFromParent.getName()); }
/** * @since 1.2 */ @Override public SimpleResponse unrelate(Class<?> type, Object sourceId, Property<?> relationship) { return unrelate(type, sourceId, relationship.getName()); }
/** * Excludes an attribute or relationship. * * @param attributeOrRelationship a name of the property to exclude. * @return a new instance of Constraints. */ public ConstraintsBuilder<T> excludeProperty(Property<?> attributeOrRelationship) { return excludeProperty(attributeOrRelationship.getName()); }
@Override public UpdateBuilder<T> toManyParent(Class<?> parentType, Object parentId, Property<? extends Collection<T>> relationshipFromParent) { return parent(parentType, parentId, relationshipFromParent.getName()); }
/** * Returns a prefetch tree that follows this property path, potentially * spanning a number of phantom nodes, and having a single leaf with * "disjoint by id" prefetch semantics. */ public PrefetchTreeNode disjointById() { return PrefetchTreeNode.withPath(getName(), PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS); }
@Override public SelectBuilder<T> parent(Class<?> parentType, Map<String, Object> parentIds, Property<T> relationshipFromParent) { context.setParent(new EntityParent<>(parentType, parentIds, relationshipFromParent.getName())); return this; }
@Override public UpdateBuilder<T> parent(Class<?> parentType, Object parentId, Property<T> relationshipFromParent) { context.setParent(new EntityParent<>(parentType, parentId, relationshipFromParent.getName())); return this; }
@Override public UpdateBuilder<T> parent(Class<?> parentType, Map<String, Object> parentIds, Property<T> relationshipFromParent) { context.setParent(new EntityParent<>(parentType, parentIds, relationshipFromParent.getName())); return this; }
public static <T> Consumer<SelectContext<T>> startsWithFilter(Property<?> property, String value) { return c -> StartsWithFilter .getInstance() .filter(c, property.getName(), value) .ifPresent(exp -> processStartsWith(c, exp)); }
@Test public void testPost_Bulk() { Response r2 = target("/e3/").queryParam("exclude", "id").queryParam("include", E3.NAME.getName()).request() .post(Entity.json("[{\"name\":\"aaa\"},{\"name\":\"zzz\"},{\"name\":\"bbb\"},{\"name\":\"yyy\"}]")); assertEquals(Status.CREATED.getStatusCode(), r2.getStatus()); // ordering must be preserved... assertEquals( "{\"data\":[{\"name\":\"aaa\"},{\"name\":\"zzz\"},{\"name\":\"bbb\"},{\"name\":\"yyy\"}],\"total\":4}", r2.readEntity(String.class)); }
@GET @Path("e17/e18s") public DataResponse<E18> getChildren( @Context UriInfo uriInfo, @MatrixParam("parentId1") Integer parentId1, @MatrixParam("parentId2") Integer parentId2) { Map<String, Object> parentIds = new HashMap<>(); parentIds.put(E17.ID1_PK_COLUMN, parentId1); parentIds.put(E17.ID2_PK_COLUMN, parentId2); return Ag.select(E18.class, config).parent(E17.class, parentIds, E17.E18S.getName()).uri(uriInfo).get(); } }
@Test public void testDateTime() { Date date = Date.from(Instant.from(UtcDateConverter.dateParser().fromString("2012-02-03T11:01:02Z"))); SQLTemplate insert = new SQLTemplate(E4.class, "INSERT INTO utest.e4 (c_timestamp) values (#bind($ts 'TIMESTAMP'))"); insert.setParams(Collections.singletonMap("ts", date)); newContext().performGenericQuery(insert); String dateString = DateTimeFormatters.isoLocalDateTime().format(Instant.ofEpochMilli(date.getTime())); Response response = target("/e4").queryParam("include", E4.C_TIMESTAMP.getName()).request().get(); onSuccess(response).bodyEquals(1, "{\"cTimestamp\":\"" + dateString + "\"}"); }
@Test public void test_SelectByteArrayProperty() throws IOException { ObjectContext ctx = newContext(); E19 e19 = ctx.newObject(E19.class); e19.setGuid("someValue123".getBytes("UTF-8")); ctx.commitChanges(); Response response = target("/e19/" + Cayenne.intPKForObject(e19)) .queryParam("include", E19.GUID.getName()) .request() .get(); onSuccess(response).bodyEquals(1, "{\"guid\":\"c29tZVZhbHVlMTIz\"}"); }
@GET @Path("e4_mapBy") public DataResponse<E4> getE4_mapBy(@Context UriInfo uriInfo) { MapBy mapBy = new MapBy(E4.C_VARCHAR.getName()); AgRequest agRequest = AgRequest.builder().mapBy(mapBy).build(); return Ag.service(config).select(E4.class) .uri(uriInfo) .request(agRequest) // overrides parameters from uriInfo .get(); } }
@Test public void testConstrainResponse_Default() { ResourceEntity<E1> te1 = new ResourceEntity<>(age1); appendAttribute(te1, E1.AGE, Integer.class); appendAttribute(te1, E1.DESCRIPTION, String.class); constraintHandler.constrainResponse(te1, null, null); assertEquals(1, te1.getAttributes().size()); assertTrue(te1.getAttributes().containsKey(E1.AGE.getName())); assertTrue(te1.getChildren().isEmpty()); }
@Test public void testToDataRequest_IncludeObject_Path() { SelectContext<E2> context = new SelectContext<>(E2.class); Include include = new Include("e3s"); context.setRawRequest(AgRequest.builder().includes(Collections.singletonList(include)).build()); createEntityStage.execute(context); ResourceEntity<E2> resourceEntity = context.getEntity(); assertNotNull(resourceEntity); assertTrue(resourceEntity.isIdIncluded()); assertEquals(1, resourceEntity.getChildren().size()); assertTrue(resourceEntity.getChildren().containsKey(E2.E3S.getName())); }