@Override public void write(ObjectDataOutput out, Collection xCollection) throws IOException { super.writeEntity(out, xCollection); out.writeInt(xCollection.getId()); out.writeUTF(xCollection.getName()); out.writeUTF(xCollection.getDocumentType()); out.writeUTF(xCollection.getUriPattern()); out.writeUTF(xCollection.getDescription()); out.writeBoolean(xCollection.isEnabled()); }
private int[] getUriCollections(Schema schema, String uri) { List<Integer> found = new ArrayList<>(); for (Collection collect: schema.getCollections()) { Pattern p = collect.getCompiledPattern(); if (p != null) { found.add(collect.getId()); } } if (found.size() > 0) { int idx = 0; int[] clns = new int[found.size()]; for (Integer id: found) { clns[idx] = id; idx++; } return clns; } return null; }
/** * {@inheritDoc} */ @Override public String toString() { return "Collection [id=" + id + ", name=" + name + ", version=" + getVersion() + ", docType=" + docType + ", uriPattern=" + uriPattern + ", created at=" + getCreatedAt() + ", by=" + getCreatedBy() + ", description=" + description + ", enabled=" + enabled + "]"; }
/** * * @param name the name of schema collection to enable * @param enable the new enable value * @return true if the collection enable flag has been changed, false otherwise */ public boolean enableCollection(String name, boolean enable) { for (Collection collection: collections) { if (name.equals(collection.getName())) { return collection.setEnabled(enable); } } return false; }
public String checkDefaultDocumentCollection(Document doc) { Collection cln = getTypedCollection(repo.getSchema(), doc.getTypeRoot()); logger.trace("checkDefaultDocumentCollection; got collection: {} for typePath: {}", cln, doc.getTypeRoot()); if (cln != null) { doc.addCollection(cln.getId()); return cln.getName(); } return null; }
/** * * @param collectId the XDM collection id * @return true if the schema contains collection with id provided, false otherwise */ public boolean hasCollection(int collectId) { for (Collection collection: collections) { if (collectId == collection.getId()) { return true; } } return false; }
Collection addCollection(String name, String docType, String uriPattern, String description) { Schema schema = getEntity(); int id = 0; for (Collection collect: schema.getCollections()) { if (collect.getId() > id) { id = collect.getId(); } } id++; Collection collection = new Collection(1, new Date(), getCurrentUser(), id, name, docType, uriPattern, description, true); if (schema.addCollection(collection)) { // store schema! flushEntity(schema); return collection; } return null; }
/** * * @param name the name of the collection to search for * @return the XDM collection instance if it is found, null otherwise */ public Collection getCollection(String name) { for (Collection collection: collections) { if (name.equals(collection.getName())) { return collection; } } return null; }
private Collection getTypedCollection(Schema schema, String typePath) { for (Collection collect: schema.getCollections()) { String cPath = collect.getDocumentType(); if (cPath != null && typePath.equals(cPath)) { return collect; } } return null; }
@Override public Collection read(ObjectDataInput in) throws IOException { Object[] entity = super.readEntity(in); Collection xCollection = new Collection( (int) entity[0], (Date) entity[1], (String) entity[2], in.readInt(), in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF(), in.readBoolean()); return xCollection; }
public int updateDocumentCollections(boolean add, Map.Entry<DocumentKey, Document> entry, String[] collections) { int updCount = 0; Document doc = entry.getValue(); if (doc != null) { int size = doc.getElements(); for (Collection cln: repo.getSchema().getCollections()) { for (String collection: collections) { if (collection.equals(cln.getName())) { if (add) { if (doc.addCollection(cln.getId())) { updCount++; updateStats(cln.getName(), true, size, doc.getFragments().length); } } else { if (doc.removeCollection(cln.getId())) { updCount++; updateStats(cln.getName(), false, size, doc.getFragments().length); } } break; } } } if (updCount > 0) { entry.setValue(doc); } } return updCount; }
private int getCollectionId(String uri, String baseUri) { Schema schema = repo.getSchema(); if (baseUri != null && !baseUri.isEmpty() && uri.startsWith(baseUri)) { uri = uri.substring(baseUri.length()); } Collection cln = schema.getCollection(uri); if (cln != null) { return cln.getId(); } logger.info("getCollectionId; no collection found for uri: {}; baseUri: {}, collections: {}", uri, baseUri, schema.getCollections()); return ModelManagementBase.WRONG_PATH; }
/** * * @param name the name of the collection to remove from schema * @return true if collection has been removed, false otherwise */ public Collection removeCollection(String name) { for (Collection collection: collections) { if (name.equals(collection.getName())) { if (collections.remove(collection)) { return collection; } break; } } return null; }
public void cleanDocument(DocumentKey docKey, boolean complete) { logger.trace("cleanDocument.enter; docKey: {}, complete: {}", docKey, complete); Document doc = getDocument(docKey); boolean cleaned = false; if (doc != null) { // TODO: clean via EntryProcessor.. cntCache.delete(docKey); int size = deleteDocumentElements(doc.getFragments(), doc.getTypeRoot()); if (complete) { docCache.delete(docKey); } cleaned = true; // TODO: if xdm-key cache is used it must be cleaned too! // update statistics for (Collection cln: repo.getSchema().getCollections()) { if (doc.hasCollection(cln.getId())) { updateStats(cln.getName(), false, size, doc.getFragments().length); } } updateStats(null, false, size, doc.getFragments().length); } ((QueryManagementImpl) repo.getQueryManagement()).removeQueryResults(docKey.getKey()); logger.trace("cleanDocument.exit; cleaned: {}", cleaned); }
collectId = default_collection; } else { collectId = schema.getCollection(trigger.getCollection()).getId();
@Override public java.util.Collection<String> getCollections() throws BagriException { List<String> clNames = new ArrayList<>(repo.getSchema().getCollections().size()); for (Collection cln: repo.getSchema().getCollections()) { clNames.add(cln.getName()); } return clNames; }
if (clnId == cln.getId()) { updateStats(cln.getName(), false, updated.getElements(), updated.getFragments().length); break; Collection cln = repo.getSchema().getCollection(clName); if (cln != null) { newDoc.addCollection(cln.getId()); updateStats(clName, true, newDoc.getElements(), newDoc.getFragments().length);
return null; return new CollectionPredicate(cln.getId());
@Override public boolean deleteTrigger(TriggerDefinition trigger) { logger.trace("deleteTrigger.enter; git trigger definition: {}", trigger); int cnt = 0; Schema schema = repo.getSchema(); for (TriggerAction action: trigger.getActions()) { String key = getTriggerScopeKey(action.getOrder(), action.getScope()); Map<Integer, List<TriggerContainer>> current = triggers.get(key); if (current == null) { continue; } int collectId = tx_collection; if (!isTransactionalAction(action)) { if (trigger.getCollection() == null) { collectId = default_collection; } else { collectId = schema.getCollection(trigger.getCollection()).getId(); } } List<TriggerContainer> impls = current.get(collectId); if (impls != null) { if (impls.remove(action.getIndex()) != null) { cnt++; } } } logger.trace("deleteTrigger.exit; {} triggers deleted, for collection: {}", cnt, trigger.getCollection()); return cnt > 0; }