Java Code Examples for com.activeandroid.Model

The following are top voted examples for showing how to use com.activeandroid.Model. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: ContentProvider.java   View source code 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	final Class<? extends Model> type = getModelType(uri);
	final Cursor cursor = Cache.openDatabase().query(
			Cache.getTableName(type),
			projection,
			selection,
			selectionArgs,
			null,
			null,
			sortOrder);

	cursor.setNotificationUri(getContext().getContentResolver(), uri);

	return cursor;
}
 
Example 2
Project: GitHub   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Two different rows in a table should not be equal (different ids).
 */	
public void testEqualsDifferentRows() {
	MockModel model1 = new MockModel();
	MockModel model2 = new MockModel();
	MockModel model3;

	model1.save();
	model2.save();
	model3 = Model.load(MockModel.class, model1.getId());

       // Not equal to each other.
	assertFalse(model1.equals(model2));
	assertFalse(model2.equals(model1));

       // Equal to each other when loaded.
	assertTrue(model1.equals(model3));
	assertTrue(model1.equals(model3));

       // Loaded model is not equal to a different model.
	assertFalse(model3.equals(model2));
	assertFalse(model2.equals(model3));
}
 
Example 3
Project: GitHub   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Tests hashcode for new instances.
 */	
public void testHashCode() {
	Set<Model> set = new HashSet<Model>();
	Model m1 = new MockModel();
	Model m2 = new MockModel();
	Model m3 = new AnotherMockModel();

	assertFalse(m1.hashCode() == m2.hashCode()); // hashes for unsaved models must not match
	set.add(m1);
	set.add(m2);
	assertEquals(2, set.size()); //try in a set

	assertFalse(m1.hashCode() == m3.hashCode());
	set.add(m3);
	assertEquals(3, set.size());
}
 
Example 4
Project: GitHub   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Two rows in a table should have different hashcodes.
 */
public void testHashCodeDifferentRows() {
	Set<Model> set = new HashSet<Model>();
	Model m1 = new MockModel();
	Model m2 = new MockModel();
	Model m3;

	m1.save();
	m2.save();
	m3 = Model.load(MockModel.class, m1.getId());

	assertEquals(m1.hashCode(), m3.hashCode());
	assertFalse(m1.hashCode() == m2.hashCode());
	set.add(m1);
	set.add(m2);
	set.add(m3);
	assertEquals(2, set.size());
}
 
Example 5
Project: umeng_community_android   File: FeedDBAPIImpl.java   View source code 6 votes vote down vote up
private void removeFeedRelativeItems() throws ClassNotFoundException {
    // 获取所有缓存的Feed
    List<FeedItem> cacheFeedItems = new Select().from(FeedItem.class)
            .where("category='NORMAL'").execute();

    Class<? extends Model> feedLikeClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedLike");
    Class<? extends Model> feedCommentClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedComment");
    Class<? extends Model> feedTopicClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedTopic");
    Class<? extends Model> feedCreatorClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedCreator");
    Class<? extends Model> feedFriendClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedFriends");

    for (FeedItem feedItem : cacheFeedItems) {
        // 移除like相关
        removeRelativeLike(feedItem.id, feedLikeClass);
        // 移除Feed相关的Comment
        removeRelativeComment(feedItem.id, feedCommentClass);
        new Delete().from(feedTopicClass).where("feed_id=?", feedItem.id)
                .execute();
        new Delete().from(feedCreatorClass).where("feed_id=?", feedItem.id)
                .execute();
        new Delete().from(feedFriendClass).where("feed_id=?", feedItem.id)
                .execute();
    }
}
 
Example 6
Project: clear-todolist   File: ContentProvider.java   View source code 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	final Class<? extends Model> type = getModelType(uri);
	final Cursor cursor = Cache.openDatabase().query(
			Cache.getTableName(type),
			projection,
			selection,
			selectionArgs,
			null,
			null,
			sortOrder);

	cursor.setNotificationUri(getContext().getContentResolver(), uri);

	return cursor;
}
 
Example 7
Project: clear-todolist   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Two different rows in a table should not be equal (different ids).
 */	
public void testEqualsDifferentRows() {
	MockModel model1 = new MockModel();
	MockModel model2 = new MockModel();
	MockModel model3;

	model1.save();
	model2.save();
	model3 = Model.load(MockModel.class, model1.getId());

       // Not equal to each other.
	assertFalse(model1.equals(model2));
	assertFalse(model2.equals(model1));

       // Equal to each other when loaded.
	assertTrue(model1.equals(model3));
	assertTrue(model1.equals(model3));

       // Loaded model is not equal to a different model.
	assertFalse(model3.equals(model2));
	assertFalse(model2.equals(model3));
}
 
Example 8
Project: clear-todolist   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Tests hashcode for new instances.
 */	
public void testHashCode() {
	Set<Model> set = new HashSet<Model>();
	Model m1 = new MockModel();
	Model m2 = new MockModel();
	Model m3 = new AnotherMockModel();

	assertFalse(m1.hashCode() == m2.hashCode()); // hashes for unsaved models must not match
	set.add(m1);
	set.add(m2);
	assertEquals(2, set.size()); //try in a set

	assertFalse(m1.hashCode() == m3.hashCode());
	set.add(m3);
	assertEquals(3, set.size());
}
 
Example 9
Project: clear-todolist   File: ModelTest.java   View source code 6 votes vote down vote up
/**
 * Two rows in a table should have different hashcodes.
 */
public void testHashCodeDifferentRows() {
	Set<Model> set = new HashSet<Model>();
	Model m1 = new MockModel();
	Model m2 = new MockModel();
	Model m3;

	m1.save();
	m2.save();
	m3 = Model.load(MockModel.class, m1.getId());

	assertEquals(m1.hashCode(), m3.hashCode());
	assertFalse(m1.hashCode() == m2.hashCode());
	set.add(m1);
	set.add(m2);
	set.add(m3);
	assertEquals(2, set.size());
}
 
Example 10
Project: AndroidGeek   File: FeedDBAPIImpl.java   View source code 6 votes vote down vote up
private void removeFeedRelativeItems() throws ClassNotFoundException {
    // 获取所有缓存的Feed
    List<FeedItem> cacheFeedItems = new Select().from(FeedItem.class)
            .where("category='NORMAL'").execute();

    Class<? extends Model> feedLikeClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedLike");
    Class<? extends Model> feedCommentClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedComment");
    Class<? extends Model> feedTopicClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedTopic");
    Class<? extends Model> feedCreatorClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedCreator");
    Class<? extends Model> feedFriendClass = refectModelClz("com.umeng.comm.core.beans.relation.FeedFriends");

    for (FeedItem feedItem : cacheFeedItems) {
        // 移除like相关
        removeRelativeLike(feedItem.id, feedLikeClass);
        // 移除Feed相关的Comment
        removeRelativeComment(feedItem.id, feedCommentClass);
        new Delete().from(feedTopicClass).where("feed_id=?", feedItem.id)
                .execute();
        new Delete().from(feedCreatorClass).where("feed_id=?", feedItem.id)
                .execute();
        new Delete().from(feedFriendClass).where("feed_id=?", feedItem.id)
                .execute();
    }
}
 
Example 11
Project: mobile-android-survey-app   File: ContentProvider.java   View source code 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	final Class<? extends Model> type = getModelType(uri);
	final Cursor cursor = Cache.openDatabase().query(
			Cache.getTableName(type),
			projection,
			selection,
			selectionArgs,
			null,
			null,
			sortOrder);

	cursor.setNotificationUri(getContext().getContentResolver(), uri);

	return cursor;
}
 
Example 12
Project: ocara   File: ModelManagerImpl.java   View source code 6 votes vote down vote up
@Override
public void deleteAuditObject(AuditObject auditObject) {
    Timber.v("auditObject delete : %d", auditObject.getId());

    ActiveAndroid.beginTransaction();

    try {
        deleteAllComments(auditObject.getComments());
        updateModificationDate(auditObject.getAudit());
        Model.delete(AuditObject.class, auditObject.getId());

        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }

    Timber.v("auditObject deleted");
}
 
Example 13
Project: ocara   File: ModelManagerImpl.java   View source code 6 votes vote down vote up
@Override
public void deleteComment(Comment comment) {
    Timber.v("comment delete : %d", comment.getId());

    String attachment = comment.getAttachment();

    if (StringUtils.isNotBlank(attachment)) {
        File attachementFile = new File(attachment);
        FileUtils.deleteQuietly(attachementFile);
    }
    Audit audit = comment.getAudit();

    updateModificationDate(audit);
    Model.delete(Comment.class, comment.getId());

    Timber.v("comment deleted");
}
 
Example 14
Project: our-alliance-android   File: MatchDetail2015.java   View source code 6 votes vote down vote up
public void loadMatchScouting() {
    AsyncExecutor.create().execute(new AsyncExecutor.RunnableEx() {
        @Override
        public void run() throws Exception {
            if (getScoutingId() != 0) {
                MatchScouting2015 scouting = Model.load(MatchScouting2015.class, getScoutingId());
                if(null!=scouting) {
                    EventBus.getDefault().post(new LoadMatchScouting(scouting));
                } else {
                    Timber.d("match scouting null " + getScoutingId());
                }
            } else {
                Timber.d("match scouting id 0 == "+getScoutingId());
            }
        }
    });
}
 
Example 15
Project: our-alliance-android   File: TeamDetail2014.java   View source code 6 votes vote down vote up
public void loadScouting() {
    AsyncExecutor.create().execute(new AsyncExecutor.RunnableEx() {
        @Override
        public void run() throws Exception {
            TeamScouting2014 scouting = null;
            int year = getPrefs().getYear();
            try {
                scouting = new Select().from(TeamScouting2014.class).where(TeamScouting2014.TEAM+"=?", getTeamId()).executeSingle();
            } catch(NullPointerException e) {
                Team team = Model.load(Team.class, getTeamId());
                scouting = (TeamScouting2014) new TeamScouting2014();
                scouting.setTeam(team);
            }
            if(null!=scouting) {
                EventBus.getDefault().post(new LoadScouting(scouting));
            }
        }
    });
}
 
Example 16
Project: our-alliance-android   File: MatchDetail2014.java   View source code 6 votes vote down vote up
public void loadMatchScouting() {
    AsyncExecutor.create().execute(new AsyncExecutor.RunnableEx() {
        @Override
        public void run() throws Exception {
            if (getScoutingId() != 0) {
                MatchScouting2014 scouting = Model.load(MatchScouting2014.class, getScoutingId());
                if(null!=scouting) {
                    EventBus.getDefault().post(new LoadMatchScouting(scouting));
                } else {
                    Timber.d("match scouting null " + getScoutingId());
                }
            } else {
                Timber.d("match scouting id 0 == "+getScoutingId());
            }
        }
    });
}
 
Example 17
Project: Wabbit-Messenger---android-client   File: ContentProvider.java   View source code 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	final Class<? extends Model> type = getModelType(uri);
	final Cursor cursor = Cache.openDatabase().query(
			Cache.getTableName(type),
			projection,
			selection,
			selectionArgs,
			null,
			null,
			sortOrder);

	cursor.setNotificationUri(getContext().getContentResolver(), uri);

	return cursor;
}
 
Example 18
Project: ActiveAndroid-Validation   File: UniqueValidator.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc }
 */
@Override
public boolean isValid(IValueDescriptor<Object> value) {
	Model model = value.getModel();

	From from = new Select().from(model.getClass());
	Model existing;

	if (value.getValue() == null) {
		existing = from.where(value.getColumnName() + " IS NULL").executeSingle();
	} else {
		existing = from.where(value.getColumnName() + " = ?", value.getValue()).executeSingle();
	}

	return existing == null || existing.getId().equals(value.getModel().getId());
}
 
Example 19
Project: GitHub   File: From.java   View source code 5 votes vote down vote up
public From(Class<? extends Model> table, Sqlable queryBase) {
	mType = table;
	mJoins = new ArrayList<Join>();
	mQueryBase = queryBase;

	mJoins = new ArrayList<Join>();
	mArguments = new ArrayList<Object>();
}
 
Example 20
Project: GitHub   File: From.java   View source code 5 votes vote down vote up
public <T extends Model> List<T> execute() {
	if (mQueryBase instanceof Select) {
		return SQLiteUtils.rawQuery(mType, toSql(), getArguments());
		
	} else {
		SQLiteUtils.execSql(toSql(), getArguments());
		Cache.getContext().getContentResolver().notifyChange(ContentProvider.createUri(mType, null), null);
		return null;
		
	}
}
 
Example 21
Project: GitHub   File: From.java   View source code 5 votes vote down vote up
public <T extends Model> T executeSingle() {
	if (mQueryBase instanceof Select) {
		limit(1);
		return (T) SQLiteUtils.rawQuerySingle(mType, toSql(), getArguments());
		
	} else {
		limit(1);
		SQLiteUtils.rawQuerySingle(mType, toSql(), getArguments()).delete();
		return null;
		
	}
}
 
Example 22
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
@Override
public String getType(Uri uri) {
	final int match = URI_MATCHER.match(uri);

	String cachedMimeType = sMimeTypeCache.get(match);
	if (cachedMimeType != null) {
		return cachedMimeType;
	}

	final Class<? extends Model> type = getModelType(uri);
	final boolean single = ((match % 2) == 0);

	StringBuilder mimeType = new StringBuilder();
	mimeType.append("vnd");
	mimeType.append(".");
	mimeType.append(sAuthority);
	mimeType.append(".");
	mimeType.append(single ? "item" : "dir");
	mimeType.append("/");
	mimeType.append("vnd");
	mimeType.append(".");
	mimeType.append(sAuthority);
	mimeType.append(".");
	mimeType.append(Cache.getTableName(type));

	sMimeTypeCache.append(match, mimeType.toString());

	return mimeType.toString();
}
 
Example 23
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
@Override
public Uri insert(Uri uri, ContentValues values) {
	final Class<? extends Model> type = getModelType(uri);
	final Long id = Cache.openDatabase().insert(Cache.getTableName(type), null, values);

	if (id != null && id > 0) {
		Uri retUri = createUri(type, id);
		notifyChange(retUri);

		return retUri;
	}

	return null;
}
 
Example 24
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
	final Class<? extends Model> type = getModelType(uri);
	final int count = Cache.openDatabase().update(Cache.getTableName(type), values, selection, selectionArgs);

	notifyChange(uri);

	return count;
}
 
Example 25
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
	final Class<? extends Model> type = getModelType(uri);
	final int count = Cache.openDatabase().delete(Cache.getTableName(type), selection, selectionArgs);

	notifyChange(uri);

	return count;
}
 
Example 26
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
public static Uri createUri(Class<? extends Model> type, Long id) {
	final StringBuilder uri = new StringBuilder();
	uri.append("content://");
	uri.append(sAuthority);
	uri.append("/");
	uri.append(Cache.getTableName(type).toLowerCase());

	if (id != null) {
		uri.append("/");
		uri.append(id.toString());
	}

	return Uri.parse(uri.toString());
}
 
Example 27
Project: GitHub   File: ContentProvider.java   View source code 5 votes vote down vote up
private Class<? extends Model> getModelType(Uri uri) {
	final int code = URI_MATCHER.match(uri);
	if (code != UriMatcher.NO_MATCH) {
		return TYPE_CODES.get(code);
	}

	return null;
}
 
Example 28
Project: GitHub   File: ReflectionUtils.java   View source code 5 votes vote down vote up
public static Set<Field> getDeclaredColumnFields(Class<?> type) {
	Set<Field> declaredColumnFields = Collections.emptySet();
	
	if (ReflectionUtils.isSubclassOf(type, Model.class) || Model.class.equals(type)) {
		declaredColumnFields = new LinkedHashSet<Field>();
		
		Field[] fields = type.getDeclaredFields();
		Arrays.sort(fields, new Comparator<Field>() {
			@Override
			public int compare(Field field1, Field field2) {
				return field2.getName().compareTo(field1.getName());
			}
		});
		for (Field field : fields) {
			if (field.isAnnotationPresent(Column.class)) {
				declaredColumnFields.add(field);
			}
		}

		Class<?> parentType = type.getSuperclass();
		if (parentType != null) {
			declaredColumnFields.addAll(getDeclaredColumnFields(parentType));
		}
	}
	
	return declaredColumnFields;		
}
 
Example 29
Project: GitHub   File: SQLiteUtils.java   View source code 5 votes vote down vote up
public static <T extends Model> List<T> rawQuery(Class<? extends Model> type, String sql, String[] selectionArgs) {
	Cursor cursor = Cache.openDatabase().rawQuery(sql, selectionArgs);
	List<T> entities = processCursor(type, cursor);
	cursor.close();

	return entities;
}
 
Example 30
Project: GitHub   File: SQLiteUtils.java   View source code 5 votes vote down vote up
public static <T extends Model> T rawQuerySingle(Class<? extends Model> type, String sql, String[] selectionArgs) {
	List<T> entities = rawQuery(type, sql, selectionArgs);

	if (entities.size() > 0) {
		return entities.get(0);
	}

	return null;
}
 
Example 31
Project: GitHub   File: SQLiteUtils.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
	StringBuilder definition = new StringBuilder();

	Class<?> type = field.getType();
	final String name = tableInfo.getColumnName(field);
	final TypeSerializer typeSerializer = Cache.getParserForType(field.getType());
	final Column column = field.getAnnotation(Column.class);

	if (typeSerializer != null) {
		type = typeSerializer.getSerializedType();
	}

	if (TYPE_MAP.containsKey(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(TYPE_MAP.get(type).toString());
	}
	else if (ReflectionUtils.isModel(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.INTEGER.toString());
	}
	else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.TEXT.toString());
	}

	if (!TextUtils.isEmpty(definition)) {

		if (name.equals(tableInfo.getIdName())) {
			definition.append(" PRIMARY KEY AUTOINCREMENT");
		}else if(column!=null){
			if (column.length() > -1) {
				definition.append("(");
				definition.append(column.length());
				definition.append(")");
			}

			if (column.notNull()) {
				definition.append(" NOT NULL ON CONFLICT ");
				definition.append(column.onNullConflict().toString());
			}

			if (column.unique()) {
				definition.append(" UNIQUE ON CONFLICT ");
				definition.append(column.onUniqueConflict().toString());
			}
		}

		if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
			definition.append(" REFERENCES ");
			definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName());
			definition.append("("+tableInfo.getIdName()+")");
			definition.append(" ON DELETE ");
			definition.append(column.onDelete().toString().replace("_", " "));
			definition.append(" ON UPDATE ");
			definition.append(column.onUpdate().toString().replace("_", " "));
		}
	}
	else {
		Log.e("No type mapping for: " + type.toString());
	}

	return definition.toString();
}
 
Example 32
Project: GitHub   File: ConfigurationTest.java   View source code 5 votes vote down vote up
public void testCreateConfigurationWithMockModel() {
    Configuration conf = new Configuration.Builder(getContext())
            .addModelClass(ConfigurationTestModel.class)
            .create();
    List<Class<? extends Model>> modelClasses = conf.getModelClasses();
    assertEquals(1, modelClasses.size());
    assertTrue(conf.isValid());
}
 
Example 33
Project: GitHub   File: ModelTest.java   View source code 5 votes vote down vote up
/**
 * Equals should not be true for different model classes.
 */	
public void testEqualsDifferentModel() {
	Model model1 = new MockModel();
	Model model2 = new AnotherMockModel();

	assertFalse(model1.equals(model2));
}
 
Example 34
Project: xDrip   File: UploaderQueue.java   View source code 5 votes vote down vote up
public static UploaderQueue newEntry(String action, Model obj) {
    UserError.Log.d(TAG, "new entry called");
    final UploaderQueue result = new UploaderQueue();
    result.bitfield_wanted = DEFAULT_UPLOAD_CIRCUITS
            | (Pref.getBooleanDefaultFalse("cloud_storage_mongodb_enable") ? MONGO_DIRECT : 0)
            | (Pref.getBooleanDefaultFalse("cloud_storage_api_enable") ? NIGHTSCOUT_RESTAPI : 0)
            | (Pref.getBooleanDefaultFalse("cloud_storage_influxdb_enable") ? INFLUXDB_RESTAPI : 0)
            | (Pref.getBooleanDefaultFalse("wear_sync") ? WATCH_WEARAPI : 0);
    if (result.bitfield_wanted == 0) return null; // no queue required
    result.timestamp = JoH.tsl();
    result.reference_id = obj.getId();
    // TODO this probably could be neater
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BgReading ? ((BgReading) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Treatments ? ((Treatments) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Calibration ? ((Calibration) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BloodTest ? ((BloodTest) obj).uuid : null;

    if (result.reference_uuid == null) {
        Log.d(TAG, "reference_uuid was null so refusing to create new entry");
        return null;
    }

    if (result.reference_id < 0) {
        UserError.Log.wtf(TAG, "ERROR ref id was: " + result.reference_id + " for uuid: " + result.reference_uuid + " refusing to create");
        return null;
    }

    result.action = action;

    result.bitfield_complete = 0;
    result.type = obj.getClass().getSimpleName();
    result.saveit();
    if (d) UserError.Log.d(TAG, result.toS());
    last_new_entry = JoH.tsl();
    return result;
}
 
Example 35
Project: xDrip   File: UploaderQueue.java   View source code 5 votes vote down vote up
public static UploaderQueue newEntryForWatch(String action, Model obj) {
    UserError.Log.d(TAG, "new entry called for watch");
    final UploaderQueue result = new UploaderQueue();
    result.bitfield_wanted = DEFAULT_UPLOAD_CIRCUITS
            | (Pref.getBooleanDefaultFalse("wear_sync") ? WATCH_WEARAPI : 0);
    if (result.bitfield_wanted == 0) return null; // no queue required
    result.timestamp = JoH.tsl();
    result.reference_id = obj.getId();
    // TODO this probably could be neater
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BgReading ? ((BgReading) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Treatments ? ((Treatments) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Calibration ? ((Calibration) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BloodTest ? ((BloodTest) obj).uuid : null;

    if (result.reference_uuid == null) {
        Log.d(TAG, "reference_uuid was null so refusing to create new entry");
        return null;
    }

    if (result.reference_id < 0) {
        UserError.Log.wtf(TAG, "Watch ERROR ref id was: " + result.reference_id + " for uuid: " + result.reference_uuid + " refusing to create");
        return null;
    }

    result.action = action;

    result.bitfield_complete = 0;
    result.type = obj.getClass().getSimpleName();
    result.saveit();
    if (d) UserError.Log.d(TAG, result.toS());
    last_new_entry = JoH.tsl();
    return result;
}
 
Example 36
Project: xDrip-plus   File: UploaderQueue.java   View source code 5 votes vote down vote up
public static UploaderQueue newEntry(String action, Model obj) {
    UserError.Log.d(TAG, "new entry called");
    final UploaderQueue result = new UploaderQueue();
    result.bitfield_wanted = DEFAULT_UPLOAD_CIRCUITS
            | (Pref.getBooleanDefaultFalse("cloud_storage_mongodb_enable") ? MONGO_DIRECT : 0)
            | (Pref.getBooleanDefaultFalse("cloud_storage_api_enable") ? NIGHTSCOUT_RESTAPI : 0)
            | (Pref.getBooleanDefaultFalse("cloud_storage_influxdb_enable") ? INFLUXDB_RESTAPI : 0)
            | (Pref.getBooleanDefaultFalse("wear_sync") ? WATCH_WEARAPI : 0);
    if (result.bitfield_wanted == 0) return null; // no queue required
    result.timestamp = JoH.tsl();
    result.reference_id = obj.getId();
    // TODO this probably could be neater
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BgReading ? ((BgReading) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Treatments ? ((Treatments) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Calibration ? ((Calibration) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BloodTest ? ((BloodTest) obj).uuid : null;

    if (result.reference_uuid == null) {
        Log.d(TAG, "reference_uuid was null so refusing to create new entry");
        return null;
    }

    if (result.reference_id < 0) {
        UserError.Log.wtf(TAG, "ERROR ref id was: " + result.reference_id + " for uuid: " + result.reference_uuid + " refusing to create");
        return null;
    }

    result.action = action;

    result.bitfield_complete = 0;
    result.type = obj.getClass().getSimpleName();
    result.saveit();
    if (d) UserError.Log.d(TAG, result.toS());
    last_new_entry = JoH.tsl();
    return result;
}
 
Example 37
Project: xDrip-plus   File: UploaderQueue.java   View source code 5 votes vote down vote up
public static UploaderQueue newEntryForWatch(String action, Model obj) {
    UserError.Log.d(TAG, "new entry called for watch");
    final UploaderQueue result = new UploaderQueue();
    result.bitfield_wanted = DEFAULT_UPLOAD_CIRCUITS
            | (Pref.getBooleanDefaultFalse("wear_sync") ? WATCH_WEARAPI : 0);
    if (result.bitfield_wanted == 0) return null; // no queue required
    result.timestamp = JoH.tsl();
    result.reference_id = obj.getId();
    // TODO this probably could be neater
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BgReading ? ((BgReading) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Treatments ? ((Treatments) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof Calibration ? ((Calibration) obj).uuid : null;
    if (result.reference_uuid == null)
        result.reference_uuid = obj instanceof BloodTest ? ((BloodTest) obj).uuid : null;

    if (result.reference_uuid == null) {
        Log.d(TAG, "reference_uuid was null so refusing to create new entry");
        return null;
    }

    if (result.reference_id < 0) {
        UserError.Log.wtf(TAG, "Watch ERROR ref id was: " + result.reference_id + " for uuid: " + result.reference_uuid + " refusing to create");
        return null;
    }

    result.action = action;

    result.bitfield_complete = 0;
    result.type = obj.getClass().getSimpleName();
    result.saveit();
    if (d) UserError.Log.d(TAG, result.toS());
    last_new_entry = JoH.tsl();
    return result;
}
 
Example 38
Project: daily-dozen-android   File: TruncatableModel.java   View source code 5 votes vote down vote up
public static void truncate(Class<? extends Model> type){
    final String tableName = Cache.getTableInfo(type).getTableName();

    // Delete all rows from table
    ActiveAndroid.execSQL(String.format("DELETE FROM %s;", tableName));

    // Reset ids
    ActiveAndroid.execSQL(String.format("DELETE FROM sqlite_sequence WHERE name='%s';", tableName));
}
 
Example 39
Project: umeng_community_android   File: FeedDBAPIImpl.java   View source code 5 votes vote down vote up
private void removeRelativeLike(String feedId, Class<? extends Model> feedLikeClass)
        throws ClassNotFoundException {
    List<Like> likes = new Select().from(Like.class).innerJoin(feedLikeClass)
            .on("like._id=feed_like.like_id").where("feed_like.feed_id=?", feedId)
            .execute();
    // 删除feed_like表中的记录

    new Delete().from(feedLikeClass).where("feed_id=?", feedId);
    Class<? extends Model> likeCreatorClz = feedLikeClass = refectModelClz("com.umeng.comm.core.beans.relation.LikeCreator");
    for (Like like : likes) {
        new Delete().from(likeCreatorClz).where("like_id=?", like.id).execute();
        new Delete().from(Like.class).where("_id=?", like.id).execute();
    }
}
 
Example 40
Project: umeng_community_android   File: FeedDBAPIImpl.java   View source code 5 votes vote down vote up
private void removeRelativeComment(String feedId,
        Class<? extends Model> feedCommentClass)
        throws ClassNotFoundException {
    List<Comment> comments = new Select().from(Comment.class)
            .innerJoin(feedCommentClass)
            .on("comment._id=feed_comment.comment_id")
            .where("feed_comment.feed_id=?", feedId)
            .execute();
    for (Comment comment : comments) {
        new Delete().from(feedCommentClass).where("comment_id=?", comment.id).execute();
        new Delete().from(Comment.class).where("_id=?", comment.id).execute();
    }
}