Search in sources :

Example 1 with BasicPropertyGenerator

use of com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicPropertyGenerator in project squidb by yahoo.

the class TableModelSpecFieldPlugin method getPropertyGenerator.

@Override
protected PropertyGenerator getPropertyGenerator(VariableElement field, DeclaredTypeName fieldType) {
    Class<? extends BasicPropertyGenerator> generatorClass;
    if (isIntegerPrimaryKey(field, fieldType)) {
        // Force INTEGER PRIMARY KEY properties to be LongProperty, even if declared as e.g. int
        generatorClass = getRowidPropertyGenerator();
    } else {
        generatorClass = generatorMap.get(fieldType);
    }
    try {
        BasicPropertyGenerator propertyGenerator = generatorClass.getConstructor(ModelSpec.class, VariableElement.class, AptUtils.class).newInstance(modelSpec, field, utils);
        if (DEFAULT_ROWID_PROPERTY_NAME.equalsIgnoreCase(propertyGenerator.getColumnName()) || DEFAULT_ROWID_PROPERTY_NAME.equalsIgnoreCase(propertyGenerator.getPropertyName())) {
            modelSpec.logError("Columns in a table model spec cannot be named rowid, as " + "they would clash with the SQLite rowid column used for SquiDB bookkeeping", field);
            return null;
        }
        String propertyName = propertyGenerator.getPropertyName();
        if (DEFAULT_ID_PROPERTY_NAME.equalsIgnoreCase(propertyName) && !isIntegerPrimaryKey(field, fieldType)) {
            modelSpec.logError("User-defined non-primary-key columns cannot currently be " + "named 'ID' for the sake of backwards compatibility. This restriction will be removed in a " + "future version of SquiDB.", field);
            return null;
        }
        String columnName = propertyGenerator.getColumnName();
        if (!SqlUtils.checkIdentifier(columnName, "column", modelSpec, field, utils)) {
            return null;
        }
        return propertyGenerator;
    } catch (Exception e) {
        modelSpec.logError("Exception instantiating PropertyGenerator: " + generatorClass + ", " + e, field);
    }
    return null;
}
Also used : AptUtils(com.yahoo.aptutils.utils.AptUtils) BasicPropertyGenerator(com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicPropertyGenerator) VariableElement(javax.lang.model.element.VariableElement) ModelSpec(com.yahoo.squidb.processor.data.ModelSpec) IOException(java.io.IOException)

Aggregations

AptUtils (com.yahoo.aptutils.utils.AptUtils)1 ModelSpec (com.yahoo.squidb.processor.data.ModelSpec)1 BasicPropertyGenerator (com.yahoo.squidb.processor.plugins.defaults.properties.generators.BasicPropertyGenerator)1 IOException (java.io.IOException)1 VariableElement (javax.lang.model.element.VariableElement)1