def test_hi_level_transaction(self):

        factory = pyorient.OrientDB('localhost', 2424)

        factory.get_message( pyorient.CONNECT ).prepare( ("root", "root") )\
            .send().fetch_response()

        db_name = 'test_transactions'

        exists = factory.get_message( pyorient.DB_EXIST )\
            .prepare( [db_name, pyorient.STORAGE_TYPE_MEMORY] )\
            .send().fetch_response()

        print("Before %r" % exists)
        try:
            ( factory.get_message( pyorient.DB_DROP ) ).prepare([db_name]) \
                .send().fetch_response()
            assert True
        except pyorient.PyOrientCommandException as e:
            print(str(e))
        finally:
            ( factory.get_message( pyorient.DB_CREATE ) ).prepare(
                (db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY)
            ).send().fetch_response()

        msg = factory.get_message( pyorient.DB_OPEN )
        cluster_info = msg.prepare(
            (db_name, "admin", "admin", pyorient.DB_TYPE_GRAPH, "")
        ).send().fetch_response()

            #######################################

        # execute real create
        rec = { 'alloggio': 'baita', 'lavoro': 'no', 'vacanza': 'lago' }
        rec_position = ( factory.get_message(pyorient.RECORD_CREATE) )\
            .prepare( ( 3, rec ) )\
            .send().fetch_response()

        # prepare for an update
        rec3 = { 'alloggio': 'albergo', 'lavoro': 'ufficio', 'vacanza': 'montagna' }
        update_success = ( factory.get_message(pyorient.RECORD_UPDATE) )\
            .prepare( ( 3, rec_position._rid, rec3, rec_position._version ) )

        # prepare transaction
        rec1 = { 'alloggio': 'casa', 'lavoro': 'ufficio', 'vacanza': 'mare' }
        rec_position1 = ( factory.get_message(pyorient.RECORD_CREATE) )\
            .prepare( ( -1, rec1 ) )

        rec2 = { 'alloggio': 'baita', 'lavoro': 'no', 'vacanza': 'lago' }
        rec_position2 = ( factory.get_message(pyorient.RECORD_CREATE) )\
            .prepare( ( -1, rec2 ) )


        # create another real record
        rec = { 'alloggio': 'baita', 'lavoro': 'no', 'vacanza': 'lago' }
        rec_position = ( factory.get_message(pyorient.RECORD_CREATE) )\
            .prepare( ( 3, rec ) )\
            .send().fetch_response()

        delete_msg = ( factory.get_message(pyorient.RECORD_DELETE) )
        delete_msg.prepare( ( 3, rec_position._rid ) )


        tx = ( factory.get_message(pyorient.TX_COMMIT) )
        tx.begin()
        tx.attach( rec_position1 )
        tx.attach( rec_position1 )
        tx.attach( rec_position2 )
        tx.attach( update_success )
        tx.attach( delete_msg )
        res = tx.commit()

        for k, v in res.items():
            print(k + " -> " + v.vacanza)

        assert len(res) == 4
        assert res["#3:0"].vacanza == 'montagna'
        assert res["#3:2"].vacanza == 'mare'
        assert res["#3:3"].vacanza == 'mare'
        assert res["#3:4"].vacanza == 'lago'

        sid = ( factory.get_message(pyorient.CONNECT) ).prepare( ("root", "root") )\
            .send().fetch_response()

        ( factory.get_message(pyorient.DB_DROP) ).prepare(
            [db_name, pyorient.STORAGE_TYPE_MEMORY ]) \
            .send().fetch_response()
dataset/ETHPy150Open mogui/pyorient/tests/test_Factory_and_usage.py/CommandTestCase.test_hi_level_transaction/original