/*
(non-Javadoc)

@see
com.impetus.client.hbase.admin.DataHandler#readDataByRange(java.lang.
String, java.lang.Class,
com.impetus.kundera.metadata.model.EntityMetadata, java.util.List,
byte[], byte[])
775015
@Override
    public List readDataByRange(String tableName, Class clazz, EntityMetadata m, byte[] startRow, byte[] endRow,
            String[] columns, FilterList f) throws IOException
    {
        List output = new ArrayList();
        HTableInterface hTable = null;
        Object entity = null;
        List<String> relationNames = m.getRelationNames();
        Filter filter = getFilter(m.getTableName());
        if (filter != null)
        {
            if (f == null)
            {
                f = new FilterList();
            }
            f.addFilter(filter);
        }
        // Load raw data from HBase
        hTable = gethTable(tableName);
        List<HBaseData> results = hbaseReader.loadAll(hTable, f, startRow, endRow, m.getTableName(), null, columns);
        output = onRead(tableName, clazz, m, output, hTable, entity, relationNames, results);

        return output;
    }
914448
private ProjectFile readDatabaseFile(InputStream inputStream) throws MPXJException
   {
      ProjectReader reader = new AstaDatabaseFileReader();
      addListeners(reader);
      return reader.read(inputStream);
   }
415680
private KeyedBackendSerializationProxy<K> readMetaData(StreamStateHandle metaStateHandle) throws Exception {

		FSDataInputStream inputStream = null;

		try {
			inputStream = metaStateHandle.openInputStream();
			cancelStreamRegistry.registerCloseable(inputStream);
			DataInputView in = new DataInputViewStreamWrapper(inputStream);
			return readMetaData(in);
		} finally {
			if (cancelStreamRegistry.unregisterCloseable(inputStream)) {
				inputStream.close();
			}
		}
	}
335281
private void onQuery(EntityMetadata m, Client client)
    {

        try
        {
            // Called only in case of standalone entity.
            FilterList filter = null;
            if (translator.getFilter() != null)
            {
                filter = new FilterList(translator.getFilter());
            }
            String[] columnAsArr = getColumnsAsArray();

            if (isFindKeyOnly(m, columnAsArr))
            {
                this.handler.setFilter(new KeyOnlyFilter());
            }

            if (filter == null && columns != null)
            {
                handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                        translator.getEndRow(), columnAsArr, null);
            }
            if (MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata()))
            {
                if (filter == null)
                {
                    // means complete scan without where clause, scan all
                    // records.
                    // findAll.
                    if (translator.isRangeScan())
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                                translator.getEndRow(), columnAsArr, null);
                    }
                    else
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, null, null, columnAsArr, null);
                    }
                }
                else
                {
                    // means WHERE clause is present.
                    if (translator.isRangeScan())
                    {
                        handler.readDataByRange(m.getSchema(), m.getEntityClazz(), m, translator.getStartRow(),
                                translator.getEndRow(), columnAsArr, filter);
                    }
                    else
                    {
                        // if range query. means query over id column. create
                        // range
                        // scan method.

                        handler.readData(m.getSchema(), entityMetadata.getEntityClazz(), entityMetadata, null,
                                m.getRelationNames(), filter, columnAsArr);
                    }
                }
            }
        }
        catch (IOException ioex)
        {
            log.error("Error while executing query{} , Caused by:", ioex);
            throw new QueryHandlerException("Error while executing , Caused by:", ioex);
        }
    }
378460
@Override
    public List<HBaseData> loadAll(HTableInterface hTable, Filter filter, byte[] startRow, byte[] endRow,
            String columnFamily, String qualifier, String[] columns) throws IOException
    {
        List<HBaseData> results = null;
        if (scanner == null)
        {
            Scan s = null;
            if (startRow != null && endRow != null && startRow.equals(endRow))
            {
                Get g = new Get(startRow);
                s = new Scan(g);
            }
            else if (startRow != null && endRow != null)
            {
                s = new Scan(startRow, endRow);
            }
            else if (startRow != null)
            {
                s = new Scan(startRow);
            }
            else if (endRow != null)
            {
                s = new Scan();
                s.setStopRow(endRow);
            }
            else
            {
                s = new Scan();
            }
            setScanCriteria(filter, columnFamily, qualifier, s, columns);
            scanner = hTable.getScanner(s);
            resultsIter = scanner.iterator();
        }
        return scanResults(null, results);
    }
453152
@Override
    public List<Object> findByRelation(String colName, Object colValue, Class entityClazz)
    {
        EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz);

        String columnFamilyName = m.getTableName();

        byte[] valueInBytes = HBaseUtils.getBytes(colValue);
        SingleColumnValueFilter f = new SingleColumnValueFilter(Bytes.toBytes(columnFamilyName),
                Bytes.toBytes(colName), CompareOp.EQUAL, valueInBytes);

        List output = new ArrayList();
        try
        {
            List<AbstractManagedType> subManagedType = getSubManagedType(entityClazz, m);

            if (!subManagedType.isEmpty())
            {
                for (AbstractManagedType subEntity : subManagedType)
                {
                    EntityMetadata subEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                            subEntity.getJavaType());
                    List results = ((HBaseDataHandler) handler).scanData(f, subEntityMetadata.getSchema(),
                            subEntityMetadata.getEntityClazz(), subEntityMetadata, columnFamilyName, colName);
                    if (!results.isEmpty())
                    {
                        output.addAll(results);
                    }
                }
            }
            else
            {
                return ((HBaseDataHandler) handler).scanData(f, m.getSchema(), entityClazz, m, columnFamilyName,
                        colName);
            }
        }
        catch (IOException ioe)
        {
            log.error("Error during find By Relation, Caused by: .", ioe);
            throw new KunderaException(ioe);
        }
        catch (InstantiationException ie)
        {
            log.error("Error during find By Relation, Caused by: .", ie);
            throw new KunderaException(ie);
        }
        catch (IllegalAccessException iae)
        {
            log.error("Error during find By Relation, Caused by: .", iae);
            throw new KunderaException(iae);
        }

        return output;
    }
854768
public void init(Range annotation, PropertyMetadata propertyMetadata)
    {
        m_maxExclusive = getValue(annotation.maxExclusive());
        m_minExclusive = getValue(annotation.minExclusive());
        m_maxInclusive = getValue(annotation.maxInclusive());
        m_minInclusive = getValue(annotation.minInclusive());
        
        m_maxExclusiveMessage = annotation.maxExclusiveMessage();
        m_minExclusiveMessage = annotation.minExclusiveMessage();
        m_maxInclusiveMessage = annotation.maxInclusiveMessage();
        m_minInclusiveMessage = annotation.minInclusiveMessage();
        m_propertyMetadata = propertyMetadata;
    }
1321842
public Result readHashcodeByRange(int index, int length, boolean debug, boolean useValue) // LI4337-17
    {
        final String methodName = "readHashcodeByRange()";
        Result result = getFromResultPool();
        result.data = null;
        HashtableOnDisk cache_instance = object_cache;;
        try {
            rwLock.readLock().lock();
            if (cache_instance != null) {
                if (index < 0) {
                    index = cache_instance.getPreviousRangeIndex();
                } else if (index > 0) {
                    index = cache_instance.getNextRangeIndex();
                } else {
                    cache_instance.initRangeIndex();
                }
                if (length == -1) {
                    length = cache_instance.size();
                }
                if (length <= 0) {
                    return result;
                }
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName, "cacheName=" + this.cacheName + " before range index=" + index + " length=" + length);
                HashcodeReadCallback hrcb = new HashcodeReadCallback(invalidationBuffer, debug, useValue);
                int rangeIndex = cache_instance.iterateKeys(hrcb, index, length);
                cache_instance.addRangeIndex(rangeIndex);
                if (hrcb.isValidHashCode == true) {
                    result.totalHashcode = hrcb.totalHashcode;
                    result.data = hrcb.list;
                    result.dataSize = hrcb.count;
                    if ((hrcb.count + hrcb.expiredCount) == 100) {
                        result.bMore = true;
                    } else {
                        result.bMore = false;
                    }
                } else {
                    result.returnCode = HTODDynacache.NO_HASHCODE_OLD_FORMAT;
                }
            }
        } catch (FileManagerException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (HashtableOnDiskException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (IOException ex) {
            this.diskCacheException = ex;
            result.diskException = ex;
            result.returnCode = DISK_EXCEPTION;
        } catch (Exception ex) {
            result.returnCode = OTHER_EXCEPTION;
            result.diskException = ex;
        } finally {
            rwLock.readLock().unlock();
            if (result.returnCode != NO_EXCEPTION) {
                if (tc.isDebugEnabled())
                    Tr.debug(tc, methodName, "cacheName=" + this.cacheName + "\n Exception: " + ExceptionUtility.getStackTrace(result.diskException));
            }
            if (result.returnCode == DISK_EXCEPTION || result.returnCode == OTHER_EXCEPTION) {
                com.ibm.ws.ffdc.FFDCFilter.processException(result.diskException, "com.ibm.ws.cache.HTODDynacache.readByRange", "1582", this);
            }
        }
        if (tc.isDebugEnabled())
            Tr.debug(tc, methodName, "cacheName=" + this.cacheName + " returnCode=" + result.returnCode + " size=" + result.dataSize + " more=" + result.bMore);
        return result;
    }
280674
@Override
    public SequenceRange get(String schemaName, String tableName, int step) throws Exception {
        Map<String, String> param = new HashMap<>();
        param.put("clientId", clientId);
        param.put("accessToken", accessToken);
        param.put("schemaName", schemaName);
        param.put("tableName", tableName);
        param.put("step", String.valueOf(step));
        String result = HttpUtils.sendPost(accessUrl, param);
        Map<String, String> resultMap = parseHttpKvString(result);
        if (resultMap.isEmpty()) {
            return null;
        } else {
            if (resultMap.get("errorCode") != null) {
                authorize();
                result = HttpUtils.sendPost(accessUrl, param);
                resultMap = parseHttpKvString(result);
                if (resultMap.get("errorCode") != null) {
                    throw new GetSequenceFailedException("clientId:" + clientId
                                                         + " access data failed, return message is:" + result);
                }
            }
            SequenceRange sequenceRange = new SequenceRange();
            sequenceRange.setBeginValue(parseLong(resultMap.get("beginValue")));
            sequenceRange.setEndValue(parseLong(resultMap.get("endValue")));
            return sequenceRange;
        }
    }
1021677
<T> Method getRangeKeyGetter(Class<T> clazz) {
        synchronized (rangeKeyGetterCache) {
            if ( !rangeKeyGetterCache.containsKey(clazz) ) {
                Method rangeKeyMethod = null;
                for ( Method method : getRelevantGetters(clazz) ) {
                    if ( method.getParameterTypes().length == 0 && method.isAnnotationPresent(DynamoDBRangeKey.class)) {
                        rangeKeyMethod = method;
                        break;
                    }
                }
                rangeKeyGetterCache.put(clazz, rangeKeyMethod);
            }
        }
        return rangeKeyGetterCache.get(clazz);
    }
894990
private boolean readMetaData() throws InvalidDataException {
		final ByteBuffer buf = storage.get(0);
		int magic1, magic2, t_b_order_leaf, t_b_order_internal, t_blockSize; // sanity
		boolean isClean = false;
		magic1 = buf.getInt();
		if (magic1 != MAGIC_1) {
			throw new InvalidDataException("Invalid metadata (MAGIC1)");
		}
		t_blockSize = buf.getInt();
		if (t_blockSize != blockSize) {
			throw new InvalidDataException("Invalid metadata (blockSize) " + t_blockSize + " != " + blockSize);
		}
		t_b_order_leaf = buf.getInt();
		t_b_order_internal = buf.getInt();
		if (t_b_order_leaf != b_order_leaf) {
			throw new InvalidDataException("Invalid metadata (b-order leaf) " + t_b_order_leaf + " != "
					+ b_order_leaf);
		}
		if (t_b_order_internal != b_order_internal) {
			throw new InvalidDataException("Invalid metadata (b-order internal) " + t_b_order_internal
					+ " != " + b_order_internal);
		}
		storageBlock = buf.getInt();
		rootIdx = buf.getInt();
		lowIdx = buf.getInt();
		highIdx = buf.getInt();
		elements = buf.getInt();
		height = buf.getInt();
		maxInternalNodes = buf.getInt();
		maxLeafNodes = buf.getInt();
		isClean = ((buf.get() == ((byte) 0xEA)) ? true : false);
		magic2 = buf.getInt();
		if (magic2 != MAGIC_2) {
			throw new InvalidDataException("Invalid metadata (MAGIC2)");
		}
		if (log.isDebugEnabled()) {
			log.debug(this.getClass().getName() + "::readMetaData() elements=" + elements + " rootIdx="
					+ rootIdx);
		}
		storage.release(buf);
		// Clear Caches
		clearReadCaches();
		clearWriteCaches();
		if (isClean && fileFreeBlocks.exists()) {
			try {
				final SimpleBitSet newFreeBlocks = SimpleBitSet.deserializeFromFile(fileFreeBlocks);
				freeBlocks = newFreeBlocks;
			} catch (IOException e) {
				log.error("IOException in readMetaData()", e);
			}
		}
		return isClean;
	}
563408
function getRange(start, limit, raw, store) {
      // Monitor values
      start = start || start === 0 ? parseInt(start) : null;
      limit = limit || limit === 0 ? parseInt(limit) : null;

      var data = raw == false ? store.data.asObject() : Object.assign({}, store.rootData.asObject());
      var rangeData = {};
      var isArray = store.data.__sorted && !raw;
      
      if (isArray) {
        data = raw == false ? store.data.asArray() : Object.assign({}, store.rootData.asObject());
        rangeData = [];
      }
      
      var size = Object.keys(data).length;

      if (
        start &&
        typeof start == "number" &&
        (limit || typeof limit == "number")
      ) {
        var index = 1;

        function rangeLoop(item) {
          // Check start item key
          if (index >= start && index <= limit) {
            if (isArray) {
              rangeData.push(data[item]);
            } else {
              rangeData[item] = data[item];
            }
          }
          index++;
        }
        // Loop through data object items
        if (isArray) {
          for (var i = 0; i < data.length; i++) {
            rangeLoop(i);
            if (index > limit) {
              break;
            }
          }
        } else {
          for (var key in data) {
            rangeLoop(key);
            if (index > limit) {
              break;
            }
          }
        }
      } else {
        vcomet.error.log("store", "Incorrect range values format");
      }
      // Update store data object
      store.rangeData = new Result(rangeData, store, store.data.__sorted);
      store.size = size;

    }
855745
@Override
    public IHLLMetadata readMetadata(final byte[] bytes) {
        final byte versionByte = bytes[0];
        final byte parametersByte = bytes[1];
        final byte cutoffByte = bytes[2];

        final int typeOrdinal = SerializationUtil.typeOrdinal(versionByte);
        final int explicitCutoffValue = SerializationUtil.explicitCutoff(cutoffByte);
        final boolean explicitOff = (explicitCutoffValue == EXPLICIT_OFF);
        final boolean explicitAuto = (explicitCutoffValue == EXPLICIT_AUTO);
        final int log2ExplicitCutoff = (explicitOff || explicitAuto) ? -1/*sentinel*/ : (explicitCutoffValue - 1/*per spec*/);

        return new HLLMetadata(SCHEMA_VERSION,
                                    getType(typeOrdinal),
                                    SerializationUtil.registerCountLog2(parametersByte),
                                    SerializationUtil.registerWidth(parametersByte),
                                    log2ExplicitCutoff,
                                    explicitOff,
                                    explicitAuto,
                                    SerializationUtil.sparseEnabled(cutoffByte));
    }
804110
@Override
    protected List<Object> populateEntities(EntityMetadata entityMetadata, Client client)
    {
        /**
         * Multiple clause: like two columns with and cluase For multiple
         * andTranslate jpa clause into temp store based on clause if it is for
         * multiple data set. and fetch from there and then finally delete that
         * temp storage. Query translator will translate queries into key value
         */

        /**
         * Limitations: 1) Multiple AND/OR clause not possible 2) Only equal
         * clause possible with AND/OR clause.
         * 
         */

        Set<Object> results = new LinkedHashSet<Object>();

        ClientMetadata clientMetadata = ((ClientBase) client).getClientMetadata();

        if (!MetadataUtils.useSecondryIndex(clientMetadata)
                && !(clientMetadata.getIndexImplementor() != null && clientMetadata.getIndexImplementor().equals(
                        RedisIndexer.class.getName())))
        {
            results.addAll(populateUsingLucene(entityMetadata, client, null,
                    getColumns(getKunderaQuery().getResult(), entityMetadata)));
        }
        else
        {
            RedisQueryInterpreter interpreter = onTranslation(getKunderaQuery().getFilterClauseQueue(), entityMetadata);
            results.addAll((List<Object>) ((RedisClient) client).onExecuteQuery(interpreter,
                    entityMetadata.getEntityClazz()));
        }

        List<Object> output = new ArrayList<Object>();
        output.addAll(results);

        return output;
    }
566104
public AttributeDataset range(int from, int to) {
        AttributeDataset sub = new AttributeDataset(name+'['+from+", "+to+']', attributes, response);
        sub.description = description;

        for (int i = from; i < to; i++) {
            sub.add(get(i));
        }

        return sub;
    }
255368
@Override
    public List<HBaseData> LoadData(HTableInterface hTable, String columnFamily, Object rowKey, Filter filter,
            String... columns) throws IOException
    {
        List<HBaseData> results = new ArrayList<HBaseData>();
        if (scanner == null)
        {

            // only in case of find by id
            Scan scan = null;
            if (rowKey != null)
            {
                byte[] rowKeyBytes = HBaseUtils.getBytes(rowKey);
                Get g = new Get(rowKeyBytes);

                // TODO: After more than one column family for 1 table. this
                // should work. currently failing for embeddable entities.
                if (columnFamily != null)
                {
                    g.addFamily(Bytes.toBytes(columnFamily));
                }

                if (filter != null)
                {
                    g.setFilter(filter);
                }
                Result result = hTable.get(g);

                if (result != null && result.list() != null)
                {
                    HBaseData data = null;
                    for (KeyValue value : result.list())
                    {
                        data = new HBaseData(columnFamily != null ? columnFamily : new String(value.getFamily()),
                                value.getRow());
                        break;
                    }

                    if (data != null)
                    {
                        data.setColumns(result.list());
                        results.add(data);
                    }

                }
                return results;

                // scan = new Scan(g);
            }
            else
            {
                scan = new Scan();
            }
            setScanCriteria(filter, columnFamily, null, scan, columns);
            scanner = hTable.getScanner(scan);
            resultsIter = scanner.iterator();
        }
        return scanResults(columnFamily, results);
    }
1351400
@Override
	protected void readDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreException
    {
		try
		{
	        dataRandomAccessFile.seek((long)blockHandle*blockSize);
	        if (dataRandomAccessFile.read(data,offset,len) != len)
	            throw new DataStoreException("Cannot read "+len+" bytes from store file");
		}
		catch (DataStoreException e)
		{
		    throw e;
		}
        catch (IOException e)
        {
            throw new DataStoreException("Could not read data block "+blockHandle+" : "+dataFile.getAbsolutePath(),e);
        }
    }