use of com.orm.androrm.DatabaseAdapter in project androrm by androrm.
the class FieldResulutionTest method setUp.
@Override
public void setUp() {
List<Class<? extends Model>> models = new ArrayList<Class<? extends Model>>();
models.add(Product.class);
models.add(Branch.class);
models.add(Supplier.class);
models.add(Brand.class);
DatabaseAdapter adapter = DatabaseAdapter.getInstance(getContext());
adapter.setModels(models);
Brand b = new Brand();
b.setName("Copcal");
b.save(getContext());
mB = b;
// ID 1
Branch b1 = new Branch();
b1.setName("Cashbuild Pretoria");
b1.setBrand(b);
b1.save(getContext());
mB1 = b1;
// ID 2
Branch b2 = new Branch();
b2.setName("Plumblink Pretoria");
b2.setBrand(b);
b2.save(getContext());
mB2 = b2;
// ID 3
Branch b3 = new Branch();
b3.setName("The third Branch");
b3.setBrand(b);
b3.save(getContext());
mB3 = b3;
// ID 1
Product p1 = new Product();
p1.setName("ofen");
p1.addBranch(b1);
p1.addBranch(b3);
p1.save(getContext());
mP1 = p1;
Supplier s1 = new Supplier();
s1.setName("ACME");
s1.setBrand(b);
s1.addProduct(p1);
s1.addBranch(b1);
s1.save(getContext());
mS1 = s1;
}
use of com.orm.androrm.DatabaseAdapter in project androrm by androrm.
the class FieldResulutionTest method tearDown.
@Override
public void tearDown() {
DatabaseAdapter adapter = DatabaseAdapter.getInstance(getContext());
adapter.drop();
}
use of com.orm.androrm.DatabaseAdapter in project androrm by androrm.
the class LocationFieldTest method setUp.
@Override
public void setUp() {
List<Class<? extends Model>> models = new ArrayList<Class<? extends Model>>();
models.add(BlankModel.class);
DatabaseAdapter adapter = DatabaseAdapter.getInstance(getContext());
adapter.setModels(models);
}
use of com.orm.androrm.DatabaseAdapter in project androrm by androrm.
the class RenameModelMigration method execute.
@Override
public boolean execute(Context context, Class<T> model) {
if (isApplied(model, context)) {
return false;
}
MigrationHelper helper = new MigrationHelper(context);
if (!helper.tableExists(mOldName)) {
// on the database.
return true;
}
DatabaseAdapter adapter = DatabaseAdapter.getInstance(context);
renameRelationTables(context, model);
try {
adapter.renameTable(mOldName, getValue(model));
} catch (SQLException e) {
return false;
}
return true;
}
use of com.orm.androrm.DatabaseAdapter in project androrm by androrm.
the class RenameRelationMigration method execute.
@Override
public boolean execute(Context context, Class<T> model) {
MigrationHelper helper = new MigrationHelper(context);
List<String> tables = helper.getRelationTableNames(mOldName);
String newName = DatabaseBuilder.getTableName(model);
mValue = StringUtils.join(tables, ",");
if (isApplied(model, context)) {
return false;
}
DatabaseAdapter adapter = DatabaseAdapter.getInstance(context);
for (String table : tables) {
List<String> parts = Arrays.asList(table.replace(mOldName, newName).split("_"));
Collections.sort(parts);
String name = StringUtils.join(parts, "_");
try {
adapter.renameTable(table, name);
} catch (SQLException e) {
return false;
}
}
return true;
}
Aggregations