Example usage for org.hibernate.persister.entity EntityPersister getVersionProperty

List of usage examples for org.hibernate.persister.entity EntityPersister getVersionProperty

Introduction

In this page you can find the example usage for org.hibernate.persister.entity EntityPersister getVersionProperty.

Prototype

int getVersionProperty();

Source Link

Document

If #isVersioned() , then what is the index of the property holding the locking value.

Usage

From source file:com.mg.framework.service.HibernateListenerInjectorImpl.java

License:Open Source License

private void setUpdatedAttributes(PersistentObject entity, Object[] state, EntityPersister entityPersister) {
    String[] propertyNames = entityPersister.getPropertyNames();
    int versionProperty = entityPersister.getVersionProperty();
    for (int i = 0, len = propertyNames.length; i < len; i++) {
        if (versionProperty == i) //http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4535
            continue;

        String name = propertyNames[i];

        Type type = entityPersister.getPropertyType(name);
        //  ??  , ..  ? ?  
        if (type.isCollectionType() || type.isEntityType())
            continue;

        Object valueEntity = entity.getAttribute(name);
        Object value = state[i];/*  ww w . j  av a 2s.  c  om*/
        if (valueEntity == null) {
            if (value != null)
                state[i] = null;
        } else if (value == null || !value.equals(valueEntity))
            state[i] = valueEntity;
    }
}

From source file:corner.orm.hibernate.expression.NewExpressionExample.java

License:Apache License

public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {

    EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
    String[] propertyNames = meta.getPropertyNames();
    Type[] propertyTypes = meta.getPropertyTypes();
    //TODO: get all properties, not just the fetched ones!
    Object[] values = meta.getPropertyValues(entity, getEntityMode(criteria, criteriaQuery));
    List<TypedValue> list = new ArrayList<TypedValue>();
    for (int i = 0; i < propertyNames.length; i++) {
        Object value = values[i];
        Type type = propertyTypes[i];
        String name = propertyNames[i];

        boolean isPropertyIncluded = i != meta.getVersionProperty() && isPropertyIncluded(value, name, type);

        if (isPropertyIncluded) {
            if (propertyTypes[i].isComponentType()) {
                addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria,
                        criteriaQuery);//from ww w.j  ava 2 s .c o  m
            } else {
                addPropertyTypedValue(name, value, type, list);
            }
        }
    }
    return (TypedValue[]) list.toArray(TYPED_VALUES);
}

From source file:fr.keyconsulting.oliphant.NotifyListener.java

License:Open Source License

public boolean isKnownToBeStaleInL2(Object object, EventSource session) {
    final EntityPersister persister = sessionFactory.getEntityPersister(session.getEntityName(object));
    String uid = getUid(object, session);
    if (!versions.containsKey(uid)) {
        return false;
    }/* w  ww . j  a  v a2  s  . c  o  m*/
    if (persister.isVersioned()) {
        if (persister.hasCache() && session.getCacheMode().isGetEnabled()) {
            final EntityRegionAccessStrategy cacheAccessStrategy = persister.getCacheAccessStrategy();
            if (cacheAccessStrategy == null) {
                return false;
            }
            final CacheKey ck = new CacheKey(session.getIdentifier(object), persister.getIdentifierType(),
                    persister.getRootEntityName(), session.getEntityMode(), session.getFactory());
            CacheEntry cachedObject = (CacheEntry) cacheAccessStrategy.get(ck, Long.MAX_VALUE);
            if (cachedObject == null) {
                return false;
            }
            if (Base64.encodeBytes(cachedObject.getDisassembledState()[persister.getVersionProperty()]
                    .toString().getBytes()) != versions.get(uid)) {
                return true;
            }
        }
    }
    return false;
}