javax.persistence.PostUpdate Java Examples

The following examples show how to use javax.persistence.PostUpdate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WarpDbCRUDAndCallbackTest.java    From warpdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateProperties() throws Exception {
	User user = new User();
	user.name = "Michael";
	user.email = "[email protected]";
	warpdb.insert(user);
	Thread.sleep(100);
	user.name = "Changed";
	user.version = 99;
	warpdb.updateProperties(user, "name", "version", "updatedAt");
	assertTrue(user.callbacks.contains(PreUpdate.class));
	assertTrue(user.callbacks.contains(PostUpdate.class));
	assertNotEquals(user.createdAt, user.updatedAt);
	assertEquals(System.currentTimeMillis(), user.updatedAt, 500.0);
	// fetch:
	User bak = warpdb.fetch(User.class, user.id);
	assertNotNull(bak);
	assertEquals(user.id, bak.id);
	assertEquals("Changed", bak.name);
	assertEquals("Changed", bak.name);
	assertEquals(99, bak.version);
}
 
Example #2
Source File: WarpDbCRUDAndCallbackTest.java    From warpdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() throws Exception {
	User user = new User();
	user.name = "Michael";
	user.email = "[email protected]";
	warpdb.insert(user);
	Thread.sleep(100);
	user.name = "Changed";
	user.email = "[email protected]";
	warpdb.update(user);
	assertTrue(user.callbacks.contains(PreUpdate.class));
	assertTrue(user.callbacks.contains(PostUpdate.class));
	assertNotEquals(user.createdAt, user.updatedAt);
	assertEquals(System.currentTimeMillis(), user.updatedAt, 500.0);
	// fetch:
	User bak = warpdb.fetch(User.class, user.id);
	assertNotNull(bak);
	assertEquals(user.id, bak.id);
	assertEquals("Changed", bak.name);
	// email is set updatable=false:
	assertEquals("[email protected]", bak.email);
	assertEquals(user.createdAt, bak.createdAt);
	assertEquals(user.updatedAt, bak.updatedAt);
	assertEquals(user.version, bak.version);
}
 
Example #3
Source File: Rating.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
    Criterion criterion = getCriterion();
    if (criterion != null) {
        Rubric rubric = criterion.getRubric();
        if (rubric != null && rubric.getMetadata().isShared()) {
            getMetadata().setShared(true);
        }
    }
}
 
Example #4
Source File: Rubric.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineLockStatus() {
    if (getToolItemAssociations() != null && getToolItemAssociations().size() > 0) {
        for(ToolItemRubricAssociation tira : getToolItemAssociations()) {
            if(tira.getParameters() == null) {
                getMetadata().setLocked(true);
            } else if(!tira.getParameters().containsKey(RubricsConstants.RBCS_SOFT_DELETED) || !tira.getParameters().get(RubricsConstants.RBCS_SOFT_DELETED)) {
                getMetadata().setLocked(true);
                break;
            }
        }
    }
}
 
Example #5
Source File: Criterion.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
    Rubric rubric = getRubric();
    if (rubric != null && rubric.getMetadata().isShared()) {
        getMetadata().setShared(true);
    }
}
 
Example #6
Source File: ProjectConfigImpl.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
@PostPersist
private void postLoadAttributes() {
  if (dbAttributes != null) {
    attributes =
        dbAttributes.values().stream().collect(toMap(attr -> attr.name, attr -> attr.values));
  }
}
 
Example #7
Source File: SituationListener.java    From container with Apache License 2.0 5 votes vote down vote up
@PostUpdate
void situationAfterUpdate(final Situation situation) {
    Collection<SituationsMonitor> monis = sitMonRepo.findSituationMonitorsBySituationId(situation.getId());

    // this SHOULD inject the managementBus dependency when we use it
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    for (SituationsMonitor moni : monis) {
        sendServiceInstanceAdaptionEvent(moni);
    }
}
 
Example #8
Source File: Criterion.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
    Rubric rubric = getRubric();
    if (rubric != null && rubric.getMetadata().isShared()) {
        getMetadata().setShared(true);
    }
}
 
Example #9
Source File: Rubric.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineLockStatus() {
    if (getToolItemAssociations() != null && getToolItemAssociations().size() > 0) {
        for(ToolItemRubricAssociation tira : getToolItemAssociations()) {
            if(tira.getParameters() == null) {
                getMetadata().setLocked(true);
            } else if(!tira.getParameters().containsKey(RubricsConstants.RBCS_SOFT_DELETED) || !tira.getParameters().get(RubricsConstants.RBCS_SOFT_DELETED)) {
                getMetadata().setLocked(true);
                break;
            }
        }
    }
}
 
Example #10
Source File: Rating.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
    Criterion criterion = getCriterion();
    if (criterion != null) {
        Rubric rubric = criterion.getRubric();
        if (rubric != null && rubric.getMetadata().isShared()) {
            getMetadata().setShared(true);
        }
    }
}
 
Example #11
Source File: PolicyBean.java    From apiman with Apache License 2.0 5 votes vote down vote up
@PostPersist @PostUpdate @PostLoad
protected void decryptData() {
    // Decrypt the endpoint properties.
    EntityType entityType = EntityType.Api;
    if (type == PolicyType.Client) {
        entityType = EntityType.ClientApp;
    } else if (type == PolicyType.Plan) {
        entityType = EntityType.Plan;
    }
    DataEncryptionContext ctx = new DataEncryptionContext(organizationId, entityId, entityVersion, entityType);
    configuration = CurrentDataEncrypter.instance.decrypt(configuration, ctx);
}
 
Example #12
Source File: Model.java    From hermes with Apache License 2.0 4 votes vote down vote up
/**
 * 更新后回调
 */
@PostUpdate
protected void onPostUpdate() {
	Logger.info("user '%s' update data '%s - %s'.", getUpdater(), this.getClass().getSimpleName(), getId());
}
 
Example #13
Source File: AuditTrailListener.java    From tutorials with MIT License 4 votes vote down vote up
@PostPersist
@PostUpdate
@PostRemove
private void afterAnyUpdate(User user) {
    log.info("[USER AUDIT] add/update/delete complete for user: " + user.getId());
}
 
Example #14
Source File: JPAJSONLinkedAccountListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@PostPersist
@PostUpdate
public void readAfterSave(final JPAJSONLinkedAccount account) {
    super.json2list(account, true);
}
 
Example #15
Source File: JPAJSONUserListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@PostPersist
@PostUpdate
public void readAfterSave(final JPAJSONUser user) {
    super.json2list(user, true);
}
 
Example #16
Source File: User.java    From tutorials with MIT License 4 votes vote down vote up
@PostUpdate
public void logUserUpdate() {
    log.info("Updated user: " + userName);
}
 
Example #17
Source File: JPAJSONGroupListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@PostPersist
@PostUpdate
public void readAfterSave(final JPAJSONGroup group) {
    super.json2list(group, true);
}
 
Example #18
Source File: EagerTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@PostUpdate
void postUpdate() {
	postUpdated = true;
}
 
Example #19
Source File: GatewayBean.java    From apiman with Apache License 2.0 4 votes vote down vote up
@PostPersist @PostUpdate @PostLoad
protected void decryptData() {
    // Encrypt the endpoint properties.
    configuration = CurrentDataEncrypter.instance.decrypt(configuration, new DataEncryptionContext());
}
 
Example #20
Source File: JPAJSONAnyObjectListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
@PostPersist
@PostUpdate
public void readAfterSave(final JPAJSONAnyObject anyObject) {
    super.json2list(anyObject, true);
}
 
Example #21
Source File: AbstractEntity.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@PostUpdate
public void onUpdate() {
    PersistenceListenerManager.getInstance().fireUpdated(this);
}
 
Example #22
Source File: EntityCallbacksListenerTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@PostUpdate
void entityEmbeddedNestedPostUpdate() {
  entityEmbeddedNestedPostUpdate++;
}
 
Example #23
Source File: EntityCallbacksListener.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@PostUpdate
void postUpdate(Object entity) {
  EntityCallbackExecutor.create(PostUpdate.class).execute(entity, entity.getClass());
}
 
Example #24
Source File: User.java    From warpdb with Apache License 2.0 4 votes vote down vote up
@PostUpdate
void postUpdate() {
	callbacks.add(PostUpdate.class);
}
 
Example #25
Source File: Mapper.java    From warpdb with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #26
Source File: EncryptionListener.java    From SMSC with Apache License 2.0 4 votes vote down vote up
/**
 * Method to decrypt password after user loading.
 *
 * @param obj the {@link User} whose password should be decrypted
 */
@PostLoad
@PostUpdate
public void decrypt(Object obj) throws IllegalAccessException {
    EncrypterUtil.decrypt(obj);
}
 
Example #27
Source File: ToDoEntityListener.java    From java-microservice with MIT License 4 votes vote down vote up
@PostUpdate
public void onUpdate(ToDo todo) {
    AutowireHelper.autowire(this, this.publisher);
    this.publisher.publish(new TodoUpdatedEvent(todo));
}
 
Example #28
Source File: CascadeTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@PostUpdate
void postUpdate() {
	postUpdated = true;
}
 
Example #29
Source File: SubselectFetchTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@PostUpdate
void postUpdate() {
	postUpdated = true;
}
 
Example #30
Source File: BatchFetchTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@PostUpdate
void postUpdate() {
	postUpdated = true;
}