javax.persistence.PostLoad Java Examples

The following examples show how to use javax.persistence.PostLoad. 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: Product.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #2
Source File: PeopleFlowBo.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * 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();
            }
        }
    }
}
 
Example #3
Source File: CheckingEntityListener.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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("数据验证失败!");
		}
	}
}
 
Example #4
Source File: WarpDbCRUDAndCallbackTest.java    From warpdb with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #5
Source File: TaskDefinition.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: Interceptor.java    From heimdall with Apache License 2.0 6 votes vote down vote up
@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;
     }
}
 
Example #7
Source File: AbstractRegisteredService.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #8
Source File: DomainBase.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #9
Source File: StreamingPreProcess.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void load() throws IOException {
    if (!StringUtils.isEmpty(details)) {
        this.detailsMap = JsonUtil.toEntity(details,
            new TypeReference<Map<String, Object>>() {
            });
    }
}
 
Example #10
Source File: Task.java    From spring-labs with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void afterLoad() {

	if (status == null) {
		status = Status.TODO;
	}
}
 
Example #11
Source File: SectionAllocation.java    From monolith with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example #12
Source File: SegmentPredicate.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void load() throws IOException {
    if (!StringUtils.isEmpty(config)) {
        this.configMap = JsonUtil.toEntity(config,
            new TypeReference<Map<String, Object>>() {
            });
    }
}
 
Example #13
Source File: AbstractJob.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void load() throws IOException {
    if (!StringUtils.isEmpty(predicateConfig)) {
        this.configMap = JsonUtil.toEntity(predicateConfig,
            new TypeReference<Map<String, Object>>() {
            });
    }
}
 
Example #14
Source File: Measure.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void load() throws IOException {
    if (!StringUtils.isEmpty(sinks)) {
        this.sinksList = JsonUtil.toEntity(sinks, new TypeReference<List<String>>() {
        });
    }
}
 
Example #15
Source File: DataSource.java    From griffin with Apache License 2.0 5 votes vote down vote up
@PostLoad
public void load() throws IOException {
    if (!StringUtils.isEmpty(checkpoint)) {
        this.checkpointMap = JsonUtil.toEntity(
            checkpoint, new TypeReference<Map<String, Object>>() {
            });
    }
}
 
Example #16
Source File: Release.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #17
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 #18
Source File: SectionAllocation.java    From monolith with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example #19
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 #20
Source File: SpringEntityListener.java    From example-ddd-with-spring-data-jpa with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
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 #22
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 #23
Source File: Address.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #24
Source File: JodaMoneyConverterTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@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));
            }
          });
}
 
Example #25
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 #26
Source File: SalesOrderTombstoneListener.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #27
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 #28
Source File: AbstractPermissions.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@PostLoad
private void postLoad() {
  if (userId == null) {
    userIdHolder = "*";
  } else {
    userIdHolder = userId;
  }
}
 
Example #29
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 #30
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);
    }
}