/// <summary> /// Execute a ADO.NET operation on a command object using an Object Callback. /// </summary> /// <remarks>This allows for implementing arbitrary data access operations /// on a single command within Spring's managed DB4o environment.</remarks> /// <param name="callback">The delegate called with a command object.</param> /// <returns>A result object returned by the action or null</returns> public Object Execute(IDb4oCallback callback) { logger.Debug("Execute Callback"); // get a possibly existing connection ObjectContainer container = Db4oUtils.GetConnection(DataSource); object result; try{ logger.Debug("DoInDb4o"); result = callback.DoInDb4o(container); } catch (Exception e) { logger.Error("Exception while executing in Db4o", e); throw ConvertDb4oAccessException(e); } // dispose from the connection Db4oUtils.DisposeConnection(container, DataSource); return(result); }
/// <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); } }
/// <summary> /// Convert the Db4o exception to an equivalent one from the /// the Spring Exception Hierarchy /// </summary> /// <returns> An exception from the /// <see cref="T:Spring.Dao.DataAccessException"> Spring DataAccessException Hierarchy </see> /// </returns> public DataAccessException ConvertDb4oAccessException(Exception ex) { logger.Debug("Converting Db4o to Spring Exception", ex); return(Db4oUtils.TranslateException(ex)); }