Beispiel #1
0
        /// <summary>
        /// Method DoReleaseConnection
        /// </summary>
        /// <param name="container">An ObjectContainer</param>
        /// <param name="dataSource">An IDb4oDataSource</param>
        private static void DoDisposeConnection(ObjectContainer container, IDb4oDataSource dataSource)
        {
            logger.Debug("DoDisposeConnection");

            if (container == null)
            {
                logger.Debug("Container is null, doing nothing");
                return;
            }

            if (dataSource != null)
            {
                logger.Debug("Data Source is not null, trying to release");
                ObjectContainerHolder holder = (ObjectContainerHolder)TransactionSynchronizationManager.GetResource(dataSource);

                if (holder != null)
                {
                    logger.Debug("holder is not null, releasing");
                    // should we make sure the connection is the right one ?
                    holder.Released();

                    // should not go further since we are in a transactional context
                    // => No connection closing directly
                    return;
                }

                logger.Debug("No transaction, closing the container");
                // no transactional context so
                // close the container
                container.close();
            }
        }
        /// <summary>
        /// Return the current transaction object.
        /// </summary>
        /// <returns>The current transaction object.</returns>
        /// <exception cref="Spring.Transaction.CannotCreateTransactionException">
        /// If transaction support is not available.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of lookup or system errors.
        /// </exception>
        protected override Object DoGetTransaction()
        {
            logger.Debug("Do Get Transaction");
            Db4oTransactionObject txObject   = new Db4oTransactionObject();
            ObjectContainerHolder contHolder = (ObjectContainerHolder)TransactionSynchronizationManager.GetResource(_DataSource);

            txObject.ObjectContainerHolder = contHolder;
            return(txObject);
        }
        /// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">
        /// Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
        /// </param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        /// <remarks>
        /// Transaction synchronization will already have been suspended.
        /// </remarks>
        /// <exception cref="Spring.Transaction.IllegalTransactionStateException">
        /// If suspending is not supported by the transaction manager implementation.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// in case of system errors.
        /// </exception>
        protected override Object DoSuspend(Object transaction)
        {
            logger.Debug("Do Suspend");
            Db4oTransactionObject txObject = (Db4oTransactionObject)transaction;

            txObject.ObjectContainerHolder = null;
            ObjectContainerHolder containerHolder = (ObjectContainerHolder)TransactionSynchronizationManager.GetResource(_DataSource);

            return(new SuspendedResourcesHolder(containerHolder));
        }
Beispiel #4
0
        /// <summary>
        /// Method DoGetConnection does the actual Connection creation/recuperation
        /// It throws the orgiginal DB4o Exceptions
        /// </summary>
        /// <param name="dataSource">An IDb4oDataSource</param>
        /// <returns>An ObjectContainer</retutns>
        private static ObjectContainer DoGetConnection(IDb4oDataSource dataSource)
        {
            logger.Debug("Do Get Connection");
            logger.Debug("GetResource from TransactionSynchronizationManager");
            ObjectContainerHolder holder = (ObjectContainerHolder )TransactionSynchronizationManager.GetResource(dataSource);

            ObjectContainer container;

            if (holder != null)
            {
                logger.Debug("ObjectContainerHolder exists");
                holder.Requested();
                if (holder.ObjectContainer == null)
                {
                    logger.Debug("No connection inside the ObjectContainerHolder");
                    logger.Debug("Creating One");
                    holder.ObjectContainer = dataSource.GetConnection();
                }
                container = holder.ObjectContainer;
            }
            else
            {
                // the connection should be created
                logger.Debug("The Holder does not exist. It will be created");
                container = dataSource.GetConnection();
                if (TransactionSynchronizationManager.SynchronizationActive)
                {
                    logger.Debug("Registerbe increaseing transaction synchronization");
                    logger.Debug("Will use the same connection for further DB4o actions within the transaction");
                    logger.Debug("Thread-bound object will get removed by synchronization at transaction completion");
                    holder = new ObjectContainerHolder(container);
                    holder.SynchronizedWithTransaction = true;
                    holder.Requested();
                    TransactionSynchronizationManager.RegisterSynchronization(
                        new ObjectContainerSynchronization(holder, dataSource));
                    TransactionSynchronizationManager.BindResource(dataSource, holder);
                }
            }

            return(container);
        }
        /// <summary>
        /// Begin a new transaction with the given transaction definition.
        /// </summary>
        /// <param name="transaction">
        /// Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
        /// </param>
        /// <param name="definition">
        /// <see cref="Spring.Transaction.ITransactionDefinition"/> instance, describing
        /// propagation behavior, isolation level, timeout etc.
        /// </param>
        /// <remarks>
        /// Does not have to care about applying the propagation behavior,
        /// as this has already been handled by this abstract manager.
        /// </remarks>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of creation or system errors.
        /// </exception>
        protected override void DoBegin(Object transaction, ITransactionDefinition definition)
        {
            logger.Debug("Do Begin Transaction");

            if (definition.TransactionIsolationLevel != IsolationLevel.Unspecified)
            {
                logger.Error("Db4o Does not support Isolation Level");
                throw new CannotCreateTransactionException("Db4o does not support an isolation level concept");
            }

            try{
                Db4oTransactionObject txObject = (Db4oTransactionObject)transaction;
                if (txObject.ObjectContainerHolder == null)
                {
                    // use the given container
                    logger.Warn("Are we supposed to  be in this case ??");
                    ObjectContainer container = Db4oUtils.GetConnection(_DataSource);
                    logger.Debug("Using given objectContainer ["
                                 + container
                                 + "] for the current thread transaction");

                    txObject.ObjectContainerHolder = new ObjectContainerHolder(container);
                }

                ObjectContainerHolder holder = txObject.ObjectContainerHolder;

                //holder. set readonly ??
                if (definition.TransactionTimeout != -1)
                {
                    logger.Debug("Setting Transaction Timeout : " + definition.TransactionTimeout);
                    holder.TimeoutInSeconds = definition.TransactionTimeout;
                }
            } catch (Exception e) {
                logger.Error("Cannot create transaction");
                throw new CannotCreateTransactionException("Cannot create transaction", e);
            }
        }
Beispiel #6
0
 public ObjectContainerSynchronization(ObjectContainerHolder holder, IDb4oDataSource dataSource)
 {
     _Holder     = holder;
     _DataSource = dataSource;
 }
 public SuspendedResourcesHolder(ObjectContainerHolder containerHolder)
 {
     this._ObjectContainerHolder = containerHolder;
 }