setDatabase(db); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor();
setDatabase(db); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor();
/** * Add a column to a table by specifying the corresponding {@link Property} * * @param property the Property associated with the column to add * @return true if the statement executed without error, false otherwise */ protected boolean tryAddColumn(Property<?> property) { if (!propertyBelongsToTable(property)) { throw new IllegalArgumentException("Can't alter table: property does not belong to a Table"); } SqlConstructorVisitor visitor = new SqlConstructorVisitor(); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); sql.append("ALTER TABLE ").append(property.tableModelName.tableName).append(" ADD "); property.accept(visitor, sql); return tryExecSql(sql.toString()); }
@Override public Void visitBoolean(Property<Boolean> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitLong(Property<Long> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitInteger(Property<Integer> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitBlob(Property<byte[]> property, StringBuilder sql) { return appendColumnDefinition("BLOB", property, sql); } }
@Override public Void visitDouble(Property<Double> property, StringBuilder sql) { return appendColumnDefinition("REAL", property, sql); }
@Override public Void visitString(Property<String> property, StringBuilder sql) { return appendColumnDefinition("TEXT", property, sql); }
/** * Create a new {@link Table} or {@link VirtualTable} in the database * * @param table the Table or VirtualTable to create * @return true if the statement executed without error, false otherwise */ protected boolean tryCreateTable(Table table) { SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor(); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); table.appendCreateTableSql(getCompileContext(), sql, sqlVisitor); return tryExecSql(sql.toString()); }
/** * Add a column to a table by specifying the corresponding {@link Property} * * @param property the Property associated with the column to add * @return true if the statement executed without error, false otherwise */ protected boolean tryAddColumn(Property<?> property) { if (!propertyBelongsToTable(property)) { throw new IllegalArgumentException("Can't alter table: property does not belong to a Table"); } SqlConstructorVisitor visitor = new SqlConstructorVisitor(); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); sql.append("ALTER TABLE ").append(property.tableModelName.tableName).append(" ADD "); property.accept(visitor, sql); return tryExecSql(sql.toString()); }
@Override public Void visitBoolean(Property<Boolean> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitString(Property<String> property, StringBuilder sql) { return appendColumnDefinition("TEXT", property, sql); }
@Override public Void visitInteger(Property<Integer> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitBlob(Property<byte[]> property, StringBuilder sql) { return appendColumnDefinition("BLOB", property, sql); } }
@Override public Void visitLong(Property<Long> property, StringBuilder sql) { return appendColumnDefinition("INTEGER", property, sql); }
@Override public Void visitDouble(Property<Double> property, StringBuilder sql) { return appendColumnDefinition("REAL", property, sql); }
/** * Create a new {@link Table} or {@link VirtualTable} in the database * * @param table the Table or VirtualTable to create * @return true if the statement executed without error, false otherwise */ protected boolean tryCreateTable(Table table) { SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor(); StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); table.appendCreateTableSql(getCompileContext(), sql, sqlVisitor); return tryExecSql(sql.toString()); }