
com.github.dynodao.processor.schema.DynamoSchema Maven / Gradle / Ivy
package com.github.dynodao.processor.schema;
import com.github.dynodao.processor.schema.attribute.DocumentDynamoAttribute;
import com.github.dynodao.processor.schema.index.DynamoIndex;
import com.github.dynodao.processor.schema.index.IndexType;
import lombok.Builder;
import lombok.Value;
import javax.lang.model.element.TypeElement;
import java.util.Set;
import static com.github.dynodao.processor.util.StreamUtil.toLinkedHashSet;
/**
* The structured schema depicted by an annotated document class.
*/
@Value
@Builder
public class DynamoSchema {
private final String tableName;
private final DocumentDynamoAttribute document;
private final Set indexes;
/**
* @return the {@link TypeElement} which this schema is modelled after
*/
public TypeElement getDocumentElement() {
return (TypeElement) document.getElement();
}
/**
* @return the table index
*/
public DynamoIndex getTableIndex() {
return getIndexes().stream()
.filter(index -> index.getIndexType().equals(IndexType.TABLE))
.findFirst().orElseThrow(() -> new IllegalStateException("expected there to always be a table 'index'"));
}
/**
* @return all local secondary indexes, if any
*/
public Set getLocalSecondaryIndexes() {
return getIndexes().stream()
.filter(index -> index.getIndexType().equals(IndexType.LOCAL_SECONDARY_INDEX))
.collect(toLinkedHashSet());
}
/**
* @return true if the schema has any local secondary indexes, false otherwise
*/
public boolean hasLocalSecondaryIndexes() {
return getIndexes().stream().anyMatch(index -> index.getIndexType().equals(IndexType.LOCAL_SECONDARY_INDEX));
}
/**
* @return all global secondary indexes, if any
*/
public Set getGlobalSecondaryIndexes() {
return getIndexes().stream()
.filter(index -> index.getIndexType().equals(IndexType.GLOBAL_SECONDARY_INDEX))
.collect(toLinkedHashSet());
}
/**
* @return true if the schema has any global secondary indexes, false otherwise
*/
public boolean hasGlobalSecondaryIndexes() {
return getIndexes().stream().anyMatch(index -> index.getIndexType().equals(IndexType.GLOBAL_SECONDARY_INDEX));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy