@Override public void add(PropertyData propertyData) { if ( this.propertyData != null ) { throw new AuditException( "Only one property can be added!" ); } this.propertyData = propertyData; }
@Override public void add(PropertyData propertyData) { if ( this.propertyData != null ) { throw new AuditException( "Only one property can be added!" ); } this.propertyData = propertyData; }
private Object getComponentInstance(Object dataObject) { if ( dataObject != null ) { return dataObject; } return AccessController.doPrivileged( new PrivilegedAction<Object>() { @Override public Object run() { try { return ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); } catch ( InstantiationException e ) { throw new AuditException( e ); } catch ( IllegalAccessException e ) { throw new AuditException( e ); } catch ( InvocationTargetException e ) { throw new AuditException( e ); } } } ); }
@Override public T run() { try { return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance(); } catch (InstantiationException e) { throw new AuditException( e ); } catch (IllegalAccessException e) { throw new AuditException( e ); } catch (InvocationTargetException e) { throw new AuditException( e ); } } }
protected AbstractCollectionMapper( CommonCollectionMapperData commonCollectionMapperData, Class<? extends T> collectionClass, Class<? extends T> proxyClass, boolean ordinalInId, boolean revisionTypeInId) { this.commonCollectionMapperData = commonCollectionMapperData; this.collectionClass = collectionClass; this.ordinalInId = ordinalInId; this.revisionTypeInId = revisionTypeInId; try { proxyConstructor = proxyClass.getConstructor( Initializor.class ); } catch (NoSuchMethodException e) { throw new AuditException( e ); } }
@Override public T run() { try { return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance(); } catch (InstantiationException e) { throw new AuditException( e ); } catch (IllegalAccessException e) { throw new AuditException( e ); } catch (InvocationTargetException e) { throw new AuditException( e ); } } }
@Override protected SortedMap initializeCollection(int size) { if ( comparator == null ) { return super.initializeCollection( size ); } try { return collectionClass.getConstructor( Comparator.class ).newInstance( comparator ); } catch (InstantiationException e) { throw new AuditException( e ); } catch (IllegalAccessException e) { throw new AuditException( e ); } catch (NoSuchMethodException e) { throw new AuditException( e ); } catch (InvocationTargetException e) { throw new AuditException( e ); } }
@Override public Object run() { try { return ReflectHelper.getDefaultConstructor( componentClass ).newInstance(); } catch ( InstantiationException e ) { throw new AuditException( e ); } catch ( IllegalAccessException e ) { throw new AuditException( e ); } catch ( InvocationTargetException e ) { throw new AuditException( e ); } } }
@Override protected SortedSet initializeCollection(int size) { if ( comparator == null ) { return super.initializeCollection( size ); } try { return collectionClass.getConstructor( Comparator.class ).newInstance( comparator ); } catch (InstantiationException e) { throw new AuditException( e ); } catch (IllegalAccessException e) { throw new AuditException( e ); } catch (NoSuchMethodException e) { throw new AuditException( e ); } catch (InvocationTargetException e) { throw new AuditException( e ); } } }
public void cacheEntityState(Object id, String entityName, Object[] snapshot) { final Pair<String, Object> key = new Pair<>( entityName, id ); if ( entityStateCache.containsKey( key ) ) { throw new AuditException( "The entity [" + entityName + "] with id [" + id + "] is already cached." ); } entityStateCache.put( key, snapshot ); }
protected void checkIfTransactionInProgress(SessionImplementor session) { if ( !session.isTransactionInProgress() ) { // Historical data would not be flushed to audit tables if outside of active transaction // (AuditProcess#doBeforeTransactionCompletion(SessionImplementor) not executed). throw new AuditException( "Unable to create revision because of non-active transaction" ); } } }
@Override public Object run() { try { return ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance(); } catch ( Exception e ) { throw new AuditException( e ); } } }
@Override public CrossTypeRevisionChangesReader getCrossTypeRevisionChangesReader() throws AuditException { if ( !enversService.getGlobalConfiguration().isTrackEntitiesChangedInRevision() ) { throw new AuditException( "This API is designed for Envers default mechanism of tracking entities modified in a given revision." + " Extend DefaultTrackingModifiedEntitiesRevisionEntity, utilize @ModifiedEntityNames annotation or set " + "'org.hibernate.envers.track_entities_changed_in_revision' parameter to true." ); } return crossTypeRevisionChangesReader; }
public static void checkPropertyNotARelation( EnversService enversService, String entityName, String propertyName) throws AuditException { if ( enversService.getEntitiesConfigurations().get( entityName ).isRelation( propertyName ) ) { throw new AuditException( "This criterion cannot be used on a property that is " + "a relation to another property." ); } }
public static Class<?> getType(Class cls, PropertyData propertyData, ServiceRegistry serviceRegistry) { final Setter setter = getSetter( cls, propertyData, serviceRegistry ); if ( setter.getMethod() != null && setter.getMethod().getParameterCount() > 0 ) { return setter.getMethod().getParameterTypes()[0]; } final Field field = getField( cls, propertyData ); if ( field != null ) { return field.getType(); } throw new AuditException( String.format( Locale.ROOT, "Failed to determine type for field [%s] on class [%s].", propertyData.getName(), cls.getName() ) ); }
public static RelationDescription getRelatedEntity( EnversService enversService, String entityName, String propertyName) throws AuditException { RelationDescription relationDesc = enversService.getEntitiesConfigurations().getRelationDescription( entityName, propertyName ); if ( relationDesc == null ) { return null; } if ( relationDesc.getRelationType() == RelationType.TO_ONE ) { return relationDesc; } throw new AuditException( "This type of relation (" + entityName + "." + propertyName + ") isn't supported and can't be used in queries." ); }
@Override public Boolean run() { final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData, getServiceRegistry() ); final Setter setter = ReflectionTools.getSetter( obj.getClass(), idPropertyData, getServiceRegistry() ); try { final Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance(); boolean ret = true; for ( IdMapper idMapper : ids.values() ) { ret &= idMapper.mapToEntityFromMap( subObj, data ); } if ( ret ) { setter.set( obj, subObj, null ); } return ret; } catch (Exception e) { throw new AuditException( e ); } } }
@Override protected void addToQuery( EnversService enversService, AuditReaderImplementor versionsReader, String entityName, String alias, QueryBuilder qb, Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( enversService, versionsReader, entityName, propertyNameGetter ); RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { throw new AuditException( "The criterion can only be used on a property that is a relation to another property." ); } // todo: should this throw an error if qpdList is null? is it possible? List<QueryParameterData> qpdList = relatedEntity.getIdMapper().mapToQueryParametersFromId( propertyName ); if ( qpdList != null ) { QueryParameterData qpd = qpdList.iterator().next(); parameters.addWhereWithParams( alias, qpd.getQueryParameterName(), "in (", ids, ")" ); } } }
@Override protected void addToQuery( EnversService enversService, AuditReaderImplementor versionsReader, String entityName, String alias, QueryBuilder qb, Parameters parameters) { String propertyName = CriteriaTools.determinePropertyName( enversService, versionsReader, entityName, propertyNameGetter ); RelationDescription relatedEntity = CriteriaTools.getRelatedEntity( enversService, entityName, propertyName ); if ( relatedEntity == null ) { throw new AuditException( "This criterion can only be used on a property that is a relation to another property." ); } relatedEntity.getIdMapper().addIdEqualsToQuery( parameters, id, alias, null, equals ); } }
@Override public Object mapToObjectFromFullMap( EntityInstantiator entityInstantiator, Map<String, Object> data, Object dataObject, Number revision) { try { final Object componentInstance = getComponentInstance( dataObject ); delegate.mapToEntityFromMap( entityInstantiator.getEnversService(), componentInstance, data, null, entityInstantiator.getAuditReaderImplementor(), revision ); return componentInstance; } catch (AuditException e) { // just throw the AuditException without wrapping in another AuditException throw e; } catch (Exception e) { throw new AuditException( e ); } }