本文整理汇总了Java中com.haulmont.cuba.core.EntityManager.persist方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.persist方法的具体用法?Java EntityManager.persist怎么用?Java EntityManager.persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.EntityManager
的用法示例。
在下文中一共展示了EntityManager.persist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeAccessTokenToDatabase
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void storeAccessTokenToDatabase(String tokenValue,
byte[] accessTokenBytes,
String authenticationKey,
byte[] authenticationBytes,
Date tokenExpiry,
String userLogin,
@Nullable Locale locale,
@Nullable String refreshTokenValue) {
try (Transaction tx = persistence.getTransaction()) {
EntityManager em = persistence.getEntityManager();
AccessToken accessToken = metadata.create(AccessToken.class);
accessToken.setCreateTs(timeSource.currentTimestamp());
accessToken.setTokenValue(tokenValue);
accessToken.setTokenBytes(accessTokenBytes);
accessToken.setAuthenticationKey(authenticationKey);
accessToken.setAuthenticationBytes(authenticationBytes);
accessToken.setExpiry(tokenExpiry);
accessToken.setUserLogin(userLogin);
accessToken.setLocale(locale != null ? locale.toString() : null);
accessToken.setRefreshTokenValue(refreshTokenValue);
em.persist(accessToken);
tx.commit();
}
}
示例2: storeRefreshTokenToDatabase
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void storeRefreshTokenToDatabase(String tokenValue,
byte[] tokenBytes,
byte[] authenticationBytes,
Date tokenExpiry,
String userLogin) {
try (Transaction tx = persistence.getTransaction()) {
EntityManager em = persistence.getEntityManager();
RefreshToken refreshToken = metadata.create(RefreshToken.class);
refreshToken.setCreateTs(timeSource.currentTimestamp());
refreshToken.setTokenValue(tokenValue);
refreshToken.setTokenBytes(tokenBytes);
refreshToken.setAuthenticationBytes(authenticationBytes);
refreshToken.setExpiry(tokenExpiry);
refreshToken.setUserLogin(userLogin);
em.persist(refreshToken);
tx.commit();
}
}
示例3: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
User user = new User();
userId = user.getId();
user.setName("testUser");
user.setLogin("testLogin");
user.setPosition("manager");
user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")));
em.persist(user);
UserRole userRole = new UserRole();
userRoleId = userRole.getId();
userRole.setUser(user);
userRole.setRole(em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93")));
em.persist(userRole);
tx.commit();
} finally {
tx.end();
}
}
示例4: persistSendingMessage
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void persistSendingMessage(EntityManager em, SendingMessage message,
MessagePersistingContext context) throws FileStorageException {
boolean useFileStorage = config.isFileStorageUsed();
if (useFileStorage) {
byte[] bodyBytes = bodyTextToBytes(message);
FileDescriptor contentTextFile = createBodyFileDescriptor(message, bodyBytes);
fileStorage.saveFile(contentTextFile, bodyBytes);
context.files.add(contentTextFile);
em.persist(contentTextFile);
message.setContentTextFile(contentTextFile);
message.setContentText(null);
}
em.persist(message);
for (SendingAttachment attachment : message.getAttachments()) {
if (useFileStorage) {
FileDescriptor contentFile = createAttachmentFileDescriptor(attachment);
fileStorage.saveFile(contentFile, attachment.getContent());
context.files.add(contentFile);
em.persist(contentFile);
attachment.setContentFile(contentFile);
attachment.setContent(null);
}
em.persist(attachment);
}
}
示例5: migrateMessage
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void migrateMessage(EntityManager em, SendingMessage msg) {
msg = em.merge(msg);
byte[] bodyBytes = bodyTextToBytes(msg);
FileDescriptor bodyFile = createBodyFileDescriptor(msg, bodyBytes);
try {
fileStorage.saveFile(bodyFile, bodyBytes);
} catch (FileStorageException e) {
throw new RuntimeException(e);
}
em.persist(bodyFile);
msg.setContentTextFile(bodyFile);
msg.setContentText(null);
}
示例6: migrateAttachment
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void migrateAttachment(EntityManager em, SendingAttachment attachment) {
attachment = em.merge(attachment);
FileDescriptor contentFile = createAttachmentFileDescriptor(attachment);
try {
fileStorage.saveFile(contentFile, attachment.getContent());
} catch (FileStorageException e) {
throw new RuntimeException(e);
}
em.persist(contentFile);
attachment.setContentFile(contentFile);
attachment.setContent(null);
}
示例7: createSnapshot
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public EntitySnapshot createSnapshot(Entity entity, View view, Date snapshotDate, User author) {
Preconditions.checkNotNullArgument(entity);
Preconditions.checkNotNullArgument(view);
Preconditions.checkNotNullArgument(snapshotDate);
checkCompositePrimaryKey(entity);
Class viewEntityClass = view.getEntityClass();
Class entityClass = entity.getClass();
if (!viewEntityClass.isAssignableFrom(entityClass)) {
throw new IllegalStateException("View could not be used with this propertyValue");
}
MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(metadata.getClass(entity.getClass()));
EntitySnapshot snapshot = metadata.create(EntitySnapshot.class);
snapshot.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity));
snapshot.setEntityMetaClass(metaClass.getName());
snapshot.setViewXml(viewSerializationAPI.toJson(view, ViewSerializationOption.COMPACT_FORMAT));
snapshot.setSnapshotXml(entitySerializationAPI.toJson(entity));
snapshot.setSnapshotDate(snapshotDate);
snapshot.setAuthor(author);
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
em.persist(snapshot);
tx.commit();
} finally {
tx.end();
}
return snapshot;
}
示例8: test
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void test() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Role role = new Role();
role.setName("testRole1");
em.persist(role);
Group group = new Group();
group.setName("testGroup1");
em.persist(group);
User user = new User();
UUID userId = user.getId();
user.setLogin("testUser1");
user.setName("Test User 1");
user.setGroup(group);
em.persist(user);
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(role);
em.persist(userRole);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
user = em.find(User.class, userId);
List<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
Role r = ur.getRole();
assertEquals(role.getName(), r.getName());
}
} finally {
tx.end();
}
}
示例9: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
passwordEncryption = AppBeans.get(PasswordEncryption.NAME);
loginWorker = AppBeans.get(LoginWorker.NAME);
userSessionSource = AppBeans.get(UserSessionSource.NAME);
standardTestUserSession = userSessionSource.getUserSession();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group = em.getReference(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
User user1 = new User();
user1Id = user1.getId();
user1.setGroup(group);
user1.setLogin("user1");
user1.setPassword(passwordEncryption.getPasswordHash(user1.getId(), "1"));
em.persist(user1);
User user2 = new User();
user2Id = user2.getId();
user2.setGroup(group);
user2.setLogin("user2");
user2.setPassword(passwordEncryption.getPasswordHash(user2.getId(), "2"));
em.persist(user2);
tx.commit();
} finally {
tx.end();
}
}
示例10: createGroups
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
private void createGroups() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group root = new Group();
rootId = root.getId();
root.setName("root");
em.persist(root);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group1 = new Group();
group1Id = group1.getId();
group1.setName("group1");
group1.setParent(root);
em.persist(group1);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
group1 = em.find(Group.class, group1Id);
Group group2 = new Group();
group2Id = group2.getId();
group2.setName("group2");
group2.setParent(group1);
em.persist(group2);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group3 = new Group();
group3Id = group3.getId();
group3.setName("group3");
group3.setParent(root);
em.persist(group3);
tx.commit();
} finally {
tx.end();
}
}
示例11: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
user = new User();
user.setLogin("user-" + user.getId());
user.setGroup(group);
em.persist(user);
substitutedUser = new User();
substitutedUser.setLogin("substitutedUser");
substitutedUser.setGroup(group);
em.persist(substitutedUser);
userSubstitution = new UserSubstitution();
userSubstitution.setUser(user);
userSubstitution.setSubstitutedUser(substitutedUser);
user.setSubstitutions(new ArrayList<>(ImmutableList.of(userSubstitution)));
em.persist(userSubstitution);
tx.commit();
} finally {
tx.end();
}
cont.setupLogging("com.haulmont.cuba.core.sys.FetchGroupManager", Level.TRACE);
}
示例12: onBeforeInsert
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public void onBeforeInsert(Server entity, EntityManager entityManager) {
EntityManager em = persistence.getEntityManager();
FileDescriptor related = new FileDescriptor();
related.setName("Related");
System.out.println(">>>>> persist related: " + related.getId());
em.persist(related);
entity.setData(related.getId().toString());
}
示例13: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Metadata metadata = cont.metadata();
root = metadata.create(CascadeEntity.class);
root.setName("root");
em.persist(root);
first = metadata.create(CascadeEntity.class);
first.setName("first");
first.setFather(root);
em.persist(first);
second = metadata.create(CascadeEntity.class);
second.setName("second");
second.setFather(first);
em.persist(second);
third = metadata.create(CascadeEntity.class);
third.setName("third");
third.setFather(second);
em.persist(third);
tx.commit();
} finally {
tx.end();
}
}
示例14: createEntity
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
private void createEntity(Collection<Entity> managedEntities, EntityManager entityManager) {
Group companyGroup = entityManager.find(Group.class, TestSupport.COMPANY_GROUP_ID);
User u = metadata.create(User.class);
createdEntityId = u.getId();
u.setLogin("TxLstnrTst-" + u.getId());
u.setLoginLowerCase(u.getLogin().toLowerCase());
u.setGroup(companyGroup);
entityManager.persist(u);
}
示例15: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
passwordEncryption = AppBeans.get(PasswordEncryption.class);
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Role role1 = new Role();
role1Id = role1.getId();
role1.setName("testRole1");
em.persist(role1);
Role role2 = new Role();
role2Id = role2.getId();
role2.setName("testRole2");
em.persist(role2);
Permission permission1 = new Permission();
permission1Id = permission1.getId();
permission1.setRole(role1);
permission1.setType(PermissionType.SCREEN);
permission1.setTarget(PERM_TARGET_SCREEN);
permission1.setValue(0);
em.persist(permission1);
Permission permission2 = new Permission();
permission2Id = permission2.getId();
permission2.setRole(role2);
permission2.setType(PermissionType.ENTITY_ATTR);
permission2.setTarget(PERM_TARGET_ATTR);
permission2.setValue(1);
em.persist(permission2);
Group group = new Group();
groupId = group.getId();
group.setName("testGroup");
em.persist(group);
User user = new User();
userId = user.getId();
user.setName(USER_NAME);
user.setLogin(USER_NAME);
String pwd = passwordEncryption.getPasswordHash(userId, USER_PASSW);
user.setPassword(pwd);
user.setGroup(group);
em.persist(user);
UserRole userRole1 = new UserRole();
userRole1Id = userRole1.getId();
userRole1.setUser(user);
userRole1.setRole(role1);
em.persist(userRole1);
UserRole userRole2 = new UserRole();
userRole2Id = userRole2.getId();
userRole2.setUser(user);
userRole2.setRole(role2);
em.persist(userRole2);
tx.commit();
} finally {
tx.end();
}
}