public ConsistencyCheckerImpl(AbstractBundlePersistenceManager pm, ConsistencyCheckListener listener, String lostNFoundId, final UpdateEventChannel eventChannel) { this.pm = pm; this.listener = listener; if (lostNFoundId != null) { this.lostNFoundId = new NodeId(lostNFoundId); } if (eventChannel != null) { this.eventChannel = eventChannel; } }
/** * Returns {@code true} if the specified {@code nodeId} is the ID of the root node; false otherwise. * * @param nodeId The identifier of the node to be tested. * @return {@code true} if the given id is the identifier of the root node. */ private boolean isRootId( NodeId nodeId ) { return rootID.equals( nodeId ); }
/** * {@inheritDoc} */ public String toString() { return id.toString(); } }
/** * Serializes a node identifier * * @param id the node id * @throws IOException in an I/O error occurs. */ private void writeNodeId(NodeId id) throws IOException { out.writeLong(id.getMostSignificantBits()); out.writeLong(id.getLeastSignificantBits()); }
/** * Constructs a parameter list for a PreparedStatement * for the given node identifier. * * @param id the node id * @return a list of Objects */ protected Object[] getKey(NodeId id) { if (getStorageModel() == SM_BINARY_KEYS) { return new Object[] { id.getRawBytes() }; } else { return new Object[] { id.getMostSignificantBits(), id.getLeastSignificantBits() }; } }
public void testUuidFormat() { long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L; for (int i = 0; i < 100; i++) { NodeId id = NodeId.randomId(); assertUuidFormat(id); maxHigh |= id.getMostSignificantBits(); maxLow |= id.getLeastSignificantBits(); minHigh &= id.getMostSignificantBits(); minLow &= id.getLeastSignificantBits(); } NodeId max = new NodeId(maxHigh, maxLow); assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.toString()); NodeId min = new NodeId(minHigh, minLow); assertEquals("00000000-0000-4000-8000-000000000000", min.toString()); }
public void testGetMostAndLeastSignificantBits() { for (NodeId id : ids) { long msb = id.getMostSignificantBits(); long lsb = id.getLeastSignificantBits(); assertEquals(id, new NodeId(msb, lsb)); } }
public void testGetRawBytes() { for (NodeId id : ids) { assertEquals(id, new NodeId(id.getRawBytes())); } }
public void testPerformance() { NodeId id = NodeId.randomId(); long time = System.currentTimeMillis(); for (int i = 0; i < 1000 * 1000; i++) { new IDField(id); } time = System.currentTimeMillis() - time; System.out.println("IDField: " + time + " ms."); for (int i = 0; i < 50; i++) { createNodes(id.toString(), i % 2 == 0); } }
public void testCompareTo() { for (NodeId id : ids) { assertEquals(0, id.compareTo(id)); } NodeId[] ordered = { new NodeId(-1, -1), new NodeId(-1, 0), new NodeId(0, -1), new NodeId(0, 0), new NodeId(0, 1), new NodeId(1, 0), new NodeId(1, 1) }; for (int i = 0; i < ordered.length; i++) { for (int j = 0; j < i; j++) { assertEquals(1, ordered[i].compareTo(ordered[j])); } assertEquals(0, ordered[i].compareTo(ordered[i])); for (int j = i + 1; j < ordered.length; j++) { assertEquals(-1, ordered[i].compareTo(ordered[j])); } } }
private void readState(DOMWalker walker, NodeReferences refs) throws ItemStateException { // first do some paranoid sanity checks if (!walker.getName().equals(NODEREFERENCES_ELEMENT)) { String msg = "invalid serialization format (unexpected element: " + walker.getName() + ")"; log.debug(msg); throw new ItemStateException(msg); } // check targetId if (!refs.getTargetId().equals(NodeId.valueOf(walker.getAttribute(TARGETID_ATTRIBUTE)))) { String msg = "invalid serialized state: targetId mismatch"; log.debug(msg); throw new ItemStateException(msg); } // now we're ready to read the references data // property id's refs.clearAllReferences(); while (walker.iterateElements(NODEREFERENCE_ELEMENT)) { refs.addReference(PropertyId.valueOf(walker.getAttribute(PROPERTYID_ATTRIBUTE))); } }
public int hashCode() { // ChildNodeEntry is immutable, we can store the computed hash code value int h = hash; if (h == 0) { h = 17; h = 37 * h + name.hashCode(); h = 37 * h + id.hashCode(); h = 37 * h + index; hash = h; } return h; } }
/** * @see IdentifierResolver#checkFormat(String) */ public void checkFormat(String identifier) throws MalformedPathException { try { NodeId.valueOf(identifier); } catch (IllegalArgumentException e) { throw new MalformedPathException("Invalid identifier: " + identifier); } }
public ParameterizedNodeId(NodeId original, String parameter) { super(original.getRawBytes()); this.original = original; this.parameter = parameter; }
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(); } }
public void testVersionIterator() throws Exception { InternalVersion version = new DummyInternalVersion(new InternalVersion[] {}, NodeId.randomId()); for (int i = 1; i < VERSION_COUNT; i++) { version = new DummyInternalVersion(new InternalVersion[] {version}, NodeId.randomId()); } try { VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version); assertEquals(VERSION_COUNT, versionIteratorImpl.getSize()); } catch (StackOverflowError e) { fail("Should be able to handle " + VERSION_COUNT + " versions."); } }
private static int slotIndex(ItemId id) { NodeId nodeId; if (id.denotesNode()) { nodeId = (NodeId) id; } else { nodeId = ((PropertyId) id).getParentId(); } return ((int) nodeId.getLeastSignificantBits()) & 0xf; } }
/** * Constructs a parameter list for a PreparedStatement * for the given node identifier. * * @param id the node id * @return a list of Objects */ protected Object[] getKey(NodeId id) { if (getStorageModel() == SM_BINARY_KEYS) { return new Object[] { id.getRawBytes() }; } else { return new Object[] { id.getMostSignificantBits(), id.getLeastSignificantBits() }; } }