@Override protected String getGeneratedClassNameString() { return modelSpecAnnotation.className(); }
private boolean shouldGenerateROWIDProperty() { TableModelSpecWrapper tableModelSpec = (TableModelSpecWrapper) modelSpec; return tableModelSpec.isVirtualTable() || tableModelSpec.hasMetadata(METADATA_KEY_HAS_PRIMARY_KEY) || tableModelSpec.getSpecAnnotation().noRowIdAlias(); }
private void emitTableDeclaration() throws IOException { writer.writeComment("--- table declaration"); List<Object> arguments = new ArrayList<>(); arguments.add(Expressions.classObject(modelSpec.getGeneratedClassName())); // modelClass arguments.add(PROPERTIES_ARRAY_NAME); // properties arguments.add("\"" + modelSpec.getSpecAnnotation().tableName().trim() + "\""); // name arguments.add(null); // database name, null by default if (modelSpec.isVirtualTable()) { if (AptUtils.isEmpty(modelSpec.getSpecAnnotation().virtualModule())) { modelSpec.logError("virtualModule should be non-empty for virtual table models", modelSpec.getModelSpecElement()); } arguments.add("\"" + modelSpec.getSpecAnnotation().virtualModule() + "\""); } else if (!AptUtils.isEmpty(modelSpec.getSpecAnnotation().tableConstraint())) { arguments.add("\"" + modelSpec.getSpecAnnotation().tableConstraint() + "\""); } writer.writeFieldDeclaration(modelSpec.getTableType(), TABLE_NAME, Expressions.callConstructor(modelSpec.getTableType(), arguments), TypeConstants.PUBLIC_STATIC_FINAL); writer.writeFieldDeclaration(TypeConstants.TABLE_MODEL_NAME, TABLE_MODEL_NAME, Expressions.callConstructor(TypeConstants.TABLE_MODEL_NAME, Expressions.classObject(modelSpec.getGeneratedClassName()), Expressions.callMethodOn(TableModelFileWriter.TABLE_NAME, "getName")), TypeConstants.PUBLIC_STATIC_FINAL); writer.writeNewline(); }
@TableModelSpec(className = "BasicData", tableName = "data") public class BasicDataSpec { @PrimaryKey long dataId; String data1; String data2; String data3; int type; TestEnum someEnum; }
private void checkTableName() { String tableName = getSpecAnnotation().tableName().trim(); if (tableName.toLowerCase().startsWith("sqlite_")) { logError("Table names cannot start with 'sqlite_'; such names are reserved for internal use", getModelSpecElement()); } else { SqlUtils.checkIdentifier(tableName, "table", this, getModelSpecElement(), utils); } }
/** * @return true if the table model is for a virtual table, false otherwise */ public boolean isVirtualTable() { return !AptUtils.isEmpty(modelSpecAnnotation.virtualModule()); }
@TableModelSpec(className = "Tag", tableName = "tags", tableConstraint = "FOREIGN KEY(taskId) references tasks(_id) ON DELETE CASCADE") public class TagSpec { @PrimaryKey @ColumnSpec(name = "_id") long id; @ColumnSpec(constraints = "NOT NULL") String tag; @ColumnSpec(constraints = "NOT NULL") long taskId; }
private void checkTableName() { String tableName = getSpecAnnotation().tableName().trim(); if (tableName.toLowerCase().startsWith("sqlite_")) { logError("Table names cannot start with 'sqlite_'; such names are reserved for internal use", getModelSpecElement()); } else { SqlUtils.checkIdentifier(tableName, "table", this, getModelSpecElement(), utils); } }
/** * @return true if the table model is for a virtual table, false otherwise */ public boolean isVirtualTable() { return !AptUtils.isEmpty(modelSpecAnnotation.virtualModule()); }
private void emitTableDeclaration() throws IOException { writer.writeComment("--- table declaration"); List<Object> arguments = new ArrayList<>(); arguments.add(Expressions.classObject(modelSpec.getGeneratedClassName())); // modelClass arguments.add(PROPERTIES_ARRAY_NAME); // properties arguments.add("\"" + modelSpec.getSpecAnnotation().tableName().trim() + "\""); // name arguments.add(null); // database name, null by default if (modelSpec.isVirtualTable()) { if (AptUtils.isEmpty(modelSpec.getSpecAnnotation().virtualModule())) { modelSpec.logError("virtualModule should be non-empty for virtual table models", modelSpec.getModelSpecElement()); } arguments.add("\"" + modelSpec.getSpecAnnotation().virtualModule() + "\""); } else if (!AptUtils.isEmpty(modelSpec.getSpecAnnotation().tableConstraint())) { arguments.add("\"" + modelSpec.getSpecAnnotation().tableConstraint() + "\""); } writer.writeFieldDeclaration(modelSpec.getTableType(), TABLE_NAME, Expressions.callConstructor(modelSpec.getTableType(), arguments), TypeConstants.PUBLIC_STATIC_FINAL); writer.writeFieldDeclaration(TypeConstants.TABLE_MODEL_NAME, TABLE_MODEL_NAME, Expressions.callConstructor(TypeConstants.TABLE_MODEL_NAME, Expressions.classObject(modelSpec.getGeneratedClassName()), Expressions.callMethodOn(TableModelFileWriter.TABLE_NAME, "getName")), TypeConstants.PUBLIC_STATIC_FINAL); writer.writeNewline(); }
@TableModelSpec(className = "TestNonIntegerPrimaryKey", tableName = "testNonIntegerPrimaryKey") public class TestNonIntegerPrimaryKeySpec { @PrimaryKey @ColumnSpec(name = "keyCol", constraints = "NOT NULL") String key; String value; }
private boolean shouldGenerateROWIDProperty() { TableModelSpecWrapper tableModelSpec = (TableModelSpecWrapper) modelSpec; return tableModelSpec.isVirtualTable() || tableModelSpec.hasMetadata(METADATA_KEY_HAS_PRIMARY_KEY) || tableModelSpec.getSpecAnnotation().noRowIdAlias(); }
@Override protected String getGeneratedClassNameString() { return modelSpecAnnotation.className(); }
@TableModelSpec(className = "TestVirtualModel", tableName = "virtual_models", virtualModule = "fts4") public class TestVirtualModelSpec { @ColumnSpec(name = "test_num", defaultValue = "7") long testNumber; @ColumnSpec(defaultValue = ColumnSpec.DEFAULT_NULL) String title; @ColumnSpec(defaultValue = ColumnSpec.DEFAULT_NULL) String body; }
@TableModelSpec(className = "TestMultiColumnKey", tableName = "multiColumnKey", tableConstraint = "PRIMARY KEY(keyCol1, keyCol2, keyCol3)", noRowIdAlias = true) public class TestMultiColumnKeySpec { @ColumnSpec(constraints = "NOT NULL") String keyCol1; @ColumnSpec(constraints = "NOT NULL") String keyCol2; @ColumnSpec(constraints = "NOT NULL") String keyCol3; String otherData; }
@TableModelSpec(className = "Task", tableName = "tasks") public class TaskSpec { @PrimaryKey @ColumnSpec(name = "_id") long id; @ColumnSpec(constraints = "NOT NULL") String title; @ColumnSpec(defaultValue = "0") long completionDate; @ColumnSpec(defaultValue = "0") long dueDate; @ColumnSpec(defaultValue = "0") int priority; @ModelMethod public static boolean isCompleted(Task instance) { return instance.getCompletionDate() > 0; } }
@TableModelSpec(className = "TriggerTester", tableName = "trigger_testers") public class TriggerTesterSpec { @PrimaryKey @ColumnSpec(name = "_id") long id; @ColumnSpec(defaultValue = "0") int value1; @ColumnSpec(defaultValue = "0") int value2; String str1; String str2; }
@TableModelSpec(className = "Employee", tableName = "employees") public class EmployeeSpec { @PrimaryKey @ColumnSpec(name = "_id") long id; @ColumnSpec(constraints = "NOT NULL") String name; long managerId; @ColumnSpec(defaultValue = "true") boolean isHappy; }
@TableModelSpec(className = "Thing", tableName = "things") public class ThingSpec { public static final String DEFAULT_FOO = "thing"; public static final int DEFAULT_BAR = 100; public static final boolean DEFAULT_IS_ALIVE = true; @PrimaryKey(autoincrement = false) long id; @ColumnSpec(defaultValue = DEFAULT_FOO) String foo; @ColumnSpec(defaultValue = "100") int bar; long baz; @ColumnSpec(defaultValue = "0.0") double qux; @ColumnSpec(defaultValue = "true") boolean isAlive; byte[] blob; }
@TableModelSpec(className = "TestModel", tableName = "testModels", tableConstraint = "UNIQUE (creationDate) ON CONFLICT REPLACE") @Implements(interfaceClasses = Runnable.class,