blob: f13b050e35fc4e57a2be4a66ee4ea4d339c87866 [file] [log] [blame]
// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gwtorm.nosql;
/**
* A function to produce a NoSQL secondary index key from an object.
* <p>
* An index function computes a row key for a secondary index table by appending
* the relevant values to builder's internal buffer in the order they are
* referenced in the query.
* <p>
* Typically an IndexFunction would be code generated at runtime by
* {@link IndexFunctionGen} as necessary by a NoSQL implementation.
*
* @param <T> type of the object the index record references.
*/
public abstract class IndexFunction<T> {
/** @return name of this index, should be unique within the relation. */
public abstract String getName();
/**
* Should this object exist in the index?
* <p>
* Objects that shouldn't appear in this index are skipped because field
* values are currently {@code null} or because one or more constants doesn't
* match as expected.
*
* @param object the object to read fields from.
* @return true if the object should be indexed by this index.
*/
public abstract boolean includes(T object);
/**
* Encodes the current values from the object into the index buffer.
*
* @param dst the buffer to append the indexed field value(s) onto.
* @param object the object to read current field values from.
*/
public abstract void encode(IndexKeyBuilder dst, T object);
}