Java Code Examples for com.j256.ormlite.dao.Dao#CreateOrUpdateStatus

The following examples show how to use com.j256.ormlite.dao.Dao#CreateOrUpdateStatus . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Packets.java    From PacketProxy with Apache License 2.0 5 votes vote down vote up
public void update(Packet packet) throws Exception {
	if(database.isAlertFileSize()){
		notifyObservers(true);
	}
	Dao.CreateOrUpdateStatus status;
	synchronized (dao) {
		status = dao.createOrUpdate(packet);
	}
	if (status.isCreated()) {
		notifyObservers(packet.getId() * -1);
	} else {
		notifyObservers(packet.getId());
	}
}
 
Example 2
Source File: QueryGetRepos.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute() throws Exception {
    final Call<List<DTORepo>> loCall = gitHubService.listRepos(user);
    final Response<List<DTORepo>> loExecute = loCall.execute();

    if (isCached(loExecute)) {
        // not modified, no need to do anything
        return;
    }

    results = loExecute.body();

    final int liDeleted = daoRepo.deleteBuilder().delete();

    if (BuildConfig.DEBUG && DEBUG) {
        Logger.t(TAG).d("deleted row count = %d", liDeleted);
    }

    int liCount = 0;
    for (final DTORepo loDTORepo : results) {
        final RepoEntity loRepo = transformerRepo.transform(loDTORepo, RepoEntity.class);
        loRepo.avatarUrl = loDTORepo.owner.avatarUrl;
        final Dao.CreateOrUpdateStatus loStatus = daoRepo.createOrUpdate(loRepo);
        if (loStatus.isCreated() || loStatus.isUpdated()) {
            ++liCount;
        }
    }

    if (BuildConfig.DEBUG && DEBUG) {
        Logger.t(TAG).d("created or updated row count = %d", liCount);
    }
}
 
Example 3
Source File: BaseRxDao.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 增加或更新一条记录
 */
public Observable<Dao.CreateOrUpdateStatus> createOrUpdateWithRx(final T t) {
    return Observable.create(new ObservableOnSubscribe<Dao.CreateOrUpdateStatus>() {
        @Override
        public void subscribe(ObservableEmitter<Dao.CreateOrUpdateStatus> e) throws Exception {
            e.onNext(createOrUpdate(t));
            e.onComplete();
        }
    }).compose(RxUtil.<Dao.CreateOrUpdateStatus>applySchedulers());
}
 
Example 4
Source File: BaseManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void createOrUpdate(Object object, boolean notify) {
    try {
        Dao.CreateOrUpdateStatus status = dao.createOrUpdate((T) object);

        if (notify) {
            notifyObservers((T) object, status.isCreated() ? CREATE_ACTION : UPDATE_ACTION);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(TAG, "createOrUpdate(Object) - " + e.getMessage());
    }
}
 
Example 5
Source File: PstRequest.java    From Presentation with Apache License 2.0 5 votes vote down vote up
private int getPinsFromResponse(String response) {
    JsonObject jsonObject = (JsonObject) new JsonParser().parse(response);
    JsonArray jsonArrayPins = jsonObject.getAsJsonArray("pins");

    mAffectedRows = 0;
    for (int i = 0; i < jsonArrayPins.size(); i++) {
        JsonObject tmp = (JsonObject) jsonArrayPins.get(i);
        Pin pin = mGson.fromJson(tmp, Pin.class);
        Pin.File file = mGson.fromJson(tmp.getAsJsonObject("file"), Pin.File.class);
        pin.setKey(file.key);
        pin.setWidth(file.width);
        pin.setHeight(file.height);

        // ignore gif and some 'bad' images.
        if (file.frames == 1 && (file.width / (float) file.height < .38f)) {
            try {
                Dao.CreateOrUpdateStatus status =
                        mDatabaseHelper.getPinsDAO().createOrUpdate(pin);

                mAffectedRows += status.getNumLinesChanged();
            } catch (SQLException e) {
                Logger.e(e.getMessage());
            }
        }
    }

    mListener.onSaved(mAffectedRows);
    return mAffectedRows;
}
 
Example 6
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * 增加或更新一条记录
 *
 * @param t 新增或更新数据实体
 * @return
 */
public Dao.CreateOrUpdateStatus createOrUpdate(T t) throws SQLException {
    return ormLiteDao.createOrUpdate(t);
}