Java objectdb中的查询

Java objectdb中的查询,java,sql,database,objectdb,Java,Sql,Database,Objectdb,我必须在objectdb中实现一个查询,但我对此知之甚少 问题是要编写一个查询 Returns the collection of all laptops each of which has at least one other laptop preinstalled with the same processor. 我的笔记本电脑课是 public class Laptop { String modelName; // key int price;

我必须在objectdb中实现一个查询,但我对此知之甚少

问题是要编写一个查询

Returns the collection of all laptops each of which has at least one
          other laptop preinstalled with the same processor.
我的笔记本电脑课是

public class Laptop {

    String modelName; // key
    int price;        // in dollars
    boolean hasHDScreen; // has a HD Screen ?
    int hardDriveCapacity; // in GB

    Processor processor;  // the preinstalled processor
    Memory memory; // the preinstalled memory
    Company madeBy; // the inverse of company.makeLaptops
}
我的处理器类是

public class Processor {

    String modelName; // key 
    float clockSpeed; // in gigahertz (GHz)

    Company madeBy; // the inverse of Company.makeProcessors
}   
我的函数定义如下所示

public static Collection<Laptop> sameProcessor(Query q) {
        /* Returns the collection of all laptops each of which has at least one
         * other laptop preinstalled with the same processor.
         */
        q.setClass(Laptop.class);
        q.setFilter("this.processor == ");

    } 
publicstaticcollectionsameprocessor(查询q){
/*返回至少有一台笔记本电脑的所有笔记本电脑的集合
*其他预装有相同处理器的笔记本电脑。
*/
q、 setClass(Laptop.class);
q、 setFilter(“this.processor==”;
} 
我怎样才能做到呢?SQL也可以


谢谢

终于克服了这一点。这是解决办法

public static Collection<Laptop> sameProcessor(Query q) {
        /* Returns the collection of all laptops each of which has at least one
         * other laptop preinstalled with the same processor.
         */

        Collection result = new HashSet<Laptop>();
        q.setClass(Laptop.class);

        Collection allLaptops = (Collection) q.execute();

        Iterator it = allLaptops.iterator();

        while(it.hasNext()) {
            Laptop currentLaptop = ((Laptop)it.next());
            Processor p = currentLaptop.processor;
            if(p.installedOn(q).size()>=2) {

                result.add(currentLaptop);
            }
        }

        return (Collection<Laptop>)result;       
    } 

谢谢。希望能有所帮助。

@ant:但在hibernate中进行查询也很方便。因为我可以尝试将其转换为JAVA,从而转换为ObjectDb查询语言
public Collection<Laptop> installedOn(Query q) {

     /* Returns the collection of all laptops on which the target memory 
        is preinstalled. Represents the inverse of Laptop.memory.
     */
        Memory memory = this;
        q.setClass(Laptop.class);
        q.declareParameters("Memory m");
        q.setFilter("this.memory == m");
        Collection result = (Collection)q.execute(memory);
        return (Collection<Laptop>) result;

    }