Search in sources :

Example 56 with DatabaseObject

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;
}
Also used : ArrayList(java.util.ArrayList) DatabaseObject(com.dailystudio.dataobject.DatabaseObject)

Example 57 with DatabaseObject

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);
}
Also used : Query(com.dailystudio.dataobject.query.Query) DatabaseObject(com.dailystudio.dataobject.DatabaseObject)

Example 58 with DatabaseObject

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);
}
Also used : ContentValues(android.content.ContentValues) DatabaseObject(com.dailystudio.dataobject.DatabaseObject) Uri(android.net.Uri) Template(com.dailystudio.dataobject.Template)

Aggregations

DatabaseObject (com.dailystudio.dataobject.DatabaseObject)58 Query (com.dailystudio.dataobject.query.Query)38 Cursor (android.database.Cursor)28 ExpressionToken (com.dailystudio.dataobject.query.ExpressionToken)27 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 Template (com.dailystudio.dataobject.Template)23 QueryObject (com.dailystudio.dataobject.samples.QueryObject)23 Column (com.dailystudio.dataobject.Column)19 SampleObject2 (com.dailystudio.dataobject.samples.SampleObject2)17 Uri (android.net.Uri)15 SampleObject1 (com.dailystudio.dataobject.samples.SampleObject1)14 ContentValues (android.content.ContentValues)13 ContentResolver (android.content.ContentResolver)12 OrderingToken (com.dailystudio.dataobject.query.OrderingToken)8 SQLException (android.database.SQLException)6 DatabaseConnectivity (com.dailystudio.dataobject.database.DatabaseConnectivity)3 ProjectionObject (com.dailystudio.dataobject.samples.ProjectionObject)3 ArrayList (java.util.ArrayList)3 DynamicColumnsObject (com.dailystudio.dataobject.samples.DynamicColumnsObject)2 List (java.util.List)2