From aa16900e504c11c7642d9141738b6aba6b00b487 Mon Sep 17 00:00:00 2001 From: Konstantin Krivopustov Date: Wed, 12 Nov 2008 12:49:55 +0000 Subject: [PATCH] - Standard entity interfaces - EntityLifecycleListener - TimeProvider, SecurityProvider --- db/init/sql/create-db.sql | 5 ++ .../core/src/META-INF/cuba-persistence.xml | 3 + .../haulmont/cuba/core/CubaProperties.java | 2 - .../cuba/core/PersistenceProvider.java | 2 + .../haulmont/cuba/core/SecurityProvider.java | 31 +++++++ .../com/haulmont/cuba/core/TimeProvider.java | 33 ++++++++ .../cuba/core/entity/BaseLongIdEntity.java | 4 +- .../cuba/core/entity/BaseUuidEntity.java | 14 ++-- .../cuba/core/entity/DeleteDeferred.java | 22 +++++ .../com/haulmont/cuba/core/entity/Server.java | 5 +- .../cuba/core/entity/StandardEntity.java | 80 +++++++++++++++++++ .../haulmont/cuba/core/entity/Updatable.java | 24 ++++++ .../haulmont/cuba/core/entity/Versioned.java | 18 +++++ .../core/impl/EntityManagerAdapterImpl.java | 10 ++- .../core/impl/ManagedPersistenceProvider.java | 11 +++ .../cuba/core/impl/SecurityProviderImpl.java | 20 +++++ .../cuba/core/impl/TimeProviderImpl.java | 22 +++++ .../core/persistence/BaseEntityListener.java | 28 ------- .../persistence/EntityLifecycleListener.java | 53 ++++++++++++ .../haulmont/cuba/core/PersistenceTest.java | 29 ++++++- 20 files changed, 368 insertions(+), 48 deletions(-) create mode 100644 modules/core/src/com/haulmont/cuba/core/SecurityProvider.java create mode 100644 modules/core/src/com/haulmont/cuba/core/TimeProvider.java create mode 100644 modules/core/src/com/haulmont/cuba/core/entity/DeleteDeferred.java create mode 100644 modules/core/src/com/haulmont/cuba/core/entity/StandardEntity.java create mode 100644 modules/core/src/com/haulmont/cuba/core/entity/Updatable.java create mode 100644 modules/core/src/com/haulmont/cuba/core/entity/Versioned.java create mode 100644 modules/core/src/com/haulmont/cuba/core/impl/SecurityProviderImpl.java create mode 100644 modules/core/src/com/haulmont/cuba/core/impl/TimeProviderImpl.java delete mode 100644 modules/core/src/com/haulmont/cuba/core/persistence/BaseEntityListener.java create mode 100644 modules/core/src/com/haulmont/cuba/core/persistence/EntityLifecycleListener.java diff --git a/db/init/sql/create-db.sql b/db/init/sql/create-db.sql index b9b30f1e9b..9b7af3bc93 100644 --- a/db/init/sql/create-db.sql +++ b/db/init/sql/create-db.sql @@ -2,6 +2,11 @@ create table SYS_SERVER ( ID varchar(36), CREATE_TS timestamp, CREATED_BY varchar(20), + VERSION integer, + UPDATE_TS timestamp, + UPDATED_BY varchar(20), + IS_DELETED smallint, + DELETED_BY varchar(20), NAME varchar(255), ADDRESS varchar(255), IS_RUNNING smallint, diff --git a/modules/core/src/META-INF/cuba-persistence.xml b/modules/core/src/META-INF/cuba-persistence.xml index 692ad660d3..7755db8919 100644 --- a/modules/core/src/META-INF/cuba-persistence.xml +++ b/modules/core/src/META-INF/cuba-persistence.xml @@ -3,8 +3,11 @@ org.apache.openjpa.persistence.PersistenceProviderImpl java:/DefaultDS + com.haulmont.cuba.core.entity.BaseUuidEntity + com.haulmont.cuba.core.entity.StandardEntity com.haulmont.cuba.core.entity.Server + diff --git a/modules/core/src/com/haulmont/cuba/core/CubaProperties.java b/modules/core/src/com/haulmont/cuba/core/CubaProperties.java index 513da26e19..bfc2b07318 100644 --- a/modules/core/src/com/haulmont/cuba/core/CubaProperties.java +++ b/modules/core/src/com/haulmont/cuba/core/CubaProperties.java @@ -13,6 +13,4 @@ public class CubaProperties { public static final String PERSISTENCE_XML = "cuba.PersistenceXml"; public static final String PERSISTENCE_UNIT = "cuba.PersistenceUnit"; - - public static final int LOGIN_FIELD_LEN = 20; } diff --git a/modules/core/src/com/haulmont/cuba/core/PersistenceProvider.java b/modules/core/src/com/haulmont/cuba/core/PersistenceProvider.java index e1dafbea3e..182c0cb32c 100644 --- a/modules/core/src/com/haulmont/cuba/core/PersistenceProvider.java +++ b/modules/core/src/com/haulmont/cuba/core/PersistenceProvider.java @@ -13,6 +13,8 @@ import com.haulmont.cuba.core.impl.ManagedPersistenceProvider; public abstract class PersistenceProvider { + public static final int LOGIN_FIELD_LEN = 20; + private static PersistenceProvider instance; private static PersistenceProvider getInstance() { diff --git a/modules/core/src/com/haulmont/cuba/core/SecurityProvider.java b/modules/core/src/com/haulmont/cuba/core/SecurityProvider.java new file mode 100644 index 0000000000..8055ae85c0 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/SecurityProvider.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 18:27:17 + * + * $Id$ + */ +package com.haulmont.cuba.core; + +import com.haulmont.cuba.core.impl.SecurityProviderImpl; + +public abstract class SecurityProvider +{ + private static SecurityProvider instance; + + private static SecurityProvider getInstance() { + if (instance == null) { + instance = new SecurityProviderImpl(); + } + return instance; + } + + public static String currentUserLogin() { + return getInstance().__currentUserLogin(); + } + + protected abstract String __currentUserLogin(); +} diff --git a/modules/core/src/com/haulmont/cuba/core/TimeProvider.java b/modules/core/src/com/haulmont/cuba/core/TimeProvider.java new file mode 100644 index 0000000000..ca738230ab --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/TimeProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 14:29:14 + * + * $Id$ + */ +package com.haulmont.cuba.core; + +import com.haulmont.cuba.core.impl.TimeProviderImpl; + +import java.util.Date; + +public abstract class TimeProvider +{ + private static TimeProvider instance; + + private static TimeProvider getInstance() { + if (instance == null) { + instance = new TimeProviderImpl(); + } + return instance; + } + + public static Date currentTimestamp() { + return getInstance().__currentTimestamp(); + } + + protected abstract Date __currentTimestamp(); +} diff --git a/modules/core/src/com/haulmont/cuba/core/entity/BaseLongIdEntity.java b/modules/core/src/com/haulmont/cuba/core/entity/BaseLongIdEntity.java index 685e644fc6..1d23f68f62 100644 --- a/modules/core/src/com/haulmont/cuba/core/entity/BaseLongIdEntity.java +++ b/modules/core/src/com/haulmont/cuba/core/entity/BaseLongIdEntity.java @@ -9,7 +9,7 @@ */ package com.haulmont.cuba.core.entity; -import com.haulmont.cuba.core.CubaProperties; +import com.haulmont.cuba.core.PersistenceProvider; import javax.persistence.Column; import javax.persistence.Id; @@ -27,7 +27,7 @@ public class BaseLongIdEntity implements BaseEntity @Column(name = "CREATE_TS") private Date createTs; - @Column(name = "CREATED_BY", length = CubaProperties.LOGIN_FIELD_LEN) + @Column(name = "CREATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN) private String createdBy; public Long getId() { diff --git a/modules/core/src/com/haulmont/cuba/core/entity/BaseUuidEntity.java b/modules/core/src/com/haulmont/cuba/core/entity/BaseUuidEntity.java index b924b6cebc..14647fddeb 100644 --- a/modules/core/src/com/haulmont/cuba/core/entity/BaseUuidEntity.java +++ b/modules/core/src/com/haulmont/cuba/core/entity/BaseUuidEntity.java @@ -9,20 +9,16 @@ */ package com.haulmont.cuba.core.entity; +import com.haulmont.cuba.core.PersistenceProvider; import org.apache.openjpa.persistence.Persistent; -import javax.persistence.MappedSuperclass; -import javax.persistence.Id; import javax.persistence.Column; -import javax.persistence.EntityListeners; -import java.util.UUID; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; import java.util.Date; - -import com.haulmont.cuba.core.CubaProperties; -import com.haulmont.cuba.core.persistence.BaseEntityListener; +import java.util.UUID; @MappedSuperclass -@EntityListeners({BaseEntityListener.class}) public class BaseUuidEntity implements BaseEntity { @Id @@ -33,7 +29,7 @@ public class BaseUuidEntity implements BaseEntity @Column(name = "CREATE_TS") private Date createTs; - @Column(name = "CREATED_BY", length = CubaProperties.LOGIN_FIELD_LEN) + @Column(name = "CREATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN) private String createdBy; public BaseUuidEntity() { diff --git a/modules/core/src/com/haulmont/cuba/core/entity/DeleteDeferred.java b/modules/core/src/com/haulmont/cuba/core/entity/DeleteDeferred.java new file mode 100644 index 0000000000..18b25dbd2e --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/entity/DeleteDeferred.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 12.11.2008 12:29:58 + * + * $Id$ + */ +package com.haulmont.cuba.core.entity; + +public interface DeleteDeferred extends Updatable +{ + Boolean isDeleted(); + + void setDeleted(Boolean deleted); + + String getDeletedBy(); + + void setDeletedBy(String deletedBy); +} diff --git a/modules/core/src/com/haulmont/cuba/core/entity/Server.java b/modules/core/src/com/haulmont/cuba/core/entity/Server.java index de1be9d60c..8f49d71b4d 100644 --- a/modules/core/src/com/haulmont/cuba/core/entity/Server.java +++ b/modules/core/src/com/haulmont/cuba/core/entity/Server.java @@ -9,15 +9,14 @@ */ package com.haulmont.cuba.core.entity; -import com.haulmont.cuba.core.entity.BaseEntity; - import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Column; +import javax.persistence.EntityListeners; @Entity @Table(name = "SYS_SERVER") -public class Server extends BaseUuidEntity +public class Server extends StandardEntity { @Column(name = "NAME") private String name; diff --git a/modules/core/src/com/haulmont/cuba/core/entity/StandardEntity.java b/modules/core/src/com/haulmont/cuba/core/entity/StandardEntity.java new file mode 100644 index 0000000000..52ce9d28f0 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/entity/StandardEntity.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 18:32:18 + * + * $Id$ + */ +package com.haulmont.cuba.core.entity; + +import com.haulmont.cuba.core.PersistenceProvider; + +import javax.persistence.MappedSuperclass; +import javax.persistence.Column; +import javax.persistence.Version; +import java.util.Date; + +@MappedSuperclass +public class StandardEntity + extends BaseUuidEntity + implements Versioned, Updatable, DeleteDeferred +{ + @Version + @Column(name = "VERSION") + private Integer version; + + @Column(name = "UPDATE_TS") + private Date updateTs; + + @Column(name = "UPDATED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN) + private String updatedBy; + + @Column(name = "IS_DELETED") + private Boolean deleted = false; + + @Column(name = "DELETED_BY", length = PersistenceProvider.LOGIN_FIELD_LEN) + private String deletedBy; + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public Date getUpdateTs() { + return updateTs; + } + + public void setUpdateTs(Date updateTs) { + this.updateTs = updateTs; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public Boolean isDeleted() { + return deleted; + } + + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } + + public String getDeletedBy() { + return deletedBy; + } + + public void setDeletedBy(String deletedBy) { + this.deletedBy = deletedBy; + } +} diff --git a/modules/core/src/com/haulmont/cuba/core/entity/Updatable.java b/modules/core/src/com/haulmont/cuba/core/entity/Updatable.java new file mode 100644 index 0000000000..3a99a4cc80 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/entity/Updatable.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 18:25:30 + * + * $Id$ + */ +package com.haulmont.cuba.core.entity; + +import java.util.Date; + +public interface Updatable +{ + Date getUpdateTs(); + + void setUpdateTs(Date updateTs); + + String getUpdatedBy(); + + void setUpdatedBy(String updatedBy); +} diff --git a/modules/core/src/com/haulmont/cuba/core/entity/Versioned.java b/modules/core/src/com/haulmont/cuba/core/entity/Versioned.java new file mode 100644 index 0000000000..c6b249a84a --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/entity/Versioned.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 12.11.2008 12:23:01 + * + * $Id$ + */ +package com.haulmont.cuba.core.entity; + +public interface Versioned +{ + Integer getVersion(); + + void setVersion(Integer version); +} diff --git a/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java b/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java index c57c682b9a..613557b83e 100644 --- a/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java +++ b/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java @@ -11,7 +11,9 @@ package com.haulmont.cuba.core.impl; import org.apache.openjpa.persistence.OpenJPAEntityManager; import com.haulmont.cuba.core.EntityManagerAdapter; +import com.haulmont.cuba.core.SecurityProvider; import com.haulmont.cuba.core.entity.BaseEntity; +import com.haulmont.cuba.core.entity.DeleteDeferred; public class EntityManagerAdapterImpl implements EntityManagerAdapter { @@ -30,7 +32,13 @@ public class EntityManagerAdapterImpl implements EntityManagerAdapter } public void remove(BaseEntity entity) { - jpaEm.remove(entity); + if (entity instanceof DeleteDeferred) { + ((DeleteDeferred) entity).setDeleted(true); + ((DeleteDeferred) entity).setDeletedBy(SecurityProvider.currentUserLogin()); + } + else { + jpaEm.remove(entity); + } } public T find(Class clazz, Object key) { diff --git a/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java b/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java index f408f81db8..87f5fa6bee 100644 --- a/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java +++ b/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java @@ -14,6 +14,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.commons.lang.StringUtils; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.persistence.EntityManagerFactoryImpl; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; import javax.naming.Context; import javax.naming.NamingException; @@ -27,6 +29,7 @@ import com.haulmont.cuba.core.PersistenceProvider; import com.haulmont.cuba.core.EntityManagerFactoryAdapter; import com.haulmont.cuba.core.EntityManagerAdapter; import com.haulmont.cuba.core.CubaProperties; +import com.haulmont.cuba.core.persistence.EntityLifecycleListener; public class ManagedPersistenceProvider extends PersistenceProvider { @@ -63,6 +66,7 @@ public class ManagedPersistenceProvider extends PersistenceProvider OpenJPAEntityManagerFactory jpaFactory = OpenJPAPersistence.createEntityManagerFactory(unitName, xmlPath); + initJpaFactory(jpaFactory); EntityManagerFactoryAdapter emf = new EntityManagerFactoryAdapterImpl(jpaFactory); try { @@ -81,6 +85,13 @@ public class ManagedPersistenceProvider extends PersistenceProvider } } + private void initJpaFactory(OpenJPAEntityManagerFactory jpaFactory) { + ((OpenJPAEntityManagerFactorySPI) jpaFactory).addLifecycleListener( + new EntityLifecycleListener(), + null + ); + } + protected EntityManagerAdapter __getEntityManager() { EntityManagerAdapterImpl em; try { diff --git a/modules/core/src/com/haulmont/cuba/core/impl/SecurityProviderImpl.java b/modules/core/src/com/haulmont/cuba/core/impl/SecurityProviderImpl.java new file mode 100644 index 0000000000..2cdb39b727 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/impl/SecurityProviderImpl.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 18:29:38 + * + * $Id$ + */ +package com.haulmont.cuba.core.impl; + +import com.haulmont.cuba.core.SecurityProvider; + +public class SecurityProviderImpl extends SecurityProvider +{ + protected String __currentUserLogin() { + return "admin"; + } +} diff --git a/modules/core/src/com/haulmont/cuba/core/impl/TimeProviderImpl.java b/modules/core/src/com/haulmont/cuba/core/impl/TimeProviderImpl.java new file mode 100644 index 0000000000..0d1ba58305 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/impl/TimeProviderImpl.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 16:14:49 + * + * $Id$ + */ +package com.haulmont.cuba.core.impl; + +import com.haulmont.cuba.core.TimeProvider; + +import java.util.Date; + +public class TimeProviderImpl extends TimeProvider +{ + protected Date __currentTimestamp() { + return new Date(); + } +} diff --git a/modules/core/src/com/haulmont/cuba/core/persistence/BaseEntityListener.java b/modules/core/src/com/haulmont/cuba/core/persistence/BaseEntityListener.java deleted file mode 100644 index ba7b3c2bf4..0000000000 --- a/modules/core/src/com/haulmont/cuba/core/persistence/BaseEntityListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. - * Haulmont Technology proprietary and confidential. - * Use is subject to license terms. - - * Author: Konstantin Krivopustov - * Created: 10.11.2008 16:33:43 - * - * $Id$ - */ -package com.haulmont.cuba.core.persistence; - -import com.haulmont.cuba.core.entity.BaseEntity; - -import javax.persistence.PrePersist; -import java.util.Date; - -public class BaseEntityListener -{ - @PrePersist - void onCreate(Object obj) { - if (obj instanceof BaseEntity) { - ((BaseEntity) obj).setCreatedBy("admin"); - ((BaseEntity) obj).setCreateTs(new Date()); - } - } - -} diff --git a/modules/core/src/com/haulmont/cuba/core/persistence/EntityLifecycleListener.java b/modules/core/src/com/haulmont/cuba/core/persistence/EntityLifecycleListener.java new file mode 100644 index 0000000000..378c3fcddb --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/persistence/EntityLifecycleListener.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. + * Haulmont Technology proprietary and confidential. + * Use is subject to license terms. + + * Author: Konstantin Krivopustov + * Created: 11.11.2008 18:14:37 + * + * $Id$ + */ +package com.haulmont.cuba.core.persistence; + +import com.haulmont.cuba.core.SecurityProvider; +import com.haulmont.cuba.core.TimeProvider; +import com.haulmont.cuba.core.entity.BaseEntity; +import com.haulmont.cuba.core.entity.Updatable; +import org.apache.openjpa.enhance.PersistenceCapable; +import org.apache.openjpa.event.AbstractLifecycleListener; +import org.apache.openjpa.event.LifecycleEvent; + +import java.util.Date; + +public class EntityLifecycleListener extends AbstractLifecycleListener +{ + public void beforePersist(LifecycleEvent event) { + if ((event.getSource() instanceof BaseEntity)) { + __beforePersist((BaseEntity) event.getSource()); + } + } + + public void beforeStore(LifecycleEvent event) { + PersistenceCapable pc = (PersistenceCapable) event.getSource(); + if (!pc.pcIsNew() && (event.getSource() instanceof Updatable)) { + __beforeUpdate((Updatable) event.getSource()); + } + } + + private void __beforePersist(BaseEntity entity) { + entity.setCreatedBy(SecurityProvider.currentUserLogin()); + Date ts = TimeProvider.currentTimestamp(); + entity.setCreateTs(ts); + + if (entity instanceof Updatable) { + ((Updatable) entity).setUpdateTs(TimeProvider.currentTimestamp()); + } + } + + private void __beforeUpdate(Updatable entity) { + String user = SecurityProvider.currentUserLogin(); + entity.setUpdatedBy(user); + entity.setUpdateTs(TimeProvider.currentTimestamp()); + } +} diff --git a/modules/core/test/com/haulmont/cuba/core/PersistenceTest.java b/modules/core/test/com/haulmont/cuba/core/PersistenceTest.java index 41c76262ce..a504b355e8 100644 --- a/modules/core/test/com/haulmont/cuba/core/PersistenceTest.java +++ b/modules/core/test/com/haulmont/cuba/core/PersistenceTest.java @@ -36,9 +36,32 @@ public class PersistenceTest extends CubaTestCase throw new RuntimeException(e); } - EntityManagerAdapter em = PersistenceProvider.getEntityManager(); - Server server = em.find(Server.class, id); - assertEquals(id, server.getId()); + beginTran(); + try { + EntityManagerAdapter em = PersistenceProvider.getEntityManager(); + Server server = em.find(Server.class, id); + assertEquals(id, server.getId()); + + server.setAddress("222"); + commitTran(); + } catch (Exception e) { + rollbackTran(); + throw new RuntimeException(e); + } + + beginTran(); + try { + EntityManagerAdapter em = PersistenceProvider.getEntityManager(); + Server server = em.find(Server.class, id); + assertEquals(id, server.getId()); + + em.remove(server); + commitTran(); + } catch (Exception e) { + rollbackTran(); + throw new RuntimeException(e); + } + } private void beginTran() {