use of org.eclipse.ecf.storage.IIDEntry in project ecf by eclipse.
the class NamespaceEntry method getIDEntries.
/* (non-Javadoc)
* @see org.eclipse.ecf.storage.INamespaceEntry#getIDEntries()
*/
public IIDEntry[] getIDEntries() {
String[] names = prefs.childrenNames();
List results = new ArrayList();
for (int i = 0; i < names.length; i++) results.add(new IDEntry(prefs.node(names[i])));
return (IIDEntry[]) results.toArray(new IIDEntry[] {});
}
use of org.eclipse.ecf.storage.IIDEntry in project ecf by eclipse.
the class IDStoreTest method testGetLongIDEntries.
public void testGetLongIDEntries() throws Exception {
final ID newLongID = IDFactory.getDefault().createLongID(1);
idStore.store(newLongID);
// Get namespace entry
final INamespaceEntry namespaceEntry = idStore.getNamespaceEntry(newLongID.getNamespace());
assertNotNull(namespaceEntry);
final IIDEntry[] idEntries = namespaceEntry.getIDEntries();
assertTrue(idEntries.length == 1);
// Create LongID from idEntry
final ID persistedLongID = idEntries[0].createID();
assertNotNull(persistedLongID);
assertTrue(persistedLongID.equals(newLongID));
}
use of org.eclipse.ecf.storage.IIDEntry in project ecf by eclipse.
the class IDStoreTest method testCreateAssociation.
public void testCreateAssociation() throws Exception {
// Create two GUIDs and store them in idStore
final ID guid1 = IDFactory.getDefault().createGUID();
final IIDEntry entry1 = idStore.store(guid1);
final ID guid2 = IDFactory.getDefault().createGUID();
final IIDEntry entry2 = idStore.store(guid2);
final String key = "foo";
// Create association
entry1.putAssociate(key, entry2, true);
// Get entry1a
final IIDEntry entry1a = idStore.store(guid1);
assertNotNull(entry1a);
// Get associates (should include entry2)
final IIDEntry[] entries = entry1a.getAssociates(key);
assertNotNull(entries);
assertTrue(entries.length == 1);
// entry2a should be same as entry2
final IIDEntry entry2a = entries[0];
assertNotNull(entry2a);
final ID guid2a = entry2a.createID();
// and guid2a should equal guid2
assertTrue(guid2.equals(guid2a));
}
use of org.eclipse.ecf.storage.IIDEntry in project ecf by eclipse.
the class IDStoreTest method testCreateAssociations.
public void testCreateAssociations() throws Exception {
// Create two GUIDs and store them in idStore
final ID guid1 = IDFactory.getDefault().createGUID();
final IIDEntry entry1 = idStore.store(guid1);
final ID guid2 = IDFactory.getDefault().createGUID();
final IIDEntry entry2 = idStore.store(guid2);
final ID guid3 = IDFactory.getDefault().createGUID();
final IIDEntry entry3 = idStore.store(guid3);
final ID guid4 = IDFactory.getDefault().createGUID();
final IIDEntry entry4 = idStore.store(guid4);
final String key1 = "foo";
final String key2 = "foo2";
// Create association
entry1.putAssociate(key1, entry2, true);
// Create another association with same key (key1)
entry1.putAssociate(key1, entry3, false);
// Create another association with different key (key2)
entry1.putAssociate(key2, entry4, true);
// Get entry1a
final IIDEntry entry1a = idStore.store(guid1);
assertNotNull(entry1a);
final ID guid1a = entry1a.createID();
assertTrue(guid1.equals(guid1a));
// Get associates (should include entry2)
final IIDEntry[] entries1 = entry1a.getAssociates(key1);
assertNotNull(entries1);
assertTrue(entries1.length == 2);
// entry2a should be same as entry2
final IIDEntry entry2a = entries1[0];
assertNotNull(entry2a);
final ID guid2a = entry2a.createID();
// entry3a should be same as entry3
final IIDEntry entry3a = entries1[1];
assertNotNull(entry3a);
final ID guid3a = entry3a.createID();
// Since the order can be turned around, 2a can equal 2 or 3
assertTrue(guid2.equals(guid2a) && guid3.equals(guid3a));
final IIDEntry[] entries2 = entry1a.getAssociates(key2);
assertNotNull(entries2);
assertTrue(entries2.length == 1);
// entry4a should be same as entry4
final IIDEntry entry4a = entries2[0];
assertNotNull(entry4a);
final ID guid4a = entry4a.createID();
// and guid4a should equal guid4
assertTrue(guid4.equals(guid4a));
}
use of org.eclipse.ecf.storage.IIDEntry in project ecf by eclipse.
the class IDEntry method getAssociates.
public IIDEntry[] getAssociates(String key) {
if (key == null)
return new IIDEntry[0];
ISecurePreferences associateNode = prefs.node(key);
String[] childrenNames = associateNode.childrenNames();
SortedMap results = new TreeMap();
for (int i = 0; i < childrenNames.length; i++) {
addAssociateFromName(childrenNames[i], results);
}
return (IIDEntry[]) results.values().toArray(new IIDEntry[] {});
}
Aggregations