// returns 0 for OK, -1 for exception int ManagedDatasource::closeUnlocked(ExceptionSink *xsink) { int rc = 0; if (grabLock(xsink)) return -1; if (isOpen()) { if (isInTransaction()) { if (!wasConnectionAborted()) { // FIXME: check for statement xsink->raiseException("DATASOURCE-TRANSACTION-EXCEPTION", "%s:%s@%s: Datasource closed while in a transaction; transaction will be automatically rolled back and the lock released", getDriverName(), getUsernameStr().c_str(), getDBNameStr().c_str()); Datasource::rollback(xsink); } remove_thread_resource(this); setTransactionStatus(false); // force-exit the transaction lock forceReleaseLockIntern(); rc = -1; } Datasource::close(); } return rc; }
/*! * \brief This method creates a MockDataSourceTransactor * \return Returns a mocked DataSourceTransactor that has the required behavior for unittests */ te::da::MockDataSourceTransactor* createMockDataSourceTransactor() { te::da::MockDataSourceTransactor* mockDataSourceTransactor(new te::da::MockDataSourceTransactor()); EXPECT_CALL(*mockDataSourceTransactor, createDataSet(::testing::_, ::testing::_)).WillRepeatedly(::testing::Return()); EXPECT_CALL(*mockDataSourceTransactor, PrimaryKeyPtrReturn()).WillRepeatedly(::testing::Return(new te::da::PrimaryKey())); EXPECT_CALL(*mockDataSourceTransactor, execute(::testing::An<const std::string&>())).WillRepeatedly(::testing::Return()); EXPECT_CALL(*mockDataSourceTransactor, commit()).WillRepeatedly(::testing::Return()); EXPECT_CALL(*mockDataSourceTransactor, getLastGeneratedId()).WillRepeatedly(::testing::Return(1)); EXPECT_CALL(*mockDataSourceTransactor, PropertyPtrReturn()).WillRepeatedly(::testing::Return(nullptr)); EXPECT_CALL(*mockDataSourceTransactor, addPrimaryKey(::testing::An<const std::string&>(), ::testing::_)).WillRepeatedly(::testing::Return()); EXPECT_CALL(*mockDataSourceTransactor, addForeignKey(::testing::An<const std::string&>(), ::testing::_)).WillRepeatedly(::testing::Return()); EXPECT_CALL(*mockDataSourceTransactor, escape(::testing::An<const std::string&>())).WillRepeatedly(::testing::Return("")); EXPECT_CALL(*mockDataSourceTransactor, isInTransaction()).WillRepeatedly(::testing::Return(false)); EXPECT_CALL(*mockDataSourceTransactor, begin()).WillRepeatedly(::testing::Return()); /* Every time the mockDataSourceTransactor object calls a method that returns a DataSet * the actualy method called will be the createMockDataSet() that returns a * new mocked DataSet. * A new mocked object is needed in every call because TerraLib takes ownership from the pointer. */ EXPECT_CALL(*mockDataSourceTransactor, DataSetPtrReturn()).WillRepeatedly(::testing::Invoke(&createMockDataSet)); return mockDataSourceTransactor; }
void ManagedDatasource::cleanup(ExceptionSink *xsink) { // this thread has the transaction lock AutoLocker al(&ds_lock); assert(isInTransaction()); xsink->raiseException("DATASOURCE-TRANSACTION-EXCEPTION", "%s:%s@%s: TID %d terminated while in a transaction; transaction will be automatically rolled back and the lock released", getDriverName(), getUsernameStr().c_str(), getDBNameStr().c_str(), gettid()); Datasource::rollback(xsink); setTransactionStatus(false); releaseLockIntern(); }