1 8 9 package com.sleepycat.collections; 10 11 import java.util.Set ; 12 13 import com.sleepycat.bind.EntityBinding; 14 import com.sleepycat.bind.EntryBinding; 15 import com.sleepycat.je.Database; 16 import com.sleepycat.je.DatabaseEntry; 17 import com.sleepycat.je.DatabaseException; 18 import com.sleepycat.je.OperationStatus; 19 20 28 public class StoredValueSet extends StoredCollection implements Set { 29 30 33 34 51 public StoredValueSet(Database database, 52 EntryBinding valueBinding, 53 boolean writeAllowed) { 54 55 super(new DataView(database, null, valueBinding, null, 56 writeAllowed, null)); 57 } 58 59 76 public StoredValueSet(Database database, 77 EntityBinding valueEntityBinding, 78 boolean writeAllowed) { 79 80 super(new DataView(database, null, null, valueEntityBinding, 81 writeAllowed, null)); 82 } 83 84 StoredValueSet(DataView valueSetView) { 85 86 super(valueSetView); 87 } 88 89 105 public boolean add(Object entity) { 106 107 if (view.isSecondary()) { 108 throw new UnsupportedOperationException ( 109 "add() not allowed with index"); 110 } else if (view.range.isSingleKey()) { 111 112 if (!view.dupsAllowed) { 113 throw new UnsupportedOperationException ("duplicates required"); 114 } 115 DataCursor cursor = null; 116 boolean doAutoCommit = beginAutoCommit(); 117 try { 118 cursor = new DataCursor(view, true); 119 cursor.useRangeKey(); 120 OperationStatus status = 121 cursor.putNoDupData(null, entity, null, true); 122 closeCursor(cursor); 123 commitAutoCommit(doAutoCommit); 124 return (status == OperationStatus.SUCCESS); 125 } catch (Exception e) { 126 closeCursor(cursor); 127 throw handleException(e, doAutoCommit); 128 } 129 } else if (view.entityBinding == null) { 130 throw new UnsupportedOperationException ( 131 "add() requires entity binding"); 132 } else { 133 return add(null, entity); 134 } 135 } 136 137 146 public boolean contains(Object value) { 147 148 return containsValue(value); 149 } 150 151 164 public boolean remove(Object value) { 165 166 return removeValue(value); 167 } 168 169 Object makeIteratorData(BaseIterator iterator, 170 DatabaseEntry keyEntry, 171 DatabaseEntry priKeyEntry, 172 DatabaseEntry valueEntry) { 173 174 return view.makeValue(priKeyEntry, valueEntry); 175 } 176 177 boolean hasValues() { 178 179 return true; 180 } 181 } 182 | Popular Tags |