uuid

Efficient method to generate UUID String in JAVA (UUID.randomUUID().toString() without the dashes)

徘徊边缘 提交于 2019-11-28 13:56:17
问题 I would like an efficient utility to generate unique sequences of bytes. UUID is a good candidate but UUID.randomUUID().toString() generates stuff like 44e128a5-ac7a-4c9a-be4c-224b6bf81b20 which is good as long as you don't need to transmit it over HTTP, in which case the dashes need to be removed. I'm looking for an efficient way to generate a random strings, only from alphanumeric characters (no dashes or any other special symbols). 回答1: This does it: public static void main(String[] args)

Hibernate UUID with PostgreSQL and SQL Server

只愿长相守 提交于 2019-11-28 13:55:54
I have an application I would like to run on both PostgreSQL and SQL Server. I would like to use java.util.UUID as the IDs. I have defined my columns in SQL Server as id UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE I have defined my columns in PostgreSQL as id UUID NOT NULL The columns are defined in my JPA Entities as @Id @Column(name = "id") public UUID getId() { return id; } This works for PostgreSQL as it passes the UUID to the PostgreSQL JDBC driver. This sort of works for SQL Server, as Hibernate translates the UUID to its binary form before sending it to SQL Server. Unfortunately the

PHP preg_match UUID v4

一笑奈何 提交于 2019-11-28 13:47:45
I've got a string that contains UUID v4 $uuid = 'http://domain.com/images/123/b85066fc-248f-4ea9-b13d-0858dbf4efc1_small.jpg'; How would i get the b85066fc-248f-4ea9-b13d-0858dbf4efc1 value from the above using preg_match() ? More info on UUID v4 can be be found here Nemoden $uuid = 'http://domain.com/images/123/b85066fc-248f-4ea9-b13d-0858dbf4efc1_small.jpg'; preg_match('!/images/\d+/([a-z0-9\-]*)_!i', $uuid, $m); And preg_match('/[a-f0-9]{8}\-[a-f0-9]{4}\-4[a-f0-9]{3}\-(8|9|a|b)[a-f0-9]{3‌​}\-[a-f0-9]{12}/', $uuid, $m); works too. Taken from here , but I don't know if we can rely on that.

MySQL主键设计

会有一股神秘感。 提交于 2019-11-28 13:36:34
目录 MySQL主键设计原则 主键设计的常用方案 自增ID UUID 自定义序列表 如何解决水平分片的需求 UUID 独立的序列库 复合标识符 带分库策略的自定义序列表 主键的必要性 主键的数据类型选择 在项目过程中遇到一个看似极为基础的问题,但是在深入思考后还是引出了不少问题,觉得有必要把这一学习过程进行记录。 MySQL主键设计原则 MySQL主键应当是对用户没有意义的。 MySQL主键应该是单列的,以便提高连接和筛选操作的效率 永远也不要更新MySQL主键 MySQL主键不应包含动态变化的数据,如时间戳、创建时间列、修改时间列等 MySQL主键应当有计算机自动生成。 主键设计的常用方案 自增ID 优点 : 1、数据库自动编号,速度快,而且是增量增长,聚集型主键按顺序存放,对于检索非常有利。 2、 数字型,占用空间小,易排序,在程序中传递方便。 缺点 : 1、不支持水平分片架构,水平分片的设计当中,这种方法显然不能保证全局唯一。 2、表锁 在MySQL5.1.22之前,InnoDB自增值是通过其本身的自增长计数器来获取值,该实现方式是通过表锁机制来完成的(AUTO-INC LOCKING)。锁不是在每次事务完成后释放,而是在完成对自增长值插入的SQL语句后释放,要等待其释放才能进行后续操作。比如说当表里有一个auto_increment字段的时候

[Golang] 使用dep

房东的猫 提交于 2019-11-28 12:57:10
原文引用 https://www.dazhuanlan.com/2019/08/25/5d62275d94dc6/ 之前的博文 [Golang]Win10下Glide的安装和使用 记录了对Glide的学习,本博将记录对Golang包管理工具dep的学习使用。 dep介绍 在2012年,go get成为获取依赖包的方式。dep的FAQ中有一段描述dep是否要取代go get的解答,一句话概括就是:依赖管理工具是为应用管理代码的,go get是为GOPATH管理代码的。go get仅仅支持获取master branch上的latest代码,没有指定version、branch或revision的能力。这不符合gopher对自己项目所依赖的第三方包受控的期望。 在2015年,Russ Cox在Go 1.5发布前期以一个experiment feature身份紧急加入vendor机制,vendor标准化了项目依赖的第三方库的存放位置,隔离不同项目依赖的同一个包的不同版本。 Golang的包管理一直没有官方统一的解决方案,因此也产生了很多非官方的包管理工具。这些工具很多都很不错,但是相互兼容性差。随着Go语言在全球范围内应用的愈加广泛,缺少官方包管理工具这一问题变得日益突出。2016年GopherCon大会后,由微服务框架go-kit作者Peter Bourgon牵头, 在Go官方的组织下

