Java Code Examples for com.raizlabs.android.dbflow.sql.language.Select

The following examples show how to use com.raizlabs.android.dbflow.sql.language.Select. These examples are extracted from open source projects. 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
public static void addLocalHistory(String url){
    ModelAdapter<LocalHistoryModel> manager =
            FlowManager.getModelAdapter(LocalHistoryModel.class);

    LocalHistoryModel oldModel = new Select()
            .from(LocalHistoryModel.class)
            .where(LocalHistoryModel_Table.url.eq(url))
            .querySingle();

    if (oldModel != null){
        manager.delete(oldModel);
    }

    LocalHistoryModel model = new LocalHistoryModel();
    model.setUrl(url);
    manager.insert(model);
    judgeHistoryNum();
}
 
Example 2
public static void addLocalHistory(String label){
    Log.d("DBLocalSearchManager", "执行到这了");
    ModelAdapter<LocalLabel> manager =
            FlowManager.getModelAdapter(LocalLabel.class);

    LocalLabel oldModel = new Select()
            .from(LocalLabel.class)
            .where(LocalLabel_Table.label.eq(label))
            .querySingle();

    if (oldModel != null){
        manager.delete(oldModel);
    }

    LocalLabel model = new LocalLabel();
    model.setLabel(label);
    manager.insert(model);
    judgeHistoryNum();
}
 
Example 3
Source Project: coderfun   Source File: FunDao.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static List<Results> getFun_Part() {
    List<Results> results = new ArrayList<>();
    List<PartDbBean> partDbBeen = new Select().from(PartDbBean.class).queryList();
    for (int i = 0; i < partDbBeen.size(); i++) {
        Results result = new Results();
        result.setWho(partDbBeen.get(i).who);
        result.setPublishedAt(partDbBeen.get(i).publishedAt);
        result.setDesc(partDbBeen.get(i).desc);
        result.setType(partDbBeen.get(i).type);
        result.setUrl(partDbBeen.get(i).url);
        result.setUsed(partDbBeen.get(i).used);
        result.set_id(partDbBeen.get(i).objectId);
        result.setCreatedAt(partDbBeen.get(i).createdAt);
        results.add(result);
    }
    return results;
}
 
Example 4
Source Project: coderfun   Source File: FunDao.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static List<List<Results>> getFun_Real() {
    List<RealDbBean> realDbBeen = new Select().from(RealDbBean.class).queryList();
    List<List<Results>> results_list = new ArrayList<>();
    for (int i = 0; i < realDbBeen.size() / 3; i++) {
        List<Results> results = new ArrayList<>();
        for (int j = 0; j < 3; j++) {
            int k= 3*i+j;
            Results result = new Results();
            result.setWho(realDbBeen.get(k).who);
            result.setPublishedAt(realDbBeen.get(k).publishedAt);
            result.setDesc(realDbBeen.get(k).desc);
            result.setType(realDbBeen.get(k).type);
            result.setUrl(realDbBeen.get(k).url);
            result.setUsed(realDbBeen.get(k).used);
            result.set_id(realDbBeen.get(k).objectId);
            result.setCreatedAt(realDbBeen.get(k).createdAt);
            results.add(result);
        }
        results_list.add(results);
    }
    return results_list;
}
 
Example 5
Source Project: coderfun   Source File: FunDao.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static List<Results> getFun_Girly() {
    List<Results> results = new ArrayList<>();
    List<GirlyDbBean> girlyDbBeen = new Select().from(GirlyDbBean.class).queryList();
    for (int i = 0; i < girlyDbBeen.size(); i++) {
        Results result = new Results();
        result.setWho(girlyDbBeen.get(i).who);
        result.setPublishedAt(girlyDbBeen.get(i).publishedAt);
        result.setDesc(girlyDbBeen.get(i).desc);
        result.setType(girlyDbBeen.get(i).type);
        result.setUrl(girlyDbBeen.get(i).url);
        result.setUsed(girlyDbBeen.get(i).used);
        result.set_id(girlyDbBeen.get(i).objectId);
        result.setCreatedAt(girlyDbBeen.get(i).createdAt);
        results.add(result);
    }
    return results;
}
 
Example 6
Source Project: AndroidDatabaseLibraryComparison   Source File: DBFlowTester.java    License: MIT License 6 votes vote down vote up
public static void testAddressItems(Context context) {
    com.raizlabs.android.dbflow.sql.language.Delete.table(SimpleAddressItem.class);
    Collection<SimpleAddressItem> dbFlowModels =
            Generator.getAddresses(SimpleAddressItem.class, MainActivity.LOOP_COUNT);
    long startTime = System.currentTimeMillis();
    final Collection<SimpleAddressItem> finalDbFlowModels = dbFlowModels;
    TransactionManager.transact(DBFlowDatabase.NAME, new Runnable() {
        @Override
        public void run() {
            Saver.saveAll(finalDbFlowModels);
        }
    });
    EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.SAVE_TIME));

    startTime = System.currentTimeMillis();
    dbFlowModels = new Select().from(SimpleAddressItem.class).queryList();
    EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.LOAD_TIME));

    com.raizlabs.android.dbflow.sql.language.Delete.table(SimpleAddressItem.class);
}
 
Example 7
@JsonIgnore
public List<DashboardElement> queryRelatedDashboardElements() {
    if (isEmpty(getType())) {
        return new ArrayList<>();
    }

    List<DashboardElement> elements = new Select().from(DashboardElement.class)
            .where(Condition.column(DashboardElement$Table.DASHBOARDITEM_DASHBOARDITEM).is(getId()))
            .and(Condition.column(DashboardElement$Table.STATE).isNot(State.TO_DELETE.toString()))
            .queryList();

    if (elements == null) {
        elements = new ArrayList<>();
    }

    return elements;
}
 
Example 8
private void sendDashboardItemChanges() throws APIException {
    List<DashboardItem> dashboardItems = new Select()
            .from(DashboardItem.class)
            .where(Condition.column(DashboardItem$Table
                    .STATE).isNot(State.SYNCED))
            .orderBy(true, DashboardItem$Table.ID)
            .queryList();

    if (dashboardItems == null || dashboardItems.isEmpty()) {
        return;
    }

    for (DashboardItem dashboardItem : dashboardItems) {
        switch (dashboardItem.getState()) {
            case TO_POST: {
                postDashboardItem(dashboardItem);
                break;
            }
            case TO_DELETE: {
                deleteDashboardItem(dashboardItem);
                break;
            }
        }
    }
}
 
Example 9
private void sendDashboardElements() throws APIException {
    List<DashboardElement> elements = new Select()
            .from(DashboardElement.class)
            .where(Condition.column(DashboardElement$Table
                    .STATE).isNot(State.SYNCED))
            .orderBy(true, DashboardElement$Table.ID)
            .queryList();

    if (elements == null || elements.isEmpty()) {
        return;
    }

    for (DashboardElement element : elements) {
        switch (element.getState()) {
            case TO_POST: {
                postDashboardElement(element);
                break;
            }
            case TO_DELETE: {
                deleteDashboardElement(element);
                break;
            }
        }
    }
}
 
Example 10
public void syncDashboardContent() throws APIException {
    DateTime lastUpdated = DateTimeManager.getInstance()
            .getLastUpdated(ResourceType.DASHBOARDS_CONTENT);
    DateTime serverDateTime = mDhisApi
            .getSystemInfo().getServerDate();

    /* first we need to update api resources, dashboards
    and dashboard items */
    List<DashboardItemContent> dashboardItemContent =
            updateApiResources(lastUpdated);
    Queue<DbOperation> operations = new LinkedList<>();
    operations.addAll(DbUtils.createOperations(new Select()
            .from(DashboardItemContent.class).queryList(), dashboardItemContent));
    DbUtils.applyBatch(operations);



    DateTimeManager.getInstance()
            .setLastUpdated(ResourceType.DASHBOARDS_CONTENT, serverDateTime);
}
 
Example 11
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    long dashboardId = getArguments().getLong(Dashboard$Table.ID);
    mDashboard = new Select()
            .from(Dashboard.class)
            .where(Condition.column(Dashboard$Table
                    .ID).is(dashboardId))
            .querySingle();

    ButterKnife.bind(this, view);

    InputMethodManager imm = (InputMethodManager)
            getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mFilter.getWindowToken(), 0);

    mAdapter = new DashboardItemSearchDialogAdapter(
            LayoutInflater.from(getActivity()));
    mListView.setAdapter(mAdapter);
    mDialogLabel.setText(getString(R.string.add_dashboard_item));

    mResourcesMenu = new PopupMenu(getActivity(),mFilter, Gravity.END);
    mResourcesMenu.inflate(R.menu.menu_filter_resources);
    mResourcesMenu.setOnMenuItemClickListener(this);
}
 
Example 12
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mDashboard = new Select()
            .from(Dashboard.class)
            .where(Condition.column(Dashboard$Table
                    .ID).is(getArguments().getLong(Dashboard$Table.ID)))
            .querySingle();

    ButterKnife.bind(this, view);

    mDialogLabel.setText(getString(R.string.manage_dashboard));
    mActionName.setText(getString(R.string.edit_name));

    mDashboardName.setText(mDashboard.getDisplayName());
    mDeleteButton.setEnabled(mDashboard.getAccess().isDelete());

    setFragmentBarActionMode(false);
    //// FIXME: 22/03/2018 The api 29 => putDashboard api call override the server dashboard.
    //// But the dashboard app is incomplete.
    //// The dashboard needs all the fields and children fields before put dashboards in api 29 =>
    if(SystemInfo.isLoggedInServerWithLatestApiVersion()){
        mDashboardName.setEnabled(false);
    }
}
 
Example 13
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    ButterKnife.bind(this, view);

    long dashboardItemId = getArguments().getLong(DashboardItem$Table.ID);
    mDashboardItem = new Select()
            .from(DashboardItem.class)
            .where(Condition.column(DashboardItem$Table
                    .ID).is(dashboardItemId))
            .querySingle();

    List<DashboardElement> elements = new Select()
            .from(DashboardElement.class)
            .where(Condition.column(DashboardElement$Table
                    .DASHBOARDITEM_DASHBOARDITEM).is(dashboardItemId))
            .and(Condition.column(DashboardElement$Table
                    .STATE).isNot(State.TO_DELETE.toString()))
            .queryList();

    mDashboardItem.setDashboardElements(elements);
    mDialogLabel.setText(getString(R.string.create_interpretation));
}
 
Example 14
Source Project: MoeGallery   Source File: ImageRepository.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observable<List<? extends Image>> loadListFromHistory() {
    return Observable.create(new Observable.OnSubscribe<List<? extends Image>>() {
        @Override
        public void call(Subscriber<? super List<? extends Image>> subscriber) {
            try {
                String providerUri = mSetting.provider().
                        replace(Providers.SCHEME_HTTPS, "").
                        replace(Providers.SCHEME_HTTP, "");

                List<HistoryImage> historyImages = new Select().from(HistoryImage.class).where(
                        Condition.column(HistoryImage$Table.PREVIEWURL)
                                .like("%" + providerUri + "%")).
                        orderBy(false, HistoryImage$Table.LAST).queryList();
                for (Image image : historyImages) {
                    mImageList.add(image);
                }
                subscriber.onNext(mImageList);
                notifyDataSetChanged();
            } catch (Exception e) {
                e.printStackTrace();
                subscriber.onError(e);
            }
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
}
 
Example 15
Source Project: MoeGallery   Source File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
void switchFavorite() {
    Image image = currentImage;
    List<FavoriteImage> favoriteImages = new Select().from(FavoriteImage.class).where(
            Condition.column(FavoriteImage$Table.PREVIEWURL).eq(image.getPreviewUrl())).
            queryList();

    if (favoriteImages.size() == 1) {
        favoriteImages.get(0).delete();
        menuFavorite.setTitle(R.string.add_favorite);
        floatFavorite.setDrawableIcon(getResources().getDrawable(
                R.drawable.ic_favorite_border_white_48dp));
    } else {
        new FavoriteImage(image).save();
        menuFavorite.setTitle(R.string.remove_favorite);
        floatFavorite.setDrawableIcon(getResources().getDrawable(
                R.drawable.ic_favorite_white_48dp));
    }
}
 
Example 16
Source Project: iview-android-tv   Source File: ContentManagerBase.java    License: MIT License 6 votes vote down vote up
public List<EpisodeBaseModel> getRecentlyPlayed() {

        FlowCursorList<PlayHistory> cursor = new FlowCursorList<>(false,
                (new Select()).from(PlayHistory.class)
                        .orderBy("CASE WHEN "+PlayHistory$Table.PROGRESS+" >= 75 THEN 1 ELSE 0 END ASC, "+PlayHistory$Table.TIMESTAMP+" DESC")
                        .limit(30));

        List<EpisodeBaseModel> recent = new ArrayList<>();
        for (int i = 0, k = cursor.getCount(); i < k; i++) {
            PlayHistory history = cursor.getItem(i);
            EpisodeBaseModel ep = getEpisode(history.href);
            if (ep != null) {
                if (history.progress < 75) {
                    ep.setResumePosition(history.position);
                }
                ep.setRecent(true);
                recent.add(ep);
            }
        }
        return recent;
    }
 
Example 17
Source Project: amiibo   Source File: AmiiboDescriptorCache.java    License: GNU General Public License v2.0 6 votes vote down vote up
@NonNull
@Override
protected AmiiboDescriptor updateInDatabaseInternal(@NonNull AmiiboDescriptor object) {
    AmiiboDescriptor previous = new Select()
            .from(AmiiboDescriptor.class)
            .where(Condition.column(AmiiboDescriptor$Table.AMIIBO_IDENTIFIER)
                    .eq(object.amiibo_identifier.toLowerCase()))
            .querySingle();
    if (previous == null) {
        previous = object;
        object.insert();
    } else {
        previous.amiibo_identifier = object.amiibo_identifier.toLowerCase();
        previous.name = object.name;
        previous.update();
    }
    return previous;
}
 
Example 18
public static void judgeHistoryNum(){
    List<LocalHistoryModel> list = new Select().from(LocalHistoryModel.class).queryList();
    ModelAdapter<LocalHistoryModel> manager = FlowManager.getModelAdapter(LocalHistoryModel.class);
    if (list.size() <= Constant.DATABASE_NUM){
        return;
    }

    manager.delete(list.get(0));
}
 
Example 19
public static void judgeHistoryNum(){
    List<LocalLabel> list = new Select().from(LocalLabel.class).queryList();
    ModelAdapter<LocalLabel> manager = FlowManager.getModelAdapter(LocalLabel.class);
    if (list.size() <= Constant.LOCAL_LABEL_NUM){
        return;
    }

    manager.delete(list.get(0));
}
 
Example 20
Source Project: AndroidDatabaseLibraryComparison   Source File: DBFlowTester.java    License: MIT License 5 votes vote down vote up
public static void testAddressBooks(Context context) {
    com.raizlabs.android.dbflow.sql.language.Delete.tables(AddressItem.class,
            Contact.class, AddressBook.class);

    Collection<AddressBook> addressBooks = Generator.createAddressBooks(AddressBook.class,
            Contact.class, AddressItem.class,
            MainActivity.ADDRESS_BOOK_COUNT);

    long startTime = System.currentTimeMillis();
    final Collection<AddressBook> finalAddressBooks = addressBooks;
    TransactionManager.transact(DBFlowDatabase.NAME, new Runnable() {
        @Override
        public void run() {
            Saver.saveAll(finalAddressBooks);
        }
    });
    EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.SAVE_TIME));

    startTime = System.currentTimeMillis();
    addressBooks = new Select().from(AddressBook.class).queryList();
    Loader.loadAllInnerData(addressBooks);
    EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.LOAD_TIME));


    com.raizlabs.android.dbflow.sql.language.Delete.tables(AddressItem.class,
                                                           Contact.class, AddressBook.class);
}
 
Example 21
@Override
public long readWholeData() throws SQLException {
    long start = System.nanoTime();
    List<Message> messages = new Select().from(Message.class).queryList();
    Log.d(TAG,
          "Read, " + messages.size()
                  + " rows");
    return System.nanoTime() - start;
}
 
Example 22
/**
 * Returns related to item DashboardElements.
 *
 * @return list of dashboard elements
 */
@JsonIgnore
public long getContentCount() {
    List<DashboardElement> elements = new Select().from(DashboardElement.class)
            .where(Condition.column(DashboardElement$Table.DASHBOARDITEM_DASHBOARDITEM).is(getId()))
            .and(Condition.column(DashboardElement$Table.STATE).isNot(State.TO_DELETE.toString()))
            .queryList();
    return elements == null ? 0 : elements.size();
}
 
Example 23
/**
 * Returns list of DashboardItems associated with dashboard.
 * NOTE! Items will be read from database.
 *
 * @return list of items.
 */
@JsonIgnore
public List<DashboardItem> queryRelatedDashboardItems() {
    return new Select().from(DashboardItem.class)
            .where(Condition.column(DashboardItem$Table
                    .DASHBOARD_DASHBOARD).is(getId()))
            .and(Condition.column(DashboardItem$Table
                    .STATE).isNot(State.TO_DELETE.toString()))
            .queryList();
}
 
Example 24
public static DataMap getById(String uid) {
    return new Select()
            .from(DataMap.class)
            .where(Condition.column(DataMap$Table
                    .UID).is(uid))
            .querySingle();
}
 
Example 25
private void sendInterpretationCommentChanges() throws APIException {
    List<InterpretationComment> comments = new Select()
            .from(InterpretationComment.class)
            .where(Condition.column(InterpretationComment$Table
                    .STATE).isNot(State.SYNCED.toString()))
            .queryList();

    if (comments == null || comments.isEmpty()) {
        return;
    }

    for (InterpretationComment comment : comments) {
        switch (comment.getState()) {
            case TO_POST: {
                postInterpretationComment(comment);
                break;
            }
            case TO_UPDATE: {
                putInterpretationComment(comment);
                break;
            }
            case TO_DELETE: {
                deleteInterpretationComment(comment);
                break;
            }
        }
    }
}
 
Example 26
private static List<Interpretation> queryInterpretations() {
    return new Select()
            .from(Interpretation.class)
            .where(Condition.column(Interpretation$Table
                    .STATE).isNot(State.TO_POST.toString()))
            .queryList();
}
 
Example 27
private static List<InterpretationElement> queryInterpretationElements(
        Interpretation interpretation) {
    From<InterpretationElement> from = new Select().from(InterpretationElement.class);

    if (interpretation != null) {
        return from
                .where(Condition.column(InterpretationElement$Table
                        .INTERPRETATION_INTERPRETATION).is(interpretation.getId()))
                .queryList();
    }

    return from.queryList();
}
 
Example 28
private static List<InterpretationComment> queryInterpretationComments(
        Interpretation interpretation) {
    Where<InterpretationComment> where = new Select()
            .from(InterpretationComment.class)
            .where(Condition.column(InterpretationComment$Table
                    .STATE).isNot(State.TO_POST.toString()));

    if (interpretation != null) {
        where = where.and(Condition.column(InterpretationComment$Table
                .INTERPRETATION_INTERPRETATION).is(interpretation.getId()));
    }

    return where.queryList();
}
 
Example 29
private static List<DashboardItem> queryDashboardItems(Dashboard dashboard) {
    Where<DashboardItem> where = new Select().from(DashboardItem.class)
            .where(Condition.column(DashboardItem$Table
                    .STATE).isNot(State.TO_POST));
    if (dashboard != null) {
        where = where.and(Condition.column(DashboardItem$Table
                .DASHBOARD_DASHBOARD).is(dashboard.getId()));
    }

    return where.queryList();
}
 
Example 30
private static List<DashboardElement> queryDashboardElements(DashboardItem item) {
    return new Select().from(DashboardElement.class)
            .where(Condition.column(DashboardElement$Table
                    .DASHBOARDITEM_DASHBOARDITEM).is(item.getId()))
            .and(Condition.column(DashboardElement$Table
                    .STATE).isNot(State.TO_POST.toString()))
            .queryList();
}