Search in sources :

Example 1 with RowidPropertyGenerator

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;
            }
        }
    }
}
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 RowidPropertyGenerator

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

Aggregations

RowidPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.RowidPropertyGenerator)2 MethodDeclarationParameters (com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)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 PropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.PropertyGenerator)1