use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class AbsDatabaseConnectivity method insert.
public final int insert(DatabaseObject[] objects) {
if (objects == null || objects.length <= 0) {
return 0;
}
List<DatabaseObject> tmp = new ArrayList<DatabaseObject>();
for (DatabaseObject object : objects) {
if (matchClass(object.getClass()) == false) {
continue;
}
tmp.add(object);
}
if (tmp.size() <= 0) {
return 0;
}
final int ret = onInsert(tmp.toArray(new DatabaseObject[0]));
if (ret > 0) {
notifyObservers();
}
return ret;
}
use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class AbsDatabaseUpdater method doUpdate.
public void doUpdate(int newVersion, int oldVersion) {
if (mContext == null || mObjectClass == null) {
return;
}
AbsDatabaseConnectivity connectivity = null;
connectivity = getConnectivity(oldVersion);
if (connectivity == null) {
return;
}
Query query = new Query(mObjectClass);
List<DatabaseObject> oldObjects = connectivity.query(query);
connectivity.delete(query);
if (oldObjects == null) {
return;
}
final int N = oldObjects.size();
if (N <= 0) {
return;
}
DatabaseObject[] newObjects = new DatabaseObject[N];
DatabaseObject oldObj = null;
DatabaseObject newObj = null;
for (int i = 0; i < N; i++) {
oldObj = oldObjects.get(i);
newObj = DatabaseObjectFactory.createDatabaseObject(mObjectClass, newVersion);
updateObject(newObj, oldObj);
newObjects[i] = newObj;
}
connectivity = getConnectivity(newVersion);
if (connectivity == null) {
return;
}
connectivity.insert(newObjects);
}
use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class DatabaseConnectivity method onInsert.
@Override
protected int onInsert(DatabaseObject[] objects) {
if (objects == null) {
return 0;
}
final int count = objects.length;
if (count <= 0) {
return 0;
}
if (checkProviderPreparation() == false) {
return 0;
}
ContentValues[] values = new ContentValues[count];
Uri uri = ProviderUriBuilder.buildQueryUri(mAuthority, mObjectClass, getDatabaseVersion());
if (uri == null) {
return 0;
}
final Template template = objects[0].getTemplate();
if (template == null) {
return 0;
}
final String table = DatabaseObject.classToTable(mObjectClass);
if (table == null) {
return 0;
}
final DatabaseObject sample = objects[0];
uri = ProviderUriBuilder.attachCreateTableParamter(uri, sample.toSQLTableCreationString());
if (uri == null) {
return 0;
}
for (int i = 0; i < count; i++) {
values[i] = objects[i].getValues();
}
return mContentResovler.bulkInsert(uri, values);
}
Aggregations