1 /* 2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2.0, 6 * as published by the Free Software Foundation. 7 * 8 * This program is also distributed with certain software (including 9 * but not limited to OpenSSL) that is licensed under separate terms, 10 * as designated in a particular file or component or in included license 11 * documentation. The authors of MySQL hereby grant you an additional 12 * permission to link the program and your derivative works with the 13 * separately licensed software that they have included with MySQL. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License, version 2.0, for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 package com.mysql.clusterj.tie; 26 27 import java.util.List; 28 29 import com.mysql.clusterj.core.store.Column; 30 31 import com.mysql.clusterj.core.util.I18NHelper; 32 import com.mysql.clusterj.core.util.Logger; 33 import com.mysql.clusterj.core.util.LoggerFactoryService; 34 import com.mysql.clusterj.tie.DbImpl.BufferManager; 35 36 import com.mysql.ndbjtie.ndbapi.NdbScanOperation; 37 38 /** 39 * 40 */ 41 class ScanResultDataImpl extends ResultDataImpl { 42 43 /** My message translator */ 44 static final I18NHelper local = I18NHelper 45 .getInstance(ScanResultDataImpl.class); 46 47 /** My logger */ 48 static final Logger logger = LoggerFactoryService.getFactory() 49 .getInstance(ScanResultDataImpl.class); 50 51 private NdbScanOperation ndbScanOperation = null; 52 53 54 /** Flags for iterating a scan */ 55 protected final int RESULT_READY = 0; 56 protected final int SCAN_FINISHED = 1; 57 protected final int CACHE_EMPTY = 2; 58 ScanResultDataImpl(NdbScanOperation ndbScanOperation, List<Column> storeColumns, int maximumColumnId, int bufferSize, int[] offsets, int[] lengths, int maximumColumnLength, BufferManager bufferManager)59 public ScanResultDataImpl(NdbScanOperation ndbScanOperation, List<Column> storeColumns, 60 int maximumColumnId, int bufferSize, int[] offsets, int[] lengths, int maximumColumnLength, 61 BufferManager bufferManager) { 62 super(ndbScanOperation, storeColumns, maximumColumnId, bufferSize, offsets, lengths, 63 bufferManager, false); 64 this.ndbScanOperation = ndbScanOperation; 65 } 66 67 @Override next()68 public boolean next() { 69 // NdbScanOperation may have many results. 70 boolean done = false; 71 boolean fetch = false; 72 boolean force = true; // always true for scans 73 while (!done) { 74 int result = ndbScanOperation.nextResult(fetch, force); 75 switch (result) { 76 case RESULT_READY: 77 return true; 78 case SCAN_FINISHED: 79 ndbScanOperation.close(true, true); 80 return false; 81 case CACHE_EMPTY: 82 fetch = true; 83 break; 84 default: 85 Utility.throwError(result, ndbScanOperation.getNdbError()); 86 } 87 } 88 return true; // this statement is needed to make the compiler happy but it's never executed 89 } 90 91 } 92