Search in sources :

Example 6 with XXDBBase

use of org.apache.ranger.entity.XXDBBase in project ranger by apache.

the class TestRangerBizUtil method testGetMObject_NoObjId.

@Test
public void testGetMObject_NoObjId() {
    XXDBBase mObjChk = rangerBizUtil.getMObject(RangerCommonEnums.CLASS_TYPE_USER_PROFILE, null);
    Assert.assertNull(mObjChk);
}
Also used : XXDBBase(org.apache.ranger.entity.XXDBBase) Test(org.junit.Test)

Example 7 with XXDBBase

use of org.apache.ranger.entity.XXDBBase in project ranger by apache.

the class JPABeanCallbacks method onPreUpdate.

// @PostPersist
// void onPostPersist(Object o) {
// if (o != null && o instanceof MBase) {
// MBase entity = (MBase) o;
// if (logger.isDebugEnabled()) {
// logger.debug("DBChange.create:class=" + o.getClass().getName()
// + entity.getId());
// }
// 
// }
// }
// @PostLoad void onPostLoad(Object o) {}
@PreUpdate
void onPreUpdate(Object o) {
    try {
        if (o != null && o instanceof XXDBBase) {
            XXDBBase entity = (XXDBBase) o;
            entity.setUpdateTime(DateUtil.getUTCDate());
        }
    } catch (Throwable t) {
        logger.error(t);
    }
}
Also used : XXDBBase(org.apache.ranger.entity.XXDBBase) PreUpdate(javax.persistence.PreUpdate)

Example 8 with XXDBBase

use of org.apache.ranger.entity.XXDBBase in project ranger by apache.

the class JPABeanCallbacks method onPrePersist.

@PrePersist
void onPrePersist(Object o) {
    try {
        if (o != null && o instanceof XXDBBase) {
            XXDBBase entity = (XXDBBase) o;
            entity.setUpdateTime(DateUtil.getUTCDate());
            RangerSecurityContext context = RangerContextHolder.getSecurityContext();
            if (context != null) {
                UserSessionBase userSession = context.getUserSession();
                if (userSession != null) {
                    entity.setAddedByUserId(userSession.getUserId());
                    entity.setUpdatedByUserId(userSession.getUserId());
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Security context not found for this request. obj=" + o, new Throwable());
                }
            }
        }
    } catch (Throwable t) {
        logger.error(t);
    }
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) XXDBBase(org.apache.ranger.entity.XXDBBase) UserSessionBase(org.apache.ranger.common.UserSessionBase) PrePersist(javax.persistence.PrePersist)

Aggregations

XXDBBase (org.apache.ranger.entity.XXDBBase)8 Test (org.junit.Test)4 BaseDao (org.apache.ranger.common.db.BaseDao)2 XXAsset (org.apache.ranger.entity.XXAsset)2 PrePersist (javax.persistence.PrePersist)1 PreUpdate (javax.persistence.PreUpdate)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)1 VXAsset (org.apache.ranger.view.VXAsset)1 VXString (org.apache.ranger.view.VXString)1