8种方案解决重复提交问题

霸气de小男生 提交于 2019-11-28 12:26:01
作者:锦成同学 链接:juejin.im/post/5d31928c51882564c966a71c 1.什么是幂等 在我们编程中常见幂等 select查询天然幂等 delete删除也是幂等,删除同一个多次效果一样 update直接更新某个值的,幂等 update更新累加操作的,非幂等 insert非幂等操作,每次新增一条 2.产生原因 由于重复点击或者网络重发 eg: 点击提交按钮两次; 点击刷新按钮; 使用浏览器后退按钮重复之前的操作,导致重复提交表单; 使用浏览器历史记录重复提交表单; 浏览器重复的HTTP请; nginx重发等情况; 分布式RPC的try重发等; 3.解决方案 1)前端js提交禁止按钮可以用一些js组件 2)使用Post/Redirect/Get模式 在提交后执行页面重定向,这就是所谓的Post-Redirect-Get (PRG)模式。简言之,当用户提交了表单后,你去执行一个客户端的重定向,转到提交成功信息页面。这能避免用户按F5导致的重复提交,而其也不会出现浏览器表单重复提交的警告,也能消除按浏览器前进和后退按导致的同样问题。 3)在session中存放一个特殊标志 在服务器端,生成一个唯一的标识符,将它存入session,同时将它写入表单的隐藏字段中,然后将表单页面发给浏览器,用户录入信息后点击提交,在服务器端,获取表单中隐藏字段的值

Generate UUID values by default for each row on column of UUID type in H2 Database Engine

妖精的绣舞 提交于 2019-11-28 11:34:21
In the H2 database , on a table with a column of UUID data type , how do we specify that we want H2 to generate a UUID value by default when an INSERT omits that field? I know how to generate a UUID . I have read the Question, How to insert a specific UUID in h2 database? . My question is about how to ask H2 to generate the UUID value on my behalf. Thomas Mueller You can use built-in function RANDOM_UUID() : create table test(id int primary key, data uuid default random_uuid()); insert into test(id) values(1); select * from test; Note that using the UUID (or any other randomly generated data)

Performance of Random UUID generation with Java 7 or Java 6

霸气de小男生 提交于 2019-11-28 09:07:28
I have a web based Java application that generates random UUIDs for session information. One of our testers is claiming up to 350ms to generate UUIDs based upon his own profiling, but I have not yet been able to replicate his results. He points to this article http://www.cowtowncoder.com/blog/archives/2010/10/entry_429.html to help back up his results. I wanted to see if anyone else has ran into this limitation with Java's built-in UUID generation capability in either Java 6 or Java 7 applications. I tested it for (;;) { long t0 = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) {

UUID collision risk using different algorithms

浪子不回头ぞ 提交于 2019-11-28 09:04:46
I have a database where 2 (or maybe 3 or 4) different applications are inserting information. The new information has IDs of the type GUID/UUID, but each application is using a different algorithm to generate the IDs. For example, one is using the NHibernate's "guid.comb", other is using the SQLServer's NEWID(), other might want to use .NET's Guid.NewGuid() implementation. Is there an above normal risk of ID collision or duplicates? Thanks! Aaronaught The risk of collisions is elevated slightly but still vanishingly small. Consider that: Both Comb and NEWID / NEWSEQUENTIALID include a

Are Java random UUID's predictable?

爱⌒轻易说出口 提交于 2019-11-28 08:53:01
I would like to use a cryptographically secure primary key for sensitive data in a database - this cannot be guessable/predictable and it cannot be generated by the database (I need the key before the object is persisted). I understand Java uses a type 4 UUID with a cryptographically secure random number generator, however I know the UUID isn't completely random so my question is how safe is it to assume that uuids cannot be predicted from a set of existing ones? Robert Well if you want to know how random a UUID is you have to look onto the source. The following code section is taken from