public void testOffset() throws RepositoryException { System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "ab/0"); NodeIdFactory f = new NodeIdFactory(factoryDir); f.open(); assertEquals("00000000-0000-00ab-0000-000000000000", f.newNodeId().toString()); f.close(); f = new NodeIdFactory(factoryDir); f.open(); assertEquals("00000000-0000-00ab-0000-000000000001", f.newNodeId().toString()); f.close(); }
public void close() throws RepositoryException { if (!createRandom) { store(nextLsb); } }
id = stateMgr.getNodeIdFactory().newNodeId(); } else if (transientStore.containsKey(id)) { throw new RepositoryException(
nodeIdFactory = new NodeIdFactory(repConfig.getHomeDir()); nodeIdFactory.open(); context.setNodeIdFactory(nodeIdFactory);
nodeIdFactory.close(); } catch (RepositoryException e) { log.error("error while closing repository file system", e);
id = stateMgr.getNodeIdFactory().newNodeId(); } else if (transientStore.containsKey(id)) { throw new RepositoryException(
nodeIdFactory = new NodeIdFactory(repConfig.getHomeDir()); nodeIdFactory.open(); context.setNodeIdFactory(nodeIdFactory);
nodeIdFactory.close(); } catch (RepositoryException e) { log.error("error while closing repository file system", e);
public void testRandomVersusSequential() throws RepositoryException { NodeIdFactory f = new NodeIdFactory(factoryDir); f.open(); NodeId id = f.newNodeId(); assertTrue(id.getLeastSignificantBits() != 0); f.close(); System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "true"); f = new NodeIdFactory(factoryDir); f.open(); id = f.newNodeId(); assertTrue(id.getLeastSignificantBits() == 0); f.close(); }
/** * Creates a new activity. * * @param title title of the new activity * @return the id of the newly created activity * @throws RepositoryException if an error occurs */ NodeStateEx internalCreateActivity(String title) throws RepositoryException { WriteOperation operation = startWriteOperation(); try { // create deep path NodeId activityId = nodeIdFactory.newNodeId(); NodeStateEx parent = getParentNode(getActivitiesRoot(), activityId.toString(), NameConstants.REP_ACTIVITIES); Name name = getName(activityId.toString()); // create new activity node in the persistent state NodeStateEx pNode = InternalActivityImpl.create(parent, name, activityId, title); // end update operation.save(); log.debug("Created new activity " + activityId + " with title " + title + "."); return pNode; } catch (ItemStateException e) { throw new RepositoryException(e); } finally { operation.close(); } }
public void close() throws RepositoryException { if (!createRandom) { store(nextLsb); } }
public void testNormalUsage() throws RepositoryException { System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "true"); NodeIdFactory f = new NodeIdFactory(factoryDir); f.open(); assertTrue(f.newNodeId().toString().endsWith("-0000-000000000000")); f.close(); f = new NodeIdFactory(factoryDir); f.open(); assertTrue(f.newNodeId().toString().endsWith("-0000-000000000001")); f.close(); }
/** * Creates a new activity. * * @param title title of the new activity * @return the id of the newly created activity * @throws RepositoryException if an error occurs */ NodeStateEx internalCreateActivity(String title) throws RepositoryException { WriteOperation operation = startWriteOperation(); try { // create deep path NodeId activityId = nodeIdFactory.newNodeId(); NodeStateEx parent = getParentNode(getActivitiesRoot(), activityId.toString(), NameConstants.REP_ACTIVITIES); Name name = getName(activityId.toString()); // create new activity node in the persistent state NodeStateEx pNode = InternalActivityImpl.create(parent, name, activityId, title); // end update operation.save(); log.debug("Created new activity " + activityId + " with title " + title + "."); return pNode; } catch (ItemStateException e) { throw new RepositoryException(e); } finally { operation.close(); } }
public NodeId newNodeId() throws RepositoryException { if (createRandom) { return NodeId.randomId(); } long lsb = nextLsb++; if (lsb >= storedLsb) { store(lsb + cacheSize); } return new NodeId(msb, lsb); }
public void testKillWhileSaving() throws RepositoryException { System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "true"); NodeIdFactory f = new NodeIdFactory(factoryDir); f.open(); assertTrue(f.newNodeId().toString().endsWith("-0000-000000000000")); f.close(); File id = new File(factoryDir, "nodeId.properties"); assertTrue(id.exists()); File idTemp = new File(factoryDir, "nodeId.properties.temp"); id.renameTo(idTemp); f = new NodeIdFactory(factoryDir); f.open(); assertTrue(f.newNodeId().toString().endsWith("-0000-000000000001")); assertFalse(idTemp.exists()); f.close(); }
/** * {@inheritDoc} */ public NodeState createNew( NodeId id, Name nodeTypeName, NodeId parentId) throws RepositoryException { if (!editMode) { throw new RepositoryException("Not in edit mode"); } boolean nonRandomId = true; if (id == null) { id = getNodeIdFactory().newNodeId(); nonRandomId = false; } NodeState state = new NodeState( id, nodeTypeName, parentId, ItemState.STATUS_NEW, false); changeLog.added(state); state.setContainer(this); if (nonRandomId && !changeLog.deleted(id) && sharedStateMgr.hasItemState(id)) { throw new InvalidItemStateException( "Node " + id + " already exists"); } return state; }
public NodeId newNodeId() throws RepositoryException { if (createRandom) { return NodeId.randomId(); } long lsb = nextLsb++; if (lsb >= storedLsb) { store(lsb + cacheSize); } return new NodeId(msb, lsb); }
public void testKillRepository() throws RepositoryException { System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "true"); int cacheSize = 8; for (int i = 1; i < 40; i++) { File id = new File(factoryDir, "nodeId.properties"); id.delete(); NodeIdFactory f = new NodeIdFactory(factoryDir); f.setCacheSize(cacheSize); f.open(); NodeId last = null; for (int j = 0; j < i; j++) { last = f.newNodeId(); } // don't close the factory - this is the same as killing the process // f.close(); f = new NodeIdFactory(factoryDir); f.setCacheSize(cacheSize); f.open(); NodeId n = f.newNodeId(); assertTrue("now: " + n + " last: " + last, n.compareTo(last) > 0); long diff = n.getLeastSignificantBits() - last.getLeastSignificantBits(); assertTrue("diff: " + diff, diff > 0 && diff <= cacheSize); f.close(); } }
NodeId historyId = vMgr.getNodeIdFactory().newNodeId(); NodeStateEx pNode = parent.addNode(name, NameConstants.NT_VERSIONHISTORY, historyId, true); NodeId versionId = vMgr.getNodeIdFactory().newNodeId(); NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION, versionId, true);
/** * Test that the version field is reset (0), and that all other MSB bits are * 1 at some point. This also tests the LSB bits. */ public void testUUIDVersionFieldReset() throws Exception { System.setProperty(NodeIdFactory.SEQUENTIAL_NODE_ID, "true"); long msbOr = 0, msbAnd = -1, lsbOr = 0, lsbAnd = -1; for (int i = 0; i < 0x1f; i++) { FileUtils.deleteDirectory(new File(factoryDir)); NodeIdFactory f = new NodeIdFactory(factoryDir); f.open(); for (int j = 0; j < 8; j++) { NodeId x = f.newNodeId(); msbOr |= x.getMostSignificantBits(); msbAnd &= x.getMostSignificantBits(); lsbAnd &= x.getLeastSignificantBits(); lsbOr |= x.getLeastSignificantBits(); } f.close(); } assertEquals(0xffffffffffff0fffL, msbOr); assertEquals(0, msbAnd); assertEquals(7, lsbOr); assertEquals(0, lsbAnd); }