Search in sources :

Example 1 with PropertyGenerator

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;
            }
        }
    }
}
Also used : RowidPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator) BasicStringPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicStringPropertyGenerator) PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator) BasicBooleanPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicBooleanPropertyGenerator) BasicPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicPropertyGenerator) BasicLongPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicLongPropertyGenerator) BasicDoublePropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicDoublePropertyGenerator) BasicBlobPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicBlobPropertyGenerator) RowidPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator) BasicIntegerPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicIntegerPropertyGenerator)

Example 2 with PropertyGenerator

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);
        }
    }
}
Also used : PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)

Example 3 with PropertyGenerator

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());
}
Also used : Expression(com.yahoo.aptutils.writer.expressions.Expression) Alias(com.yahoo.squidb.annotations.Alias) PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator) VariableElement(javax.lang.model.element.VariableElement)

Example 4 with PropertyGenerator

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();
    }
}
Also used : PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)

Example 5 with PropertyGenerator

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);
}
Also used : PropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)

Aggregations

PropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)5 Expression (com.yahoo.aptutils.writer.expressions.Expression)1 Alias (com.yahoo.squidb.annotations.Alias)1 BasicBlobPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicBlobPropertyGenerator)1 BasicBooleanPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicBooleanPropertyGenerator)1 BasicDoublePropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicDoublePropertyGenerator)1 BasicIntegerPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicIntegerPropertyGenerator)1 BasicLongPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicLongPropertyGenerator)1 BasicPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicPropertyGenerator)1 BasicStringPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicStringPropertyGenerator)1 RowidPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator)1 VariableElement (javax.lang.model.element.VariableElement)1