@Override public KeyType getKeyType() { return new UUIDKeyType(); }
private List<IndexField> guaranteeIdKey(IndexField... valueFields) throws JasDBStorageException { Set<String> fields = new HashSet<>(); List<IndexField> indexFields = new ArrayList<>(); for(IndexField valueField : valueFields) { fields.add(valueField.getField()); indexFields.add(valueField); } if(!fields.contains(SimpleEntity.DOCUMENT_ID)) { indexFields.add(new SimpleIndexField(SimpleEntity.DOCUMENT_ID, new UUIDKeyType())); } return indexFields; }
@Override public Index createIndex(String bagName, IndexField indexField, boolean unique, IndexField... valueFields) throws JasDBStorageException { KeyInfo keyInfo; if(unique) { keyInfo = new KeyInfoImpl(indexField, guaranteeIdKey(valueFields)); } else { keyInfo = new KeyInfoImpl(Lists.newArrayList(indexField, new SimpleIndexField(SimpleEntity.DOCUMENT_ID, new UUIDKeyType())), Lists.newArrayList(valueFields)); } return createInStore(bagName, keyInfo); }
@Override public Index createIndex(String bagName, CompositeIndexField compositeIndexFields, boolean unique, IndexField... values) throws JasDBStorageException { KeyInfo keyInfo; if(unique) { keyInfo = new KeyInfoImpl(compositeIndexFields.getIndexFields(), guaranteeIdKey(values)); } else { List<IndexField> indexFields = Lists.newArrayList(compositeIndexFields.getIndexFields()); indexFields.add(new SimpleIndexField(SimpleEntity.DOCUMENT_ID, new UUIDKeyType())); keyInfo = new KeyInfoImpl(indexFields, Lists.newArrayList(values)); } return createInStore(bagName, keyInfo); }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("RECORD_POINTER", new LongKeyType())); this.index = new BTreeIndex(indexLocation, keyInfo); this.writer.openWriter(); this.index.openIndex(); }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("data", new DataKeyType())); try { this.index = new BTreeIndex(recordStorageLocation, keyInfo); this.index.openIndex(); } catch(OverlappingFileLockException e) { throw new RecordStoreInUseException("Record datastore: " + recordStorageLocation + " is already in use, cannot be opened"); } }