下面列出了怎么用javax.persistence.PostRemove的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Clear products and orders from cache post remove.
*/
@PostRemove
private void clearCaches() {
CacheManager.MANAGER.clearCache(PersistenceProduct.class);
CacheManager.MANAGER.clearCache(PersistenceOrder.class);
CacheManager.MANAGER.clearRemoteCache(PersistenceOrderItem.class);
}
/**
* Clear users and order items from cache post remove.
*/
@PostRemove
private void clearCaches() {
CacheManager.MANAGER.clearCache(PersistenceUser.class);
CacheManager.MANAGER.clearCache(PersistenceOrderItem.class);
CacheManager.MANAGER.clearRemoteCache(PersistenceOrder.class);
}
@Test
public void testRemove() throws Exception {
User user = new User();
user.name = "Michael";
user.email = "[email protected]";
warpdb.insert(user);
warpdb.remove(user);
assertTrue(user.callbacks.contains(PreRemove.class));
assertTrue(user.callbacks.contains(PostRemove.class));
assertNull(warpdb.fetch(User.class, user.id));
}
@Test
public void testRemoveBeans() throws Exception {
User[] users = new User[5];
for (int i = 0; i < users.length; i++) {
User user = new User();
user.name = "Mr No." + i;
user.email = "no." + i + "@somewhere.org";
users[i] = user;
}
warpdb.insert(Arrays.asList(users));
warpdb.remove(Arrays.asList(users));
assertTrue(users[0].callbacks.contains(PreRemove.class));
assertTrue(users[0].callbacks.contains(PostRemove.class));
assertNull(warpdb.fetch(User.class, users[0].id));
}
@PostRemove
void postRemove() {
postRemoved = true;
}
@PostRemove
void postRemove() {
postRemoved = true;
}
@PostRemove
void postRemove() {
postRemoved = true;
}
@PostRemove
void postRemove() {
postRemoved = true;
}
@PostRemove
void postRemove() {
postRemoved = true;
}
/**
* Clear categories and order items from cache post remove.
*/
@PostRemove
private void clearCaches() {
CacheManager.MANAGER.clearCache(PersistenceCategory.class);
CacheManager.MANAGER.clearRemoteCache(PersistenceProduct.class);
}
/**
* Clear users and order items from cache post remove.
*/
@PostRemove
private void clearCaches() {
CacheManager.MANAGER.clearCache(PersistenceOrder.class);
CacheManager.MANAGER.clearRemoteCache(PersistenceUser.class);
}
/**
* Clear products from cache to update relationships.
*/
@PostRemove
private void clearCaches() {
CacheManager.MANAGER.clearCache(PersistenceProduct.class);
CacheManager.MANAGER.clearRemoteCache(PersistenceCategory.class);
}
@PostRemove
public void removeObject(BaseEntity o) {
//System.out.println("create object :"+ o);
jmsTool.sendMessage(JMSType.DELETE, o);
}
public Mapper(Class<T> clazz) {
super();
List<AccessibleProperty> all = getPropertiesIncludeHierarchy(clazz);
// check duplicate name:
Set<String> propertyNamesSet = new HashSet<>();
for (String propertyName : all.stream().map((p) -> {
return p.propertyName;
}).toArray(String[]::new)) {
if (!propertyNamesSet.add(propertyName.toLowerCase())) {
throw new ConfigurationException(
"Duplicate property name found: " + propertyName + " in class: " + clazz.getName());
}
}
Set<String> columnNamesSet = new HashSet<>();
for (String columnName : all.stream().map((p) -> {
return p.columnName;
}).toArray(String[]::new)) {
if (!columnNamesSet.add(columnName.toLowerCase())) {
throw new ConfigurationException("Duplicate column name found: " + columnName);
}
}
// check @Id:
AccessibleProperty[] ids = all.stream().filter((p) -> {
return p.isId();
}).sorted((p1, p2) -> {
return p1.columnName.compareTo(p2.columnName);
}).toArray(AccessibleProperty[]::new);
if (ids.length == 0) {
throw new ConfigurationException("No @Id found.");
}
if (ids.length > 1 && all.stream().filter((p) -> {
return p.isId() && p.isIdentityId();
}).count() > 0) {
throw new ConfigurationException("Mutiple @Id cannot be identity.");
}
// get @Version:
AccessibleProperty[] versions = all.stream().filter((p) -> {
return p.isVersion();
}).toArray(AccessibleProperty[]::new);
if (versions.length > 1) {
throw new ConfigurationException("Multiple @Version found.");
}
this.version = versions.length == 0 ? null : versions[0];
this.allProperties = all;
this.allPropertiesMap = buildPropertiesMap(this.allProperties);
this.insertableProperties = all.stream().filter((p) -> {
if (p.isIdentityId()) {
return false;
}
return p.isInsertable();
}).collect(Collectors.toList());
this.updatableProperties = all.stream().filter((p) -> {
return p.isUpdatable();
}).collect(Collectors.toList());
this.updatablePropertiesMap = buildPropertiesMap(this.updatableProperties);
// init:
this.ids = ids;
this.entityClass = clazz;
this.tableName = getTableName(clazz);
this.whereIdsEquals = String.join(" AND ",
Arrays.stream(this.ids).map(id -> id.columnName + " = ?").toArray(String[]::new));
this.selectSQL = "SELECT * FROM " + this.tableName + " WHERE " + this.whereIdsEquals;
String insertPostfix = this.tableName + " (" + String.join(", ", this.insertableProperties.stream().map((p) -> {
return p.columnName;
}).toArray(String[]::new)) + ") VALUES (" + numOfQuestions(this.insertableProperties.size()) + ")";
this.insertSQL = "INSERT INTO " + insertPostfix;
this.insertIgnoreSQL = "INSERT IGNORE INTO " + insertPostfix;
this.updateSQL = "UPDATE " + this.tableName + " SET "
+ String.join(", ", this.updatableProperties.stream().map((p) -> {
return p.columnName + " = ?";
}).toArray(String[]::new)) + " WHERE " + this.whereIdsEquals;
this.deleteSQL = "DELETE FROM " + this.tableName + " WHERE " + this.whereIdsEquals;
this.rowMapper = new BeanRowMapper<>(this.entityClass, this.allProperties);
List<Method> methods = this.findMethods(clazz);
this.prePersist = findListener(methods, PrePersist.class);
this.preUpdate = findListener(methods, PreUpdate.class);
this.preRemove = findListener(methods, PreRemove.class);
this.postLoad = findListener(methods, PostLoad.class);
this.postPersist = findListener(methods, PostPersist.class);
this.postUpdate = findListener(methods, PostUpdate.class);
this.postRemove = findListener(methods, PostRemove.class);
}
@PostRemove
void postRemove(Object entity) {
EntityCallbackExecutor.create(PostRemove.class).execute(entity, entity.getClass());
}
@PostRemove
void entityEmbeddedNestedPostRemove() {
entityEmbeddedNestedPostRemove++;
}
@PostRemove
public void onRemove() {
PersistenceListenerManager.getInstance().fireRemoved(this);
}
@PostPersist
@PostUpdate
@PostRemove
private void afterAnyUpdate(User user) {
log.info("[USER AUDIT] add/update/delete complete for user: " + user.getId());
}
@PostRemove
public void logUserRemoval() {
log.info("Deleted user: " + userName);
}
/**
* Callback for lifecyle event <i>post remove</i>.
*
* @param entity
* the JPA entity which this listener is associated with
*/
@PostRemove
public void postRemove(final Object entity) {
notifyAll(interceptor -> interceptor.postRemove(entity));
}
/**
* This overridden method is used to delete the {@link DocumentHeader} object due to the system not being able to
* manage the {@link DocumentHeader} object via mapping files
*
* @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#postRemove()
*/
@PostRemove
protected void postRemove() {
KRADServiceLocatorWeb.getDocumentHeaderService().deleteDocumentHeader(getDocumentHeader());
}
/**
* Default implementation of the JPA {@link PostRemove} hook. This implementation currently does nothing,
* however sub-classes can override and implement this method if needed.
*
* <p>This method is currently invoked by the corresponding OJB {@link #afterDelete(PersistenceBroker)} hook.
*/
@PostRemove
protected void postRemove() {
// do nothing
}