/** * Test a collection of Entity object for the specified entity reference * * @param entities * The collection (Entity) of entities * @param entityRef * The string entity reference to find. * @return true if found, false if not. */ public static boolean entityCollectionContainsRefString(Collection<Entity> entities, String entityRef) { for (Iterator<Entity> i = entities.iterator(); i.hasNext();) { Entity entity = i.next(); if (entity.getReference().equals(entityRef)) return true; } return false; }
/** * Set the refs collection to the entity reference strings from the entities collection (and nothing more) * * @param refs * The collection (String) of entity references to modify. * @param entities * The collection (Entity) of entity objects to use. */ public static void setEntityRefsFromEntities(Collection<String> refs, Collection<Entity> entities) { refs.clear(); for (Iterator<Entity> i = entities.iterator(); i.hasNext();) { Entity entity = i.next(); refs.add(entity.getReference()); } }
/** * Test a collection of Entity reference Strings for the specified Entity * * @param refs * The collection (String) of entity refs * @param entity * The Entity to find. * @return true if found, false if not. */ public static boolean refCollectionContainsEntity(Collection<String> refs, Entity entity) { String targetRef = entity.getReference(); for (Iterator<String> i = refs.iterator(); i.hasNext();) { String entityRef = i.next(); if (entityRef.equals(targetRef)) return true; } return false; }
public void unlockGroup(Entity entity) { unlockGroup(entity.getReference()); }
public void lockGroup(Entity entity) { lockGroup(entity.getReference()); }
/** * See if the collection of entity reference strings has at least one entity that is in the collection of Entity objects. * * @param entityRefs * The collection (String) of entity references. * @param entities * The collection (Entity) of entity objects. * @return true if there is interesection, false if not. */ public static boolean isIntersectionEntityRefsToEntities(Collection<String> entityRefs, Collection<Entity> entities) { for (Iterator<String> iRefs = entityRefs.iterator(); iRefs.hasNext();) { String findThisEntityRef = iRefs.next(); for (Iterator<Entity> iEntities = entities.iterator(); iEntities.hasNext();) { String thisEntityRef = ((Entity) iEntities.next()).getReference(); if (thisEntityRef.equals(findThisEntityRef)) { return true; } } } return false; }
String ref = r.getReference(); if (ref.startsWith(context))
/** * Return a lock on the entry with this id, or null if a lock cannot be made. * * @param container * The container id. * @param id * The id. * @return The locked object with this id, or null if a lock cannot be made. */ public Edit editResource(String container, String id) { if (container == null) container = ""; Container c = ((Container) m_store.get(container)); if (c == null) return null; Entity entry = (Entity) c.contained.get(caseId(id)); if (entry == null) return null; synchronized (m_locks) { // check for a lock in place if (m_locks.get(entry.getReference()) != null) return null; // make an Edit Edit edit = m_user.newResourceEdit(c.container, entry); // store it in the locks m_locks.put(entry.getReference(), edit); return edit; } }
String findThisEntityRef = iEntities.next().getReference(); if(!entityRefs.contains(findThisEntityRef)) { return false;
/** * Count all Resources * @param container * The container for this resource. */ public int getCount(Entity container) { // read With or without a filter String sql = doubleStorageSql.getCountSql(m_resourceTableName, m_resourceTableContainerIdField); Object[] fields = new Object[1]; fields[0] = container.getReference(); List countList = m_sql.dbRead(sql, fields, null); if ( countList.isEmpty() ) return 0; Object obj = countList.get(0); String str = (String) obj; return Integer.parseInt(str); }
/** * Count all Resources * @param container * The container for this resource. */ public int getCount(Entity container) { // read With or without a filter String sql = doubleStorageSql.getCountSql(m_resourceTableName, m_resourceTableContainerIdField); Object[] fields = new Object[1]; fields[0] = container.getReference(); List countList = m_sql.dbRead(sql, fields, null); if ( countList.isEmpty() ) return 0; Object obj = countList.get(0); String str = (String) obj; return Integer.parseInt(str); }
/** * Fill in the two collections of Entity reference strings - those added in newEntities that were not in oldEntityRefs, and those removed, i.e. in oldEntityRefs not in newEntities. */ public static void computeAddedRemovedEntityRefsFromNewEntitiesOldRefs(Collection<String> addedEntities, Collection<String> removedEntities, Collection<Entity> newEntities, Collection<String> oldEntityRefs) { // added for (Iterator<Entity> i = newEntities.iterator(); i.hasNext();) { Entity entity = i.next(); if (!refCollectionContainsEntity(oldEntityRefs, entity)) { addedEntities.add(entity.getReference()); } } // removed for (Iterator<String> i = oldEntityRefs.iterator(); i.hasNext();) { String entityRef = i.next(); if (!entityCollectionContainsRefString(newEntities, entityRef)) { removedEntities.add(entityRef); } } } }
/** * {@inheritDoc} * * @param rwo * @return */ public Reference getReference(RWikiObject rwo) { return entityManager.newReference(getEntity(rwo).getReference()); }
/** * Return a lock on the container with this id, or null if a lock cannot be made. * * @param ref * The container reference. * @return The locked object with this id, or null if a lock cannot be made. */ public Edit editContainer(String ref) { Container c = (Container) m_store.get(ref); if (c == null) return null; synchronized (m_locks) { // check for a lock in place if (m_locks.get(c.container.getReference()) != null) return null; // make an Edit Edit edit = m_user.newContainerEdit(c.container); // store it in the locks m_locks.put(edit.getReference(), edit); return edit; } }
/** * Return a lock on the container with this id, or null if a lock cannot be made. * * @param ref * The container reference. * @return The locked object with this id, or null if a lock cannot be made. */ public Edit editContainer(String ref) { Container c = (Container) m_store.get(ref); if (c == null) return null; synchronized (m_locks) { // check for a lock in place if (m_locks.get(c.container.getReference()) != null) return null; // make an Edit Edit edit = m_user.newContainerEdit(c.container); // store it in the locks m_locks.put(edit.getReference(), edit); return edit; } }
/** * Commit the changes and release the locked container. * * @param container * The container id. * @param edit * The entry to commit. */ public void commitContainer(Edit edit) { // make a new Entry from the Edit to update the info store Entity updatedContainer = m_user.newContainer(edit); // update the store Container c = ((Container) m_store.get(updatedContainer.getReference())); if (c != null) { c.container = updatedContainer; } else { c = new Container(updatedContainer); m_store.put(updatedContainer.getReference(), c); } // release the lock m_locks.remove(edit.getReference()); }
/** * Check if a Resource by this id exists. * * @param container * The container for this resource. * @param id * The id. * @return true if a Resource by this id exists, false if not. */ public boolean checkResource(Entity container, String id) { // just see if the record exists String sql = doubleStorageSql.getSelectIdSql(m_resourceTableName, m_resourceTableIdField, m_resourceTableContainerIdField); Object[] fields = new Object[2]; fields[0] = container.getReference(); fields[1] = id; List ids = m_sql.dbRead(sql, fields, null); return (!ids.isEmpty()); }
/** * Commit the changes and release the locked container. * * @param container * The container id. * @param edit * The entry to commit. */ public void commitContainer(Edit edit) { // make a new Entry from the Edit to update the info store Entity updatedContainer = m_user.newContainer(edit); // update the store Container c = ((Container) m_store.get(updatedContainer.getReference())); if (c != null) { c.container = updatedContainer; } else { c = new Container(updatedContainer); m_store.put(updatedContainer.getReference(), c); } // release the lock m_locks.remove(edit.getReference()); }
/** * Check if a Resource by this id exists. * * @param container * The container for this resource. * @param id * The id. * @return true if a Resource by this id exists, false if not. */ public boolean checkResource(Entity container, String id) { // just see if the record exists String sql = doubleStorageSql.getSelectIdSql(m_resourceTableName, m_resourceTableIdField, m_resourceTableContainerIdField); Object[] fields = new Object[2]; fields[0] = container.getReference(); fields[1] = id; List ids = m_sql.dbRead(sql, fields, null); return (!ids.isEmpty()); }
/** * Get the Resource with this id, or null if not found. * * @param container * The container for this resource. * @param id * The id. * @return The Resource with this id, or null if not found. */ public Entity getResource(Entity container, String id) { Entity entry = null; // get the user from the db String sql = doubleStorageSql.getSelectXml4Sql(m_resourceTableName, m_resourceTableIdField, m_resourceTableContainerIdField); Object[] fields = new Object[2]; fields[0] = container.getReference(); fields[1] = id; List xml = m_sql.dbRead(sql, fields, null); if (!xml.isEmpty()) { // create the Resource from the db xml entry = readResource(container, (String) xml.get(0)); } return entry; }