Search in sources :

Example 1 with Expiration

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;
}
Also used : Getter(io.jans.orm.reflect.property.Getter) Expiration(io.jans.orm.annotation.Expiration) JsonObject(io.jans.orm.annotation.JsonObject) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Aggregations

Expiration (io.jans.orm.annotation.Expiration)1 JsonObject (io.jans.orm.annotation.JsonObject)1 MappingException (io.jans.orm.exception.MappingException)1 Getter (io.jans.orm.reflect.property.Getter)1 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)1