Esempio n. 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();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Close the given container, created via the given dataSource, if
 /// it is not managed externally (i.e. not bound to the thread)
 /// </summary>
 public static void DisposeConnection(ObjectContainer container, IDb4oDataSource dataSource)
 {
     logger.Debug("Dispose Connection");
     try{
         DoDisposeConnection(container, dataSource);
     } catch (Exception ex) {
         logger.Error("Cannot dispose connection", ex);
         throw TranslateException(ex);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// <p>
 /// Gets a connection from the given Db4oDataSource. Additionnally, it changes
 /// any DB4o Exception into the Spring.NET Hierarchy of Data Access Exceptions.
 /// </p>
 /// <p> Is Aware of corresponding connections bound to the current thread when using
 /// a TransactionManager. It will bind the connection to the current thread
 /// if Transaction Synchronization is active
 /// <p>
 /// </summary>
 public static ObjectContainer GetConnection(IDb4oDataSource dataSource)
 {
     try{
         logger.Debug("GetConnection");
         return(DoGetConnection(dataSource));
     } catch (Exception ex) {
         logger.Error("Error Creating DB4o Connection", ex);
         // and translate exception
         throw TranslateException(ex);
     }
 }
Esempio n. 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);
        }
 public Db4oTemplate(IDb4oDataSource dataSource)
 {
     base.DataSource = dataSource;
     AfterPropertiesSet();
 }
Esempio n. 6
0
 public ObjectContainerSynchronization(ObjectContainerHolder holder, IDb4oDataSource dataSource)
 {
     _Holder     = holder;
     _DataSource = dataSource;
 }
 public Db4oPlatformTransactionManager(IDb4oDataSource dataSource) : this()
 {
     _DataSource = DataSource;
 }