fixed header

This commit is contained in:
Joern Muehlencord
2019-08-19 13:04:06 +02:00
parent 5a840dad7f
commit b138841faa
2 changed files with 75 additions and 50 deletions

View File

@ -1,46 +1,61 @@
package de.muehlencord.shared.db; /*
* Copyright 2019 joern.muehlencord.
import javax.annotation.Priority; *
import javax.inject.Inject; * Licensed under the Apache License, Version 2.0 (the "License");
import javax.interceptor.AroundInvoke; * you may not use this file except in compliance with the License.
import javax.interceptor.Interceptor; * You may obtain a copy of the License at
import javax.interceptor.InvocationContext; *
import javax.persistence.EntityManager; * http://www.apache.org/licenses/LICENSE-2.0
import javax.transaction.Transactional; *
import static javax.transaction.Transactional.TxType.REQUIRED; * Unless required by applicable law or agreed to in writing, software
import org.slf4j.Logger; * distributed under the License is distributed on an "AS IS" BASIS,
import org.slf4j.LoggerFactory; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
/** * limitations under the License.
* */
* @author Joern Muehlencord <joern at muehlencord.de> package de.muehlencord.shared.db;
*/
@Transactional(value = REQUIRED) import javax.annotation.Priority;
@Interceptor import javax.inject.Inject;
@Priority(value = ApplicationTransactionJoinInterceptor.PRIORITY) import javax.interceptor.AroundInvoke;
public class ApplicationTransactionJoinInterceptor { import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationTransactionJoinInterceptor.class); import javax.persistence.EntityManager;
import javax.transaction.Transactional;
// attach behind the interceptor of the container import static javax.transaction.Transactional.TxType.REQUIRED;
public static final int PRIORITY = Interceptor.Priority.PLATFORM_BEFORE + 250; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Inject
@ApplicationPU /**
private EntityManager em; *
* @author Joern Muehlencord <joern at muehlencord.de>
@AroundInvoke */
public Object joinTransaction(InvocationContext context) throws Exception { @Transactional(value = REQUIRED)
if (em == null) { @Interceptor
return context.proceed(); @Priority(value = ApplicationTransactionJoinInterceptor.PRIORITY)
} else { public class ApplicationTransactionJoinInterceptor {
if (em.isJoinedToTransaction()) {
LOGGER.trace("transaction already joined"); private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationTransactionJoinInterceptor.class);
} else {
LOGGER.trace("joining transaction"); // attach behind the interceptor of the container
em.joinTransaction(); public static final int PRIORITY = Interceptor.Priority.PLATFORM_BEFORE + 250;
}
} @Inject
return context.proceed(); @ApplicationPU
} private EntityManager em;
}
@AroundInvoke
public Object joinTransaction(InvocationContext context) throws Exception {
if (em == null) {
return context.proceed();
} else {
if (em.isJoinedToTransaction()) {
LOGGER.trace("transaction already joined");
} else {
LOGGER.trace("joining transaction");
em.joinTransaction();
}
}
return context.proceed();
}
}

View File

@ -1,7 +1,17 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright 2019 joern.muehlencord.
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package de.muehlencord.shared.db; package de.muehlencord.shared.db;