use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator 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.PropertyGenerator in project squidb by yahoo.
the class ModelFileWriter method emitGettersAndSetters.
protected void emitGettersAndSetters() throws IOException {
if (pluginEnv.hasSquidbOption(PluginEnvironment.OPTIONS_DISABLE_DEFAULT_GETTERS_AND_SETTERS)) {
writer.writeComment("--- getters and setters disabled by plugin flag");
} else {
writer.writeComment("--- getters and setters");
for (PropertyGenerator generator : modelSpec.getPropertyGenerators()) {
generator.emitGetter(writer);
generator.emitSetter(writer);
}
}
}
use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator in project squidb by yahoo.
the class ViewModelFileWriter method emitPropertyReferenceArrayBody.
private boolean emitPropertyReferenceArrayBody(boolean alias) throws IOException {
for (PropertyGenerator propertyGenerator : modelSpec.getPropertyGenerators()) {
Expression reference = Expressions.staticReference(modelSpec.getModelSpecName(), propertyGenerator.getPropertyName());
if (alias) {
VariableElement field = propertyGenerator.getField();
if (field != null) {
Alias aliasAnnotation = field.getAnnotation(Alias.class);
if (aliasAnnotation != null && !AptUtils.isEmpty(aliasAnnotation.value().trim())) {
reference = reference.callMethod("as", "\"" + aliasAnnotation.value().trim() + "\"");
}
}
}
writer.writeExpression(reference);
writer.appendString(",\n");
}
return !AptUtils.isEmpty(modelSpec.getPropertyGenerators());
}
use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator in project squidb by yahoo.
the class TableModelFileWriter method emitAllProperties.
@Override
protected void emitAllProperties() throws IOException {
for (PropertyGenerator generator : modelSpec.getPropertyGenerators()) {
modelSpec.getPluginBundle().beforeEmitPropertyDeclaration(writer, generator);
generator.emitPropertyDeclaration(writer);
modelSpec.getPluginBundle().afterEmitPropertyDeclaration(writer, generator);
writer.writeNewline();
}
for (PropertyGenerator deprecatedProperty : modelSpec.getDeprecatedPropertyGenerators()) {
modelSpec.getPluginBundle().beforeEmitPropertyDeclaration(writer, deprecatedProperty);
deprecatedProperty.emitPropertyDeclaration(writer);
modelSpec.getPluginBundle().afterEmitPropertyDeclaration(writer, deprecatedProperty);
writer.writeNewline();
}
}
use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator in project squidb by yahoo.
the class ModelSpec method addRequiredImports.
/**
* Adds imports required by this model spec to the given accumulator set
*
* @param imports accumulator set
*/
public final void addRequiredImports(Set<DeclaredTypeName> imports) {
// For PROPERTIES array
imports.add(TypeConstants.PROPERTY);
imports.add(TypeConstants.VALUES_STORAGE);
imports.add(getModelSuperclass());
for (PropertyGenerator generator : propertyGenerators) {
generator.registerRequiredImports(imports);
}
addModelSpecificImports(imports);
pluginBundle.addRequiredImports(imports);
}
Aggregations