下面列出了javax.persistence.PrePersist#javax.persistence.PostLoad 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@PostLoad
private void initValuesLoad() {
switch (lifeCycle) {
case API:
referenceId = api.getId();
break;
case PLAN:
referenceId = plan.getId();
break;
case RESOURCE:
referenceId = resource.getId();
break;
case OPERATION:
referenceId = operation.getId();
break;
default:
break;
}
}
/**
* Initializes the registered service with default values
* for fields that are unspecified. Only triggered by JPA.
* @since 4.1
*/
@PostLoad
public final void postLoad() {
if (this.proxyPolicy == null) {
this.proxyPolicy = new RefuseRegisteredServiceProxyPolicy();
}
if (this.usernameAttributeProvider == null) {
this.usernameAttributeProvider = new DefaultRegisteredServiceUsernameProvider();
}
if (this.logoutType == null) {
this.logoutType = LogoutType.BACK_CHANNEL;
}
if (this.requiredHandlers == null) {
this.requiredHandlers = new HashSet<>();
}
if (this.accessStrategy == null) {
this.accessStrategy = new DefaultRegisteredServiceAccessStrategy();
}
if (this.attributeReleasePolicy == null) {
this.attributeReleasePolicy = new ReturnAllowedAttributeReleasePolicy();
}
}
@PostLoad
private void postLoad() {
EntityManagerFactory emf = Utility.getEntityManagerFactory();
EntityManager em = emf.createEntityManager();
try {
ProductText productText = getProductText(em);
if (productText != null) {
this.name = productText.getName();
this.shortDescription = productText.getShortDescription();
this.longDescription = productText.getLongDescription();
} else {
this.name = "";
this.shortDescription = "";
this.longDescription = "";
}
} finally {
em.close();
}
}
@PostLoad
public void checking(Object target) {
AnnotationCheckingMetadata metadata = AnnotationCheckingMetadata.getMetadata(target.getClass());
if (metadata.isCheckable()) {
StringBuilder sb = new StringBuilder();
for (Field field : metadata.getCheckedFields()) {
ReflectionUtils.makeAccessible(field);
Object value = ReflectionUtils.getField(field, target);
if (value instanceof Date) {
throw new RuntimeException("不支持时间类型字段解密!");
}
sb.append(value).append(" - ");
}
sb.append(MD5_KEY);
LOGGER.debug("验证数据:" + sb);
String hex = MD5Utils.encode(sb.toString());
Field checksumField = metadata.getCheckableField();
ReflectionUtils.makeAccessible(checksumField);
String checksum = (String) ReflectionUtils.getField(checksumField, target);
if (!checksum.equals(hex)) {
//throw new RuntimeException("数据验证失败!");
}
}
}
@Test
public void testLoad() throws Exception {
String[] ids = { User.nextId(), User.nextId(), User.nextId(), User.nextId() };
for (int i = 0; i < ids.length; i++) {
User user = new User();
user.id = ids[i];
user.name = "Mr No." + i;
user.email = "no." + i + "@somewhere.org";
warpdb.insert(user);
}
// test get & fetch:
User u1 = warpdb.get(User.class, ids[0]);
assertTrue(u1.callbacks.contains(PostLoad.class));
User u2 = warpdb.fetch(User.class, ids[1]);
assertTrue(u2.callbacks.contains(PostLoad.class));
// test list:
List<User> us = warpdb.list(User.class, "SELECT * FROM User where id>?", ids[1]);
assertEquals(2, us.size());
assertTrue(us.get(0).callbacks.contains(PostLoad.class));
assertTrue(us.get(1).callbacks.contains(PostLoad.class));
// test criteria:
List<User> users = warpdb.from(User.class).where("id>?", ids[1]).list();
assertEquals(2, users.size());
assertTrue(users.get(0).callbacks.contains(PostLoad.class));
assertTrue(users.get(1).callbacks.contains(PostLoad.class));
}
@PostLoad
void postLoad() {
// Reconstitute the contact list.
ImmutableSet.Builder<DesignatedContact> contactsBuilder =
new ImmutableSet.Builder<DesignatedContact>();
if (registrantContact != null) {
contactsBuilder.add(
DesignatedContact.create(DesignatedContact.Type.REGISTRANT, registrantContact));
}
if (billingContact != null) {
contactsBuilder.add(DesignatedContact.create(DesignatedContact.Type.BILLING, billingContact));
}
if (techContact != null) {
contactsBuilder.add(DesignatedContact.create(DesignatedContact.Type.TECH, techContact));
}
if (adminContact != null) {
contactsBuilder.add(DesignatedContact.create(DesignatedContact.Type.ADMIN, adminContact));
}
allContacts = contactsBuilder.build();
}
@PostLoad
public void initialize() {
Map<String, String> properties = new HashMap<>();
TaskNode taskNode = new TaskParser(this.taskName, this.dslText, true, true).parse();
if (taskNode.isComposed()) {
setRegisteredAppName(this.taskName);
}
else {
TaskAppNode singleTaskApp = taskNode.getTaskApp();
setRegisteredAppName(singleTaskApp.getName());
if (singleTaskApp.hasArguments()) {
for (ArgumentNode argumentNode : singleTaskApp.getArguments()) {
properties.put(argumentNode.getName(), argumentNode.getValue());
}
}
}
properties.put(SPRING_CLOUD_TASK_NAME, this.taskName);
this.appDefinition = new AppDefinition(this.taskName, properties);
}
/**
* Updates the values in the attribute values map from the attribute bos and updates the members.
*/
@PostLoad
protected void postLoad() {
this.attributeValues = new HashMap<String, String>();
for (PeopleFlowAttributeBo attributeBo: attributeBos) {
this.attributeValues.put(attributeBo.getAttributeDefinition().getName(), attributeBo.getValue());
}
for (PeopleFlowMemberBo member: members) {
if (member.getMemberName() == null) {
member.updateRelatedObject();
}
for (PeopleFlowDelegateBo delegate: member.getDelegates()) {
if (delegate.getMemberName() == null) {
delegate.updateRelatedObject();
}
}
}
}
@PostLoad
public void afterLoad() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
this.pkg = mapper.readValue(this.pkgJsonString, Package.class);
this.configValues = new ConfigValues();
if (this.configValuesString != null && StringUtils.hasText(configValuesString)) {
this.configValues.setRaw(this.configValuesString);
}
}
catch (IOException e) {
throw new SkipperException("Error processing config values", e);
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(predicateConfig)) {
this.configMap = JsonUtil.toEntity(predicateConfig,
new TypeReference<Map<String, Object>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(config)) {
this.configMap = JsonUtil.toEntity(config,
new TypeReference<Map<String, Object>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(checkpoint)) {
this.checkpointMap = JsonUtil.toEntity(
checkpoint, new TypeReference<Map<String, Object>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(sinks)) {
this.sinksList = JsonUtil.toEntity(sinks, new TypeReference<List<String>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(details)) {
this.detailsMap = JsonUtil.toEntity(details,
new TypeReference<Map<String, Object>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(details)) {
this.detailsMap = JsonUtil.toEntity(
details, new TypeReference<Map<String, Object>>() {
});
}
if (!StringUtils.isEmpty(out)) {
this.outList = JsonUtil.toEntity(
out, new TypeReference<List<Map<String, Object>>>() {
});
}
}
@PostLoad
public void load() throws IOException {
if (!StringUtils.isEmpty(config)) {
this.configMap = JsonUtil.toEntity(config,
new TypeReference<Map<String, Object>>() {
});
}
}
@PostLoad
public void load() throws IOException {
super.load();
if (!StringUtils.isEmpty(ruleDescription)) {
this.ruleDescriptionMap = JsonUtil.toEntity(ruleDescription,
new TypeReference<Map<String, Object>>() {
});
}
}
/**
* <p>
* Method called by the JPA layer after loading the persisted object.
* </p>
*/
@PostLoad
@SuppressWarnings("unused")
private void loadState()
{
if (this.permission != null)
throw PicketBoxMessages.MESSAGES.aclEntryPermissionAlreadySet();
this.permission = new CompositeACLPermission(this.bitMask);
}
/**
* Post-load callback method initializes the allocation table if it not populated already
* for the entity
*/
@PostLoad
void initialize() {
if (this.allocated == null) {
this.allocated = new long[this.section.getNumberOfRows()][this.section.getRowCapacity()];
for (long[] seatStates : allocated) {
Arrays.fill(seatStates, 0l);
}
}
}
/**
* Post-load callback method initializes the allocation table if it not populated already
* for the entity
*/
@PostLoad
void initialize() {
if (this.allocated == null) {
this.allocated = new long[this.section.getNumberOfRows()][this.section.getRowCapacity()];
for (long[] seatStates : allocated) {
Arrays.fill(seatStates, 0l);
}
}
}
/**
* Post-load callback method initializes the allocation table if it not populated already
* for the entity
*/
@PostLoad
void initialize() {
if (this.allocated == null) {
this.allocated = new long[this.section.getNumberOfRows()][this.section.getRowCapacity()];
for (long[] seatStates : allocated) {
Arrays.fill(seatStates, 0l);
}
}
}
@PostLoad
@PostPersist
public void inject(Object object) {
AutowireCapableBeanFactory beanFactory = get().getBeanFactory();
if(beanFactory == null) {
LOG.warn("Bean Factory not set! Depdendencies will not be injected into: '{}'", object);
return;
}
LOG.debug("Injecting dependencies into entity: '{}'.", object);
beanFactory.autowireBean(object);
}
/**
* Sets {@link #street} after loading the entity from Cloud SQL.
*
* <p>This callback method is used by Hibernate to set {@link #street} field as it is not
* persisted in Cloud SQL. We are doing this because the street list field is exposed by Address
* class and is used everywhere in our code base. Also, setting/reading a list of strings is more
* convenient.
*/
@PostLoad
void postLoad() {
street =
streetLine1 == null
? null
: Stream.of(streetLine1, streetLine2, streetLine3)
.filter(Objects::nonNull)
.collect(toImmutableList());
}
@PostLoad
void setCurrencyScale() {
moneyMap
.entrySet()
.forEach(
entry -> {
Money money = entry.getValue();
if (!money.toBigMoney().isCurrencyScale()) {
CurrencyUnit currency = money.getCurrencyUnit();
BigDecimal amount = money.getAmount().setScale(currency.getDecimalPlaces());
entry.setValue(Money.of(currency, amount));
}
});
}
@PostLoad
private void postLoad() {
if (userId == null) {
userIdHolder = "*";
} else {
userIdHolder = userId;
}
}
@PostLoad
@PostUpdate
@PostPersist
private void postLoadAttributes() {
if (dbAttributes != null) {
attributes =
dbAttributes.values().stream().collect(toMap(attr -> attr.name, attr -> attr.values));
}
}
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
Rubric rubric = getRubric();
if (rubric != null && rubric.getMetadata().isShared()) {
getMetadata().setShared(true);
}
}
@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;
}
}
}
}
@PostLoad
@PostUpdate
public void determineSharedParentStatus() {
Criterion criterion = getCriterion();
if (criterion != null) {
Rubric rubric = criterion.getRubric();
if (rubric != null && rubric.getMetadata().isShared()) {
getMetadata().setShared(true);
}
}
}
@PostLoad
public void handleDelta(final Object entity) {
SalesOrderHeader so = (SalesOrderHeader) entity;
if(so == null || so.getCreationDate() == null) {
return;
} else if (so.getCreationDate().getTime().getTime() < ODataJPATombstoneContext.getDeltaTokenUTCTimeStamp()) {
return;
} else {
addToDelta(entity, ENTITY_NAME);
}
}