001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone.jpa2.transaction; 021 022import org.slf4j.Logger; 023import org.slf4j.LoggerFactory; 024 025import net.sf.jkniv.sqlegance.transaction.TransactionType; 026import net.sf.jkniv.whinstone.transaction.TransactionStatus; 027import net.sf.jkniv.whinstone.transaction.Transactional; 028 029public class EmptyTransactionAdapter implements Transactional 030{ 031 private final static Logger LOG = LoggerFactory.getLogger(EmptyTransactionAdapter.class); 032 033 private final static EmptyTransactionAdapter EMPTY_TRANSACTION_ADAPTER = new EmptyTransactionAdapter(); 034 035 public static Transactional empty() { 036 return EMPTY_TRANSACTION_ADAPTER; 037 } 038 /** 039 * Create an empty transaction adapter for JPA Entity Transaction 040 */ 041 private EmptyTransactionAdapter() 042 { 043 } 044 045 @Override 046 public TransactionType geTransactionType() 047 { 048 return TransactionType.GLOBAL; 049 } 050 051 @Override 052 public TransactionStatus getStatus() 053 { 054 return TransactionStatus.UNKNOWN; 055 } 056 057 @Override 058 public void begin() 059 { 060 LOG.warn("{} container managed cannot BEGIN transaction use @TransactionAttribute(TransactionAttributeType.REQUIRED)", geTransactionType()); 061 } 062 063 @Override 064 public void commit() 065 { 066 LOG.warn("{} container managed cannot COMMIT transaction use @TransactionAttribute(TransactionAttributeType.REQUIRED)", geTransactionType()); 067 } 068 069 @Override 070 public void rollback() 071 { 072 LOG.warn("JPA container managed cannot ROLLBACK transaction use @TransactionAttribute(TransactionAttributeType.REQUIRED)"); 073 } 074 075 @Override 076 public String toString() 077 { 078 return "EmptyTransactionAdapter [Status=" + getStatus() + ", transactionType="+geTransactionType()+"]"; 079 } 080 081}