/** * 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()); }
/** * 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()); }
/** * Creates a parameter array for an SQL statement that needs * (i) a node identifier, and (2) another parameter. * * @param id the node id * @param p the other parameter * @param before whether the other parameter should be before the uuid parameter * @return an Object array that represents the parameters */ protected Object[] createParams(NodeId id, Object p, boolean before) { // Create the key List<Object> key = new ArrayList<Object>(); if (getStorageModel() == SM_BINARY_KEYS) { key.add(id.getRawBytes()); } else { key.add(id.getMostSignificantBits()); key.add(id.getLeastSignificantBits()); } // Create the parameters List<Object> params = new ArrayList<Object>(); if (before) { params.add(p); params.addAll(key); } else { params.addAll(key); params.add(p); } return params.toArray(); }
/** * Creates a parameter array for an SQL statement that needs * (i) a node identifier, and (2) another parameter. * * @param id the node id * @param p the other parameter * @param before whether the other parameter should be before the uuid parameter * @return an Object array that represents the parameters */ protected Object[] createParams(NodeId id, Object p, boolean before) { // Create the key List<Object> key = new ArrayList<Object>(); if (getStorageModel() == SM_BINARY_KEYS) { key.add(id.getRawBytes()); } else { key.add(id.getMostSignificantBits()); key.add(id.getLeastSignificantBits()); } // Create the parameters List<Object> params = new ArrayList<Object>(); if (before) { params.add(p); params.addAll(key); } else { params.addAll(key); params.add(p); } return params.toArray(); }
/** * Creates a parameter array for an SQL statement that needs * (i) a node identifier, and (2) another parameter. * * @param id the node id * @param p the other parameter * @param before whether the other parameter should be before the uuid parameter * @return an Object array that represents the parameters */ protected Object[] createParams(NodeId id, Object p, boolean before) { // Create the key List<Object> key = new ArrayList<Object>(); if (getStorageModel() == SM_BINARY_KEYS) { key.add(id.getRawBytes()); } else { key.add(id.getMostSignificantBits()); key.add(id.getLeastSignificantBits()); } // Create the parameters List<Object> params = new ArrayList<Object>(); if (before) { params.add(p); params.addAll(key); } else { params.addAll(key); params.add(p); } return params.toArray(); }
/** * 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() }; } }
/** * 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() }; } }
/** * 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() }; } }
private void assertUuidFormat(NodeId id) { long high = id.getMostSignificantBits(); long low = id.getLeastSignificantBits(); long high2 = (high & (~0xf000L)) | 0x4000L; // version 4 (random) assertEquals(high, high2); long low2 = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; // variant (Leach-Salz) assertEquals(low, low2); }
public void testGetMostAndLeastSignificantBits() { for (NodeId id : ids) { long msb = id.getMostSignificantBits(); long lsb = id.getLeastSignificantBits(); assertEquals(id, new NodeId(msb, lsb)); } }
/** * 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); }
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()); }