Merge branch 'master' into feature_enable_push_in_deployment_view

This commit is contained in:
Gaurav
2016-07-29 12:35:22 +02:00
7 changed files with 389 additions and 39 deletions

View File

@@ -46,6 +46,7 @@ import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler;
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
@@ -144,6 +145,14 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
return SecurityTokenGeneratorHolder.getInstance();
}
/**
* @return the singleton instance of the {@link EntityInterceptorHolder}
*/
@Bean
public EntityInterceptorHolder entityInterceptorHolder() {
return EntityInterceptorHolder.getInstance();
}
/**
* @return the singleton instance of the {@link CacheManagerHolder}
*/

View File

@@ -31,7 +31,8 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
*/
@MappedSuperclass
@Access(AccessType.FIELD)
@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class })
@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class,
EntityInterceptorListener.class })
public abstract class AbstractJpaBaseEntity implements BaseEntity {
private static final long serialVersionUID = 1L;

View File

@@ -0,0 +1,69 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.model;
import java.util.function.Consumer;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
import org.eclipse.hawkbit.repository.model.EntityInterceptor;
/**
* Entity listener which calls the callback's of all registered entity
* interceptors.
*/
public class EntityInterceptorListener {
@PrePersist
protected void prePersist(final Object entity) {
notifyAll(interceptor -> interceptor.prePersist(entity));
}
@PostPersist
protected void postPersist(final Object entity) {
notifyAll(interceptor -> interceptor.postPersist(entity));
}
@PostRemove
protected void postRemove(final Object entity) {
notifyAll(interceptor -> interceptor.postRemove(entity));
}
@PreRemove
protected void preRemove(final Object entity) {
notifyAll(interceptor -> interceptor.preRemove(entity));
}
@PostLoad
protected void postLoad(final Object entity) {
notifyAll(interceptor -> interceptor.postLoad(entity));
}
@PreUpdate
protected void preUpdate(final Object entity) {
notifyAll(interceptor -> interceptor.preUpdate(entity));
}
@PostUpdate
protected void postUpdate(final Object entity) {
notifyAll(interceptor -> interceptor.postUpdate(entity));
}
private void notifyAll(final Consumer<? super EntityInterceptor> action) {
EntityInterceptorHolder.getInstance().getEntityInterceptors().forEach(action);
}
}

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.model.helper;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.model.EntityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A singleton bean which holds the {@link EntityInterceptor} to have all
* interceptors in spring beans.
*
*/
public final class EntityInterceptorHolder {
private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder();
@Autowired(required = false)
private final List<EntityInterceptor> entityInterceptors = new ArrayList<>();
private EntityInterceptorHolder() {
}
/**
* @return the entity intreceptor holder singleton instance
*/
public static EntityInterceptorHolder getInstance() {
return SINGLETON;
}
public List<EntityInterceptor> getEntityInterceptors() {
return entityInterceptors;
}
}