Examples of PathProperties


Examples of com.avaje.ebean.text.PathProperties

  private SqlTree createRawSqlSqlTree(OrmQueryRequest<?> request, CQueryPredicates predicates) {

    BeanDescriptor<?> descriptor = request.getBeanDescriptor();
    ColumnMapping columnMapping = request.getQuery().getRawSql().getColumnMapping();

    PathProperties pathProps = new PathProperties();

    // convert list of columns into (tree like) PathProperties
    Iterator<Column> it = columnMapping.getColumns();
    while (it.hasNext()) {
      RawSql.ColumnMapping.Column column = it.next();
      String propertyName = column.getPropertyName();
      if (!RawSqlBuilder.IGNORE_COLUMN.equals(propertyName)) {

        ElPropertyValue el = descriptor.getElGetValue(propertyName);
        if (el == null) {
            throw new PersistenceException("Property [" + propertyName + "] not found on " + descriptor.getFullName());
        } else {
          BeanProperty beanProperty = el.getBeanProperty();
          if (beanProperty.isId() || beanProperty.isDiscriminator()) {
            // For @Id properties we chop off the last part of the path
            propertyName = SplitName.parent(propertyName);
          } else if (beanProperty instanceof BeanPropertyAssocOne<?>) {
            String msg = "Column [" + column.getDbColumn() + "] mapped to complex Property[" + propertyName + "]";
            msg += ". It should be mapped to a simple property (proably the Id property). ";
            throw new PersistenceException(msg);
          }
          if (propertyName != null) {
            String[] pathProp = SplitName.split(propertyName);
            pathProps.addToPath(pathProp[0], pathProp[1]);
          }
        }
      }
    }

    OrmQueryDetail detail = new OrmQueryDetail();

    // transfer PathProperties into OrmQueryDetail
    Iterator<String> pathIt = pathProps.getPaths().iterator();
    while (pathIt.hasNext()) {
      String path = pathIt.next();
      Set<String> props = pathProps.get(path);
      detail.getChunk(path, true).setDefaultProperties(null, props);
    }

    // build SqlTree based on OrmQueryDetail of the RawSql
    return new SqlTreeBuilder(request, predicates, detail).build();
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

  @Test
  public void test_parse() {
   
    JsonWriteOptions options = JsonWriteOptions.parsePath("id,status,name");
    PathProperties pathProps = options.getPathProperties();
   
    Assert.assertEquals(1, pathProps.getPaths().size());
    Assert.assertTrue(pathProps.get(null).contains("id"));
    Assert.assertTrue(pathProps.get(null).contains("name"));
    Assert.assertTrue(pathProps.get(null).contains("status"));
    Assert.assertFalse(pathProps.get(null).contains("foo"));
  }
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

  @Test
  public void test_with_depth() {

    JsonWriteOptions options = JsonWriteOptions.parsePath("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
    PathProperties pathProps = options.getPathProperties();

    Assert.assertEquals(5, pathProps.getPaths().size());
    Assert.assertTrue(pathProps.get(null).contains("id"));
    Assert.assertTrue(pathProps.get(null).contains("name"));
    Assert.assertTrue(pathProps.get(null).contains("status"));
    Assert.assertTrue(pathProps.get(null).contains("customer"));
    Assert.assertTrue(pathProps.get(null).contains("orders"));
    Assert.assertFalse(pathProps.get(null).contains("foo"));

    Set<String> customer = pathProps.get("customer");
    Assert.assertTrue(customer.contains("id"));
    Assert.assertTrue(customer.contains("name"));
    Assert.assertTrue(customer.contains("address"));

    Set<String> address = pathProps.get("customer.address");
    Assert.assertTrue(address.contains("street"));
    Assert.assertTrue(address.contains("city"));

    Set<String> orders = pathProps.get("orders");
    Assert.assertTrue(orders.contains("qty"));
    Assert.assertTrue(orders.contains("product"));

    Set<String> product = pathProps.get("orders.product");
    Assert.assertTrue(product.contains("sku"));
    Assert.assertTrue(product.contains("prodName"));

  }
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

  @Test
  public void test_applyPathToQuery() throws IOException {

    ResetBasicData.reset();

    PathProperties pathProperties = PathProperties.parse("(id,status,name,shippingAddress(id,line1,city),billingAddress(*),contacts(*))");

    List<Customer> customers = Ebean.find(Customer.class)
        .apply(pathProperties)
        .findList();

View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

        .desc("id").findList();

    JsonContext json = Ebean.json();

    // test that lazy loading on
    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("Expect lazy loading of Customer beans and customer contacts");
    String s = json.toJson(list, o);
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

        .fetch("contacts").order().desc("id").findList();

    JsonContext json = Ebean.json();

    // test that lazy loading on
    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("expecting lazy load of Customer beans to fetch customer name");
    String s = json.toJson(list, o);
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

        .order().desc("id").findList();

    JsonContext json = Ebean.json();

    // test that lazy loading on
    PathProperties pp = PathProperties.parse("(id,name,contacts(firstName))");
    JsonWriteOptions o = new JsonWriteOptions();
    o.setPathProperties(pp);

    System.out.println("expecting lazy load of Customer contacts ");
    String s = json.toJson(list, o);
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

  public void test_push() throws IOException {

    JsonFactory jsonFactory = new JsonFactory();
    JsonGenerator generator = jsonFactory.createGenerator(new StringWriter());

    PathProperties pathProperties = PathProperties.parse("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
    WriteJson writeJson = new WriteJson(null, generator, pathProperties);

    WriteJson.WriteBean rootLevel = writeJson.createWriteBean(null, null);
    assertTrue(rootLevel.currentIncludeProps.contains("id"));
    assertTrue(rootLevel.currentIncludeProps.contains("status"));
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

    synchronized (monitor) {
      if (nodeUsageMap.isEmpty()){
          return null;
      }
       
      PathProperties pathProps = new PathProperties();
     
      Iterator<StatisticsNodeUsage> it = nodeUsageMap.values().iterator();
      while (it.hasNext()) {
        StatisticsNodeUsage statsNode = it.next();
        statsNode.buildTunedFetch(pathProps, rootDesc);
      }

          OrmQueryDetail detail = new OrmQueryDetail();

      Collection<Props> pathProperties = pathProps.getPathProps();
      for (Props props : pathProperties) {
          if (!props.isEmpty()){
              detail.addFetch(props.getPath(), props.getPropertiesAsString(), null);
          }
            }
View Full Code Here

Examples of com.avaje.ebean.text.PathProperties

      d.jsonWrite(writeJson, (EntityBean)o, null);
    }
  }

  private WriteJson createWriteJson(JsonGenerator gen, JsonWriteOptions options) {
    PathProperties pathProps = (options == null) ? null : options.getPathProperties();
    return new WriteJson(server, gen, pathProps);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.