org.jsimpledb.JCounterField 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.TypeToken;
import java.lang.reflect.Method;
import java.util.List;
import org.jsimpledb.schema.CounterSchemaField;
import org.objectweb.asm.ClassWriter;
/**
* Represents a counter field in a {@link JClass}.
*
* @see org.jsimpledb.Counter
*/
public class JCounterField extends JField {
final UpgradeConversionPolicy upgradeConversion;
JCounterField(JSimpleDB jdb, String name, int storageId,
org.jsimpledb.annotation.JField annotation, String description, Method getter) {
super(jdb, name, storageId, description, getter);
this.upgradeConversion = annotation.upgradeConversion();
}
@Override
public Counter getValue(JObject jobj) {
Preconditions.checkArgument(jobj != null, "null jobj");
return jobj.getTransaction().readCounterField(jobj.getObjId(), this.storageId, false);
}
@Override
public R visit(JFieldSwitch target) {
return target.caseJCounterField(this);
}
@Override
CounterSchemaField toSchemaItem(JSimpleDB jdb) {
final CounterSchemaField schemaField = new CounterSchemaField();
this.initialize(jdb, schemaField);
return schemaField;
}
@Override
public TypeToken getTypeToken() {
return TypeToken.of(Counter.class);
}
@Override
public Converter, ?> getConverter(JTransaction jtx) {
return null;
}
@Override
boolean supportsChangeNotifications() {
return false;
}
@Override
void addChangeParameterTypes(List> types, Class targetType) {
throw new UnsupportedOperationException("counter fields do not support change notifications");
}
// Bytecode generation
@Override
void outputFields(ClassGenerator> generator, ClassWriter cw) {
this.outputCachedValueField(generator, cw);
}
@Override
void outputMethods(ClassGenerator> generator, ClassWriter cw) {
this.outputCachedNonSimpleValueGetterMethod(generator, cw, ClassGenerator.JTRANSACTION_READ_COUNTER_FIELD_METHOD);
}
}