org.jsimpledb.JSetField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-main Show documentation
Show all versions of jsimpledb-main Show documentation
JSimpleDB classes that map Java model classes onto the core API.
The newest version!
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb;
import com.google.common.base.Converter;
import com.google.common.base.Preconditions;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
import java.lang.reflect.Method;
import java.util.List;
import java.util.NavigableSet;
import org.jsimpledb.change.SetFieldAdd;
import org.jsimpledb.change.SetFieldClear;
import org.jsimpledb.change.SetFieldRemove;
import org.jsimpledb.schema.SetSchemaField;
/**
* Represents a set field in a {@link JClass}.
*/
public class JSetField extends JCollectionField {
JSetField(JSimpleDB jdb, String name, int storageId, JSimpleField elementField, String description, Method getter) {
super(jdb, name, storageId, elementField, description, getter);
}
@Override
public NavigableSet> getValue(JObject jobj) {
Preconditions.checkArgument(jobj != null, "null jobj");
return jobj.getTransaction().readSetField(jobj.getObjId(), this.storageId, false);
}
@Override
public R visit(JFieldSwitch target) {
return target.caseJSetField(this);
}
@Override
SetSchemaField toSchemaItem(JSimpleDB jdb) {
final SetSchemaField schemaField = new SetSchemaField();
super.initialize(jdb, schemaField);
return schemaField;
}
@Override
SetElementIndexInfo toIndexInfo(JSimpleField subField) {
assert subField == this.elementField;
return new SetElementIndexInfo(this);
}
@Override
@SuppressWarnings("serial")
TypeToken> buildTypeToken(TypeToken elementType) {
return new TypeToken>() { }.where(new TypeParameter() { }, elementType);
}
// This method exists solely to bind the generic type parameters
@Override
@SuppressWarnings("serial")
void addChangeParameterTypes(List> types, Class targetType, TypeToken elementType) {
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType)
.where(new TypeParameter() { }, elementType.wrap()));
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType));
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType)
.where(new TypeParameter() { }, elementType.wrap()));
}
@Override
public NavigableSetConverter, ?> getConverter(JTransaction jtx) {
final Converter, ?> elementConverter = this.elementField.getConverter(jtx);
return elementConverter != null ? this.createConverter(elementConverter) : null;
}
// This method exists solely to bind the generic type parameters
private NavigableSetConverter createConverter(Converter elementConverter) {
return new NavigableSetConverter<>(elementConverter);
}
// Bytecode generation
@Override
Method getFieldReaderMethod() {
return ClassGenerator.JTRANSACTION_READ_SET_FIELD_METHOD;
}
}