use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator in project squidb by yahoo.
the class TableModelSpecFieldPlugin method afterProcessVariableElements.
@Override
public void afterProcessVariableElements() {
RowidPropertyGenerator rowidPropertyGenerator;
if (modelSpec.hasMetadata(METADATA_KEY_ROWID_ALIAS_PROPERTY_GENERATOR)) {
rowidPropertyGenerator = modelSpec.getMetadata(METADATA_KEY_ROWID_ALIAS_PROPERTY_GENERATOR);
} else {
if (shouldGenerateROWIDProperty()) {
rowidPropertyGenerator = new RowidPropertyGenerator(modelSpec, "rowid", DEFAULT_ROWID_PROPERTY_NAME, utils);
} else {
utils.getMessager().printMessage(Kind.WARNING, "Model class " + modelSpec.getGeneratedClassName() + " is currently generating an integer primary key ID property to act as an alias to the table's " + "rowid. Future versions of SquiDB will remove this default property for the sake of better " + "support for arbitrary primary keys. If you are using the ID property, you should update " + "your model spec by explicitly declaring a field, named id with column name '_id' and " + "annotated with @PrimaryKey", modelSpec.getModelSpecElement());
rowidPropertyGenerator = new RowidPropertyGenerator(modelSpec, "_id", DEFAULT_ID_PROPERTY_NAME, utils) {
@Override
protected String getColumnDefinition() {
return "\"PRIMARY KEY AUTOINCREMENT\"";
}
};
}
modelSpec.putMetadata(METADATA_KEY_ROWID_ALIAS_PROPERTY_GENERATOR, rowidPropertyGenerator);
}
modelSpec.getPropertyGenerators().add(0, rowidPropertyGenerator);
// Sanity check to make sure there is exactly 1 RowidPropertyGenerator
RowidPropertyGenerator foundRowidPropertyGenerator = null;
for (PropertyGenerator generator : modelSpec.getPropertyGenerators()) {
if (generator instanceof RowidPropertyGenerator) {
if (foundRowidPropertyGenerator != null) {
modelSpec.logError("Found redundant rowid property generator for property" + generator.getPropertyName() + ". Rowid property generator " + foundRowidPropertyGenerator.getPropertyName() + " already exists", generator.getField());
} else {
foundRowidPropertyGenerator = (RowidPropertyGenerator) generator;
}
}
}
}
use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator in project squidb by yahoo.
the class TableModelSpecFieldPlugin method emitMethods.
@Override
public void emitMethods(JavaFileWriter writer) throws IOException {
// overridden setRowId with appropriate return type
if (!pluginEnv.hasSquidbOption(PluginEnvironment.OPTIONS_DISABLE_DEFAULT_GETTERS_AND_SETTERS)) {
RowidPropertyGenerator rowidPropertyGenerator = modelSpec.getMetadata(METADATA_KEY_ROWID_ALIAS_PROPERTY_GENERATOR);
if (rowidPropertyGenerator != null && !"setRowId".equals(rowidPropertyGenerator.setterMethodName())) {
MethodDeclarationParameters params = new MethodDeclarationParameters().setModifiers(Modifier.PUBLIC).setMethodName("setRowId").setArgumentTypes(CoreTypes.PRIMITIVE_LONG).setArgumentNames("rowid").setReturnType(modelSpec.getGeneratedClassName());
writer.writeAnnotation(CoreTypes.OVERRIDE).beginMethodDefinition(params).writeStringStatement("super.setRowId(rowid)").writeStringStatement("return this").finishMethodDefinition();
}
}
}
Aggregations