mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-03 08:24:23 +00:00
#668 - ENH: Add ability to register a custom IdGenerator
This commit is contained in:
1 parent
036092d470
commit
4e9e11ac34
15 files changed
+371
-129
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package com.avaje.tests.idkeys;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.ECustomId;
|
||||
import org.avaje.moduuid.ModUUID;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestCustomId extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
|
||||
ECustomId bean = new ECustomId("fred");
|
||||
Ebean.save(bean);
|
||||
assertNotNull(bean.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insert_when_hasValue() {
|
||||
|
||||
ECustomId bean = new ECustomId("gotId");
|
||||
String explicitId = ModUUID.newShortId();
|
||||
bean.setId(explicitId);
|
||||
Ebean.save(bean);
|
||||
|
||||
ECustomId found = Ebean.find(ECustomId.class, explicitId);
|
||||
assertEquals(found.getName(), bean.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class ECustomId {
|
||||
|
||||
@Id @GeneratedValue(generator = "shortUid")
|
||||
String id;
|
||||
|
||||
String name;
|
||||
|
||||
public ECustomId(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user