Tag: uuid

使用UUID的唯一ID生成真的很独特吗?

我想生成唯一的ID就像java中的自动增量一样。 所以以前我使用当前纳秒秒,但我最终得到了冲突,因为两个数据在相同的纳秒时间内出现.UUID是否解决了上述问题? 注意::在我的项目中,我甚至可以每分钟获得10000行记录,我会将这些记录和UIDS一起转储到表中。可能会出现这样的情况:我会停止我的产品并在一段时间后重新启动它….所以在那种情况下,UUID类如何澄清先前生成的UID(我存储在DB中)将要创建的新UID(尚未转储到DB中)?

如何使用UUID作为Hibernate实体的主键?

我试图在Hibernate中使用UUID。 具有以下@Entity基类描述(使用@MappedSuperclass注释): @Id @Column(name=”id”) private UUID id; public UUID getId() { return id; } 为了测试,我试图从数据库中读取我的类的所有实体(数据库存在,记录存在)。 我的数据库是PostgreSQL 8.4,支持UUID,主键是UUID类型。 运行我的测试我在日志中得到以下内容: [junit] 14:21:34,839 INFO LongType:203 – could not read column value from result set: id0_0_; Bad value for type long : d46668b8-e494-42ba-803f-c43524ac3f31 … [junit] org.postgresql.util.PSQLException: Bad value for type long : d46668b8-e494-42ba-803f-c43524ac3f31 [junit] at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796) [junit] at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019) […]

从类型1 uuid获取unix时间戳

在我们的java应用程序中,我们试图从类型1 uuid获取unix时间。 但它没有给出正确的日期时间值。 long time = uuid.timestamp(); time = time / 10000L; // Dividing by 10^4 as its in 100 nanoseconds precision Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); c.getTime(); 有人可以帮忙吗? 编辑:修正了除数(10 ^ 4)

UUID蓝牙和Android设备

我正在尝试开发一个连接两个设备的Android设备的应用程序,但问题是我只能连接(使用蓝牙)PC蓝牙或设备与Android之外的其他操作系统。 我认为问题是UUID,现在我正在使用BluetoothCommandService.java : private static final UUID MY_UUID = UUID.fromString(“00001101-0000-1000-8000-00805f9b34fb”); 然后: private class ConnectThread extends Thread { private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice; public ConnectThread(BluetoothDevice device) { mmDevice = device; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.createRfcommSocketToServiceRecord(MY_UUID); } catch […]

如何通过蓝牙查询远程手机是否支持PBAP?

假设两部Android手机通过蓝牙配对并建立连接。 如何在客户端以编程方式确定远程设备(服务器)是否支持PBAP等蓝牙配置文件? 如果它支持它,那么如何以编程方式启动与远程设备的PBAP会话? 我已广泛搜索网络,到目前为止一直无法找到相同的API支持和文档。 因此,非常感谢任何帮助或指导。 编辑:获取远程设备的UUID会在这里有用吗? 如果是,我怎么知道它是否支持PBAP? 更新:我设法使用以下方法连接到远程设备: mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(applicationUUID); btAdapter.cancelDiscovery(); mBluetoothSocket.connect(); 哪里 private UUID applicationUUID = UUID.fromString(“0000111E-0000-1000-8000-00805F9B34FB”); 适用于免提配置文件模式。 是否有任何这样的固定UUID用于通过PBAP模式连接? UPDATE-2 :现在我可以使用UUID 0000112F与远程设备配对,UUID 0000112F是PSE访问的UUID。 建立连接后,我在远程设备上收到一条消息,询问我是否允许远程设备访问呼叫日志和联系人。 我点击是。

UUID缩短

我需要计算应用的每日唯一身份用户数。 我可以唯一识别用户的唯一方法是通过他们的UUID(这是外部提供的,所以我不得不使用它)。 我知道我的每日用户数量是几百万用户。 我想在Redis中使用一个bitset来进行人口统计,但是为了使它能够工作,我需要一种缩小我的UUID的方法,以便它可以舒适地适应长时间。 我知道碰撞的可能性,但我并不关心准确的数字。 有没有人以前用Java做过这个? 我所追求的是如何将我的UUID转换成适合长期的东西。

PowerMockito .when()。thenReturn(),randomUUID没有返回预期值

我正在尝试测试连接到包含JCR节点的SQL Server数据库的Web服务方法,因为我们正在使用JackRabbit。 该方法如下: public String addDocumentByJson(String fileName, byte[] fileContent, int status, String userName, String jsonProperties) { UUID id = UUID.randomUUID(); // It does a bunch of operations here return jsonResult; } 其中jsonResult是一个与此类似的对象: { “id” : “” “version” : 1 } 现在,当我尝试按照本答案中的步骤和本文中的代码测试它时,我发现了以下代码(正如我所说的基于过去的链接): @PrepareForTest({ UUID.class }) @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class) @ContextConfiguration(“/TestSpringConfig.xml”) public class TestJackRabbitService { @Autowired @Qualifier(“jackRabbitService”) IJackRabbitService jackRabbitService; […]

这个Java UUID5实现没有通过unit testing

我找不到Java的自包含UUID5实现,所以我尝试在下面推广这个解决方案。 它通过我的一些unit testing,但其他人失败。 这有什么明显的错误吗? public static UUID UUID5(UUID namespace, String name) { MessageDigest md; try { md = MessageDigest.getInstance(“SHA-1”); } catch (NoSuchAlgorithmException nsae) { throw new InternalError(“SHA-1 not supported”); } byte[] namespaceBytes = ByteBuffer.allocate(16).putLong(namespace.getMostSignificantBits()).putLong(namespace.getLeastSignificantBits()).array(); byte[] nameBytes; try { nameBytes = name.getBytes(“UTF-8”); } catch (UnsupportedEncodingException e) { throw new InternalError(“UTF-8 encoding not supported”); } byte[] toHashify […]

用Java读取MySQL二进制(16)UUID

这应该是一个非常简单的问题,我只是缺少一些基本的东西,而且我正在’其中一天……’不能使用Hibernate或其他ORM。 使用Java PreparedStatement。 MySQL的东西: CREATE TABLE `article` ( `articleID` binary(16) NOT NULL, `publisherID` bigint(20) DEFAULT NULL, PRIMARY KEY (`articleID`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$ insert into article ( articleID, publisherID ) values ( (UNHEX(REPLACE(UUID(),’-‘,”))), 1111 ); Java的东西 PreparedStatement ps = connection.prepareStatement( “select articleID, publisherID from article” ); ResultSet rs = ps.executeQuery(); while( rs.next()) { byte[] artIDArr […]

如何在java中将UUID保存为二进制(16)

我有一个表TestTable,列ID为二进制(16),名称为varchar(50) 我一直在尝试将一个有序的UUID存储为PK,就像本文以优化的方式存储UUID一样 我看到UUID作为HEX(blob)保存在数据库中 所以我想从java中保存这个ID,但是我收到了这个错误 数据截断:第1行的列“ID”的数据太长 我目前正在使用库sql2o与mysql进行交互 所以基本上这是我的代码 String suuid = UUID.randomUUID().toString(); String partial_id = suuid.substring(14,18) + suuid.substring(9, 13) + suuid.substring(0, 8) + suuid.substring(19, 23) + suuid.substring(24) String final_id = String.format(“%040x”, new BigInteger(1, partial_id.getBytes())); con.createQuery(“INSERT INTO TestTable(ID, Name) VALUES(:id, :name)”) .addParameter(“id”, final_id) .addParameter(“name”, “test1”).executeUpdate(); 部分ID应该是这样的11d8eebc58e0a7d796690800200c9a66 我在mysql中尝试了这个语句没有问题 insert into testtable(id, name) values(UNHEX(CONCAT(SUBSTR(uuid(), 15, 4),SUBSTR(uuid(), 10, 4),SUBSTR(uuid(), 1, […]