public MapperBuilder matchBy(Property<?>... paths) { Objects.requireNonNull(paths, "Null 'paths'"); for (Property<?> p : paths) { this.paths.add(p.getName()); } return this; }
/** * @return Ascending sort orderings on this property. */ public List<Ordering> ascs() { List<Ordering> result = new ArrayList<>(1); result.add(asc()); return result; }
/** * @return Descending sort orderings on this property. */ public List<Ordering> descs() { List<Ordering> result = new ArrayList<>(1); result.add(desc()); return result; }
/** * Creates alias with different name for this property */ public Property<E> alias(String alias) { return new Property<>(alias, this.getExpression(), this.getType()); }
@Test public void test_Select_RelationshipStartLimit() throws UnsupportedEncodingException { Response response = target("/e2_RelationshipStartLimit") .queryParam("include", "id") .queryParam("include", URLEncoder.encode("{\"path\":\"" + E2.E3S.getName() + "\",\"start\":1,\"limit\":1}", "UTF-8")) .queryParam("exclude", E2.E3S.dot(E3.PHONE_NUMBER).getName()) .request().get(); assertNotNull(response); }
/** * @return alias for this property */ public String getAlias() { if(getName() == null) { return null; } // check if default name for Path expression is overridden Expression exp = getExpression(); if(exp instanceof ASTPath) { if(((ASTPath) exp).getPath().equals(getName())) { return null; } } return getName(); }
@Test public void testBuildQuery_Ordering() { Ordering o1 = E1.NAME.asc(); Ordering o2 = E1.NAME.desc(); SelectQuery<E1> query = new SelectQuery<E1>(E1.class); query.addOrdering(o1); ResourceEntity<E1> resourceEntity = getResourceEntity(E1.class); resourceEntity.getOrderings().add(o2); SelectContext<E1> context = new SelectContext<E1>(E1.class); context.setSelect(query); context.setEntity(resourceEntity); SelectQuery<E1> amended = makeQueryStage.buildQuery(context); assertSame(query, amended); assertEquals(2, amended.getOrderings().size()); assertSame(o1, amended.getOrderings().get(0)); assertSame(o2, amended.getOrderings().get(1)); }
/** * Creates property with name and type * @see Property#create(Expression, Class) * @see Property#create(String, Expression, Class) */ public static <T> Property<T> create(String name, Class<? super T> type) { return new Property<>(name, type); }
/** * <p>Select average value of property</p> * @see ColumnSelect#columns(Property, Property[]) */ public ColumnSelect<Object[]> avg(Property<?> property) { return columns(property.avg()); }
/** * @return Ascending case insensitive sort orderings on this property. */ public List<Ordering> ascInsensitives() { List<Ordering> result = new ArrayList<>(1); result.add(ascInsensitive()); return result; }
@Test public void testPut_ToMany() { insert("e2", "id, name", "1, 'xxx'"); insert("e2", "id, name", "8, 'yyy'"); insert("e3", "id, name, e2_id", "3, 'zzz', null"); insert("e3", "id, name, e2_id", "4, 'aaa', 8"); insert("e3", "id, name, e2_id", "5, 'bbb', 8"); Response response = target("/e2/1") .queryParam("include", E2.E3S.getName()) .queryParam("exclude", E2.ADDRESS.getName(), E2.NAME.getName(), E2.E3S.dot(E3.NAME).getName(), E2.E3S.dot(E3.PHONE_NUMBER).getName()) .request().put(Entity.json("{\"e3s\":[3,4,5]}")); onSuccess(response).bodyEquals(1, "{\"id\":1,\"e3s\":[{\"id\":3},{\"id\":4},{\"id\":5}]}"); assertEquals(3L, countRows("e3", "WHERE e2_id = 1")); }
/** * Creates property with name, expression and type * @see Property#create(String, Class) * @see Property#create(Expression, Class) */ public static <T> Property<T> create(String name, Expression expression, Class<? super T> type) { return new Property<>(name, expression, type); }
/** * <p>Select average value of property</p> * @see ObjectSelect#column(Property) */ public <E> ColumnSelect<E> avg(Property<E> property) { return column(property.avg()); }
/** * 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); }
@Test public void testPut_ToMany_UnrelateAll() { insert("e2", "id, name", "1, 'xxx'"); insert("e2", "id, name", "8, 'yyy'"); insert("e3", "id, name, e2_id", "3, 'zzz', null"); insert("e3", "id, name, e2_id", "4, 'aaa', 8"); insert("e3", "id, name, e2_id", "5, 'bbb', 8"); Response response = target("/e2/8") .queryParam("include", E2.E3S.getName()) .queryParam("exclude", E2.ADDRESS.getName(), E2.NAME.getName(), E2.E3S.dot(E3.NAME).getName(), E2.E3S.dot(E3.PHONE_NUMBER).getName()) .request().put(Entity.json("{\"e3s\":[]}")); onSuccess(response).bodyEquals(1, "{\"id\":8,\"e3s\":[]}"); assertEquals(3, countRows("e3", "WHERE e2_id IS NULL")); }
/** * Creates property with expression and type * @see Property#create(String, Class) * @see Property#create(String, Expression, Class) */ public static <T> Property<T> create(Expression expression, Class<? super T> type) { return new Property<>(null, expression, type); }
/** * 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); }
@Test public void testPut_ToMany_UnrelateOne() { insert("e2", "id, name", "1, 'xxx'"); insert("e2", "id, name", "8, 'yyy'"); insert("e3", "id, name, e2_id", "3, 'zzz', null"); insert("e3", "id, name, e2_id", "4, 'aaa', 8"); insert("e3", "id, name, e2_id", "5, 'bbb', 8"); Response response = target("/e2/1") .queryParam("include", E2.E3S.getName()) .queryParam("exclude", E2.ADDRESS.getName(), E2.NAME.getName(), E2.E3S.dot(E3.NAME).getName(), E2.E3S.dot(E3.PHONE_NUMBER).getName()) .request() .put(Entity.json("{\"e3s\":[4]}")); onSuccess(response).bodyEquals(1, "{\"id\":1,\"e3s\":[{\"id\":4}]}"); assertEquals(1L, countRows("e3", "WHERE e2_id = 1 AND id = 4")); assertEquals(1L, countRows("e3", "WHERE e2_id = 8 AND id = 5")); }