io.permazen.JCompositeIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-main Show documentation
Show all versions of permazen-main Show documentation
Permazen classes that map Java model classes onto the core API.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen;
import com.google.common.base.Preconditions;
import io.permazen.core.Database;
import io.permazen.core.FieldType;
import io.permazen.schema.SchemaCompositeIndex;
import io.permazen.util.ParseContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
/**
* A composite index.
*/
public class JCompositeIndex extends JSchemaObject {
final Class> declaringType;
final List jfields;
final boolean unique;
final List> uniqueExcludes; // note: these are core API values, sorted lexicographically by jfield.fieldType
final Comparator> uniqueComparator;
/**
* Constructor.
*
* @param jdb associated database
* @param name the name of the object type
* @param storageId object type storage ID
* @param declaringType object type annotation is declared on (for scoping unique())
* @param annotation original annotation
* @throws IllegalArgumentException if any parameter is null
* @throws IllegalArgumentException if {@code storageId} is non-positive
*/
JCompositeIndex(Permazen jdb, String name, int storageId, Class> declaringType,
io.permazen.annotation.JCompositeIndex annotation, JSimpleField... jfields) {
super(jdb, name, storageId, "composite index `" + name + "' on fields " + Arrays.asList(jfields));
Preconditions.checkArgument(name != null, "null name");
Preconditions.checkArgument(declaringType != null, "null declaringType");
Preconditions.checkArgument(jfields.length >= 2 && jfields.length <= Database.MAX_INDEXED_FIELDS, "invalid field count");
Preconditions.checkArgument(annotation != null, "null annotation");
this.declaringType = declaringType;
this.jfields = Collections.unmodifiableList(Arrays.asList(jfields));
this.unique = annotation.unique();
// Parse uniqueExcludes
final int numExcludes = annotation.uniqueExclude().length;
if (numExcludes > 0) {
assert this.unique;
// Parse value lists
this.uniqueExcludes = new ArrayList<>(numExcludes);
final int numFields = this.jfields.size();
for (String string : annotation.uniqueExclude()) {
final ParseContext ctx = new ParseContext(string);
final ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy