github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/lockbased_query_executer.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package lockbasedtxmgr 18 19 import ( 20 "github.com/hyperledger/fabric/common/ledger" 21 "github.com/hyperledger/fabric/common/util" 22 ) 23 24 // LockBasedQueryExecutor is a query executor used in `LockBasedTxMgr` 25 type lockBasedQueryExecutor struct { 26 helper *queryHelper 27 id string 28 } 29 30 func newQueryExecutor(txmgr *LockBasedTxMgr) *lockBasedQueryExecutor { 31 helper := &queryHelper{txmgr: txmgr, rwsetBuilder: nil} 32 id := util.GenerateUUID() 33 logger.Debugf("constructing new query executor [%s]", id) 34 return &lockBasedQueryExecutor{helper, id} 35 } 36 37 // GetState implements method in interface `ledger.QueryExecutor` 38 func (q *lockBasedQueryExecutor) GetState(ns string, key string) ([]byte, error) { 39 return q.helper.getState(ns, key) 40 } 41 42 // GetStateMultipleKeys implements method in interface `ledger.QueryExecutor` 43 func (q *lockBasedQueryExecutor) GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error) { 44 return q.helper.getStateMultipleKeys(namespace, keys) 45 } 46 47 // GetStateRangeScanIterator implements method in interface `ledger.QueryExecutor` 48 // startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key 49 // and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey 50 // can be supplied as empty strings. However, a full scan shuold be used judiciously for performance reasons. 51 func (q *lockBasedQueryExecutor) GetStateRangeScanIterator(namespace string, startKey string, endKey string) (ledger.ResultsIterator, error) { 52 return q.helper.getStateRangeScanIterator(namespace, startKey, endKey) 53 } 54 55 // ExecuteQuery implements method in interface `ledger.QueryExecutor` 56 func (q *lockBasedQueryExecutor) ExecuteQuery(namespace, query string) (ledger.ResultsIterator, error) { 57 return q.helper.executeQuery(namespace, query) 58 } 59 60 // Done implements method in interface `ledger.QueryExecutor` 61 func (q *lockBasedQueryExecutor) Done() { 62 logger.Debugf("Done with transaction simulation / query execution [%s]", q.id) 63 q.helper.done() 64 }