def removeRow_throwsOptimisticLockException_shouldStillWork(self): if AllTests.db == AllTests.DB.HSQLDB: # HSQLDB doesn't support versioning, so this is to make the test # green. return DataGenerator.addVersionedData(self._connectionPool) tQuery = TableQuery('versioned', self._connectionPool, AllTests.sqlGen) tQuery.setVersionColumn('VERSION') container = SQLContainer(tQuery) row = container.getItem(container.firstItemId()) Assert.assertEquals('Junk', row.getItemProperty('TEXT').getValue()) # Update the version using another connection. conn = self._connectionPool.reserveConnection() stmt = conn.prepareStatement('UPDATE VERSIONED SET \"TEXT\" = ? WHERE \"ID\" = ?') stmt.setString(1, 'asdf') stmt.setObject(2, row.getItemProperty('ID').getValue()) stmt.executeUpdate() stmt.close() conn.commit() self._connectionPool.releaseConnection(conn) itemToRemove = container.firstItemId() # This is expected, refresh and try again. try: container.removeItem(itemToRemove) container.commit() except OptimisticLockException, e: container.rollback() container.removeItem(itemToRemove) container.commit()
def removeRow_versionSetAndEqualToDBValue_shouldSucceed(self): DataGenerator.addVersionedData(self._connectionPool) tQuery = TableQuery('versioned', self._connectionPool, AllTests.sqlGen) tQuery.setVersionColumn('VERSION') container = SQLContainer(tQuery) row = container.getItem(container.firstItemId()) Assert.assertEquals('Junk', row.getItemProperty('TEXT').getValue()) container.removeItem(container.firstItemId()) container.commit() conn = self._connectionPool.reserveConnection() stmt = conn.prepareStatement('SELECT * FROM VERSIONED WHERE \"TEXT\" = ?') stmt.setString(1, 'Junk') rs = stmt.executeQuery() Assert.assertFalse(rs.next()) rs.close() stmt.close() conn.commit() self._connectionPool.releaseConnection(conn)
def storeRow_versionSetAndLessThanDBValue_shouldThrowException(self): if AllTests.db == DB.HSQLDB: raise OptimisticLockException('HSQLDB doesn\'t support row versioning for optimistic locking - don\'t run this test.', None) DataGenerator.addVersionedData(self._connectionPool) tQuery = TableQuery('versioned', self._connectionPool, AllTests.sqlGen) tQuery.setVersionColumn('VERSION') container = SQLContainer(tQuery) row = container.getItem(container.firstItemId()) Assert.assertEquals('Junk', row.getItemProperty('TEXT').getValue()) row.getItemProperty('TEXT').setValue('asdf') # Update the version using another connection. conn = self._connectionPool.reserveConnection() stmt = conn.prepareStatement('UPDATE VERSIONED SET \"TEXT\" = ? WHERE \"ID\" = ?') stmt.setString(1, 'foo') stmt.setObject(2, row.getItemProperty('ID').getValue()) stmt.executeUpdate() stmt.close() conn.commit() self._connectionPool.releaseConnection(conn) container.commit()