1 21 package com.db4o.db4ounit.jre12.fieldindex; 22 23 import java.util.*; 24 25 import com.db4o.ObjectSet; 26 import com.db4o.config.*; 27 import com.db4o.query.Query; 28 29 import db4ounit.Assert; 30 import db4ounit.extensions.AbstractDb4oTestCase; 31 32 35 public class CollectionFieldIndexTestCase extends AbstractDb4oTestCase { 36 37 public static void main(String [] args) { 38 new CollectionFieldIndexTestCase().runSolo(); 39 } 40 41 private static class Item { 42 private String _name; 43 44 public Item(String name) { 45 _name = name; 46 } 47 48 public String getName() { 49 return _name; 50 } 51 } 52 53 private static class UntypedContainer { 54 private Object _set = new HashSet(); 55 56 public UntypedContainer(Object item) { 57 ((Set)_set).add(item); 58 } 59 60 public Iterator iterator() { 61 return ((Set)_set).iterator(); 62 } 63 } 64 65 protected void configure(Configuration config) { 66 indexField(config,Item.class, "_name"); 67 indexField(config,UntypedContainer.class, "_set"); 68 } 69 70 protected void store() throws Exception { 71 db().set(new UntypedContainer(new Item("foo"))); 72 db().set(new UntypedContainer(new Item("bar"))); 73 } 74 75 public void testUntypedContainer() { 76 final Query q = db().query(); 77 q.constrain(UntypedContainer.class); 78 q.descend("_set").descend("_name").constrain("foo"); 79 80 final ObjectSet result = q.execute(); 81 Assert.areEqual(1, result.size()); 82 83 final UntypedContainer container = (UntypedContainer)result.next(); 84 final Item item = (Item)container.iterator().next(); 85 Assert.areEqual("foo", item.getName()); 86 } 87 88 } 89 | Popular Tags |