org.jsimpledb.JSetFieldInfo 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.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb;
import com.google.common.base.Converter;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
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.core.ObjId;
import org.jsimpledb.core.Transaction;
class JSetFieldInfo extends JCollectionFieldInfo {
JSetFieldInfo(JSetField jfield) {
super(jfield);
}
@Override
public TypeToken> getTypeToken(Class> context) {
return this.buildTypeToken(this.getElementFieldInfo().getTypeToken(context).wrap());
}
// This method exists solely to bind the generic type parameters
@SuppressWarnings("serial")
private TypeToken> buildTypeToken(TypeToken elementType) {
return new TypeToken>() { }.where(new TypeParameter() { }, elementType);
}
@Override
void registerChangeListener(Transaction tx, int[] path, Iterable types, AllChangesListener listener) {
tx.addSetFieldChangeListener(this.storageId, path, types, listener);
}
@Override
void addChangeParameterTypes(List> types, Class targetType) {
this.addChangeParameterTypes(types, targetType, this.getElementFieldInfo().getTypeToken(targetType));
}
// This method exists solely to bind the generic type parameters
@SuppressWarnings("serial")
private 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.getElementFieldInfo().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);
}
@Override
public void copyRecurse(CopyState copyState, JTransaction srcTx, JTransaction dstTx,
ObjId id, int storageId, int fieldIndex, int[] fields) {
assert storageId == this.getElementFieldInfo().storageId;
this.copyRecurse(copyState, srcTx, dstTx, srcTx.tx.readSetField(id, this.storageId, false), fieldIndex, fields);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy