
io.permazen.core.CompositeIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-core Show documentation
Show all versions of permazen-core Show documentation
Permazen core API classes which provide objects, fields, indexes, queries, and schema management on top of a key/value store.
The newest version!
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen.core;
import com.google.common.base.Preconditions;
import io.permazen.encoding.Encoding;
import io.permazen.schema.SchemaCompositeIndex;
/**
* A composite index on two or more fields in an {@link ObjType}.
*/
public class CompositeIndex extends Index {
// Constructor
CompositeIndex(Schema schema, SchemaCompositeIndex index, ObjType objType, Iterable extends SimpleField>> fields) {
super(schema, index, index.getName(), objType, fields);
assert this.fields.size() >= 2;
assert this.fields.stream().noneMatch(field -> field.parent != null);
}
// IndexSwitch
@Override
public R visit(IndexSwitch target) {
Preconditions.checkArgument(target != null, "null target");
return target.caseCompositeIndex(this);
}
// Object
@Override
public String toString() {
return "composite " + super.toString();
}
// Package Methods
@Override
public AbstractCoreIndex getIndex(Transaction tx) {
switch (this.encodings.size()) {
case 2:
return this.buildIndex(tx, this.encodings.get(0), this.encodings.get(1));
case 3:
return this.buildIndex(tx, this.encodings.get(0), this.encodings.get(1), this.encodings.get(2));
case 4:
return this.buildIndex(tx, this.encodings.get(0), this.encodings.get(1), this.encodings.get(2), this.encodings.get(3));
// COMPOSITE-INDEX
default:
throw new RuntimeException("internal error");
}
}
// This method exists solely to bind the generic type parameters
private CoreIndex2 buildIndex(Transaction tx,
Encoding value1Encoding,
Encoding value2Encoding) {
return new CoreIndex2<>(tx.kvt, new Index2View<>(this.storageId,
value1Encoding,
value2Encoding,
Encodings.OBJ_ID));
}
// This method exists solely to bind the generic type parameters
private CoreIndex3 buildIndex(Transaction tx,
Encoding value1Encoding,
Encoding value2Encoding,
Encoding value3Encoding) {
return new CoreIndex3<>(tx.kvt, new Index3View<>(this.storageId,
value1Encoding,
value2Encoding,
value3Encoding,
Encodings.OBJ_ID));
}
// This method exists solely to bind the generic type parameters
private CoreIndex4 buildIndex(Transaction tx,
Encoding value1Encoding,
Encoding value2Encoding,
Encoding value3Encoding,
Encoding value4Encoding) {
return new CoreIndex4<>(tx.kvt, new Index4View<>(this.storageId,
value1Encoding,
value2Encoding,
value3Encoding,
value4Encoding,
Encodings.OBJ_ID));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy