Example #1
0
  @Test
  public void BeanClassOfTExpressionOfQArray() {
    PathBuilder<Entity> entity = new PathBuilder<Entity>(Entity.class, "entity");
    QBean<Entity> beanProjection =
        Projections.bean(
            Entity.class,
            entity.getNumber("cId", Integer.class),
            entity.getNumber("eId", Integer.class));

    assertEquals(Entity.class, beanProjection.newInstance(1, 2).getClass());
  }
  @Before
  public void setUp() throws Exception {
    serializer = new LuceneSerializer(true, true);
    entityPath = new PathBuilder<Object>(Object.class, "obj");
    title = entityPath.getString("title");
    author = entityPath.getString("author");
    text = entityPath.getString("text");
    publisher = entityPath.getString("publisher");
    year = entityPath.getNumber("year", Integer.class);
    rating = entityPath.getString("rating");
    gross = entityPath.getNumber("gross", Double.class);

    longField = entityPath.getNumber("longField", Long.class);
    shortField = entityPath.getNumber("shortField", Short.class);
    byteField = entityPath.getNumber("byteField", Byte.class);
    floatField = entityPath.getNumber("floatField", Float.class);

    idx = new RAMDirectory();
    config =
        new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30))
            .setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    writer = new IndexWriter(idx, config);

    writer.addDocument(createDocument());

    writer.close();

    IndexReader reader = IndexReader.open(idx);
    searcher = new IndexSearcher(reader);
  }
 /**
  * If filter is number its required to know its concrete class so this private helper method
  * creates and returns predicate based on concrete class.
  */
 @SuppressWarnings({"unchecked", "rawtypes"})
 private NumberPath createNumberPath(PathBuilder entityPath, String key, Object filter) {
   if (filter instanceof BigDecimal) {
     return entityPath.getNumber(key, BigDecimal.class);
   } else if (filter instanceof Long) {
     return entityPath.getNumber(key, Long.class);
   } else if (filter instanceof Integer) {
     return entityPath.getNumber(key, Integer.class);
   } else if (filter instanceof Double) {
     return entityPath.getNumber(key, Double.class);
   } else if (filter instanceof Float) {
     return entityPath.getNumber(key, Float.class);
   } else if (filter instanceof Byte) {
     return entityPath.getNumber(key, Byte.class);
   } else if (filter instanceof Short) {
     return entityPath.getNumber(key, Short.class);
   } else {
     throw new IllegalStateException(
         "Unknown number type in search filter. Supported type: BigDecimal, Long, Integer, Double, Float, Byte, Short");
   }
 }