use of io.jans.orm.annotation.Expiration in project jans by JanssenProject.
the class BaseEntryManager method getExpirationValue.
protected <T> Integer getExpirationValue(Object entry, Class<T> entryClass, boolean merge) {
// Check if entry has Expiration property
PropertyAnnotation expirationProperty = getExpirationProperty(entryClass);
if (expirationProperty == null) {
return null;
}
String expirationPropertyName = expirationProperty.getPropertyName();
Expiration expirationAnnotation = (Expiration) ReflectHelper.getAnnotationByType(expirationProperty.getAnnotations(), Expiration.class);
if (merge && expirationAnnotation.ignoreDuringUpdate()) {
return null;
}
if (expirationPropertyName == null) {
// No entry expiration property
return null;
}
// Get Expiration value
Getter expirationGetter = getGetter(entryClass, expirationPropertyName);
if (expirationGetter == null) {
throw new MappingException("Entry should has getter for property " + expirationGetter);
}
Class<?> propertyType = expirationGetter.getReturnType();
if (!((propertyType == Integer.class) || (propertyType == Integer.TYPE))) {
throw new MappingException("Entry expiration property should has Integer type. Property: '" + expirationGetter + "'");
}
Object expirationValue = expirationGetter.get(entry);
if (expirationValue == null) {
// No entry expiration or null
return null;
}
Integer resultExpirationValue;
if (expirationValue instanceof Integer) {
resultExpirationValue = (Integer) expirationValue;
} else {
resultExpirationValue = Integer.valueOf((int) expirationValue);
}
// TTL can't be negative
if (resultExpirationValue < 0) {
resultExpirationValue = 0;
}
return resultExpirationValue;
}
Aggregations