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.transaction; 021 022import org.slf4j.Logger; 023import org.slf4j.LoggerFactory; 024 025import net.sf.jkniv.asserts.Assertable; 026import net.sf.jkniv.asserts.AssertsFactory; 027import net.sf.jkniv.whinstone.ConnectionAdapter; 028 029/** 030 * 031 * Hold the JDBC connection and transaction status association with a repository context {@code name}. 032 * 033 * @author Alisson Gomes 034 * 035 */ 036public class TransactionContext 037{ 038 private final static Logger LOG = LoggerFactory.getLogger(TransactionContext.class); 039 private final static Assertable NOT_NULL = AssertsFactory.getNotNull(); 040 private final String name; 041 private final ConnectionAdapter conn; 042 private Transactional tx; 043 044 public TransactionContext() 045 { 046 this("Empty", null, null); 047 } 048 049 public TransactionContext(String name, Transactional tx, ConnectionAdapter conn) 050 { 051 NOT_NULL.verify(name, tx, conn); 052 this.name = name; 053 this.tx = tx; 054 this.conn = conn; 055 //LOG.de 056 } 057 058 public boolean isActive() 059 { 060 return (tx.getStatus() == TransactionStatus.ACTIVE); 061 } 062 063 public String getName() 064 { 065 return name; 066 } 067 068 public Transactional getTransactional() 069 { 070 return tx; 071 } 072 073 public ConnectionAdapter getConnection() 074 { 075 return conn; 076 } 077}