github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/txn/txnimpl/txn.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package txnimpl
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/container/types"
    19  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog"
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/handle"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/logstore/entry"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnbase"
    25  )
    26  
    27  type txnImpl struct {
    28  	*txnbase.Txn
    29  	catalog *catalog.Catalog
    30  }
    31  
    32  var TxnFactory = func(catalog *catalog.Catalog) txnbase.TxnFactory {
    33  	return func(mgr *txnbase.TxnManager, store txnif.TxnStore, txnId []byte,
    34  		start types.TS, info []byte) txnif.AsyncTxn {
    35  		return newTxnImpl(catalog, mgr, store, txnId, start, info)
    36  	}
    37  }
    38  
    39  func newTxnImpl(catalog *catalog.Catalog, mgr *txnbase.TxnManager, store txnif.TxnStore,
    40  	txnId []byte, start types.TS, info []byte) *txnImpl {
    41  	impl := &txnImpl{
    42  		Txn:     txnbase.NewTxn(mgr, store, txnId, start, info),
    43  		catalog: catalog,
    44  	}
    45  	return impl
    46  }
    47  
    48  func (txn *txnImpl) CreateDatabase(name, createSql string) (db handle.Database, err error) {
    49  	return txn.Store.CreateDatabase(name, createSql)
    50  }
    51  
    52  func (txn *txnImpl) CreateDatabaseWithID(name, createSql string, id uint64) (db handle.Database, err error) {
    53  	return txn.Store.CreateDatabaseWithID(name, createSql, id)
    54  }
    55  
    56  func (txn *txnImpl) DropDatabase(name string) (db handle.Database, err error) {
    57  	return txn.Store.DropDatabase(name)
    58  }
    59  
    60  func (txn *txnImpl) DropDatabaseByID(id uint64) (db handle.Database, err error) {
    61  	return txn.Store.DropDatabaseByID(id)
    62  }
    63  
    64  func (txn *txnImpl) UnsafeGetDatabase(id uint64) (db handle.Database, err error) {
    65  	return txn.Store.UnsafeGetDatabase(id)
    66  }
    67  
    68  func (txn *txnImpl) UnsafeGetRelation(dbId, id uint64) (rel handle.Relation, err error) {
    69  	return txn.Store.UnsafeGetRelation(dbId, id)
    70  }
    71  
    72  func (txn *txnImpl) GetDatabase(name string) (db handle.Database, err error) {
    73  	return txn.Store.GetDatabase(name)
    74  }
    75  
    76  func (txn *txnImpl) GetDatabaseByID(id uint64) (db handle.Database, err error) {
    77  	return txn.Store.GetDatabaseByID(id)
    78  }
    79  
    80  func (txn *txnImpl) DatabaseNames() (names []string) {
    81  	return txn.Store.DatabaseNames()
    82  }
    83  
    84  func (txn *txnImpl) LogTxnEntry(dbId, tableId uint64, entry txnif.TxnEntry, readed []*common.ID) (err error) {
    85  	return txn.Store.LogTxnEntry(dbId, tableId, entry, readed)
    86  }
    87  
    88  func (txn *txnImpl) LogTxnState(sync bool) (logEntry entry.Entry, err error) {
    89  	return txn.Store.LogTxnState(sync)
    90  }