Skip to content

Indexing

Fast ACID NoSQL Application Database edited this page Sep 18, 2019 · 4 revisions

on DB4O set Index on Field, not Property.

package com.db4odoc.performance;
import com.db4o.config.annotations.Indexed;
import org.joda.time.DateTime;
import java.util.Date;

public class Item {
    @Indexed
    private final String indexedString;
    @Indexed
    private final int indexNumber;
    @Indexed
    private final Date indexDate;

    public Item(int number) {
        this.indexedString = dataString(number);
        this.indexNumber = number;
        DateTime dt = new DateTime(number);
        this.indexDate = dt.toDate();
    }

    public String getIndexedString() {
        return indexedString;
    }

    public static String dataString(int number){
        return "data for "+number;
    }

    public boolean complexMethod(){
        return indexedString.split("for")[0].contains("5");
    }

    public int getIndexNumber() {
        return indexNumber;
    }

    public Date getIndexDate() {
        return indexDate;
    }
}
//use final to value;
final String criteria = Item.dataString(rnd.nextInt(NUMBER_OF_ITEMS));
final List<Item> result = container.query(new Predicate<Item>() {
   @Override
   public boolean match(Item o) {
     return o.getIndexedString().equals(criteria);
   }
});
//dotn't Computing expression in query
//return o.getIndexedString().equals("data for " + number);
Clone this wiki locally