com.orm.query.Select Java Examples

The following examples show how to use com.orm.query.Select. 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: StoryListViewModel.java    From hacker-news-android with Apache License 2.0 6 votes vote down vote up
public Observable<Object> deleteStory(Story item) {
    return Observable.create(subscriber -> {
        SugarTransactionHelper.doInTansaction(() -> {
            Select.from(Story.class)
                  .where(Condition.prop(StringUtil.toSQLName("mStoryId"))
                                  .eq(item.getStoryId()))
                  .first()
                  .delete();

            StoryDetail storyDetail = Select.from(StoryDetail.class)
                                            .where(Condition.prop(StringUtil.toSQLName(StoryDetail.STORY_DETAIL_ID))
                                                            .eq(item.getStoryId()))
                                            .first();
            Select.from(Comment.class)
                  .where(Condition.prop(StringUtil.toSQLName("mStoryDetail"))
                                  .eq(storyDetail.getId()))
                  .first()
                  .delete();
            storyDetail.delete();
            if (!subscriber.isUnsubscribed()) {
                subscriber.onCompleted();
            }
        });
    });
}
 
Example #2
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 6 votes vote down vote up
IProfile[] getLoggedInProfileItem() {
    if (mLoggedInProfiles == null) {
        mLoggedInProfiles = new IProfile[2];
        User currentUser = Select.from(User.class).first();
        ProfileDrawerItem profileDrawerItem = new ProfileDrawerItem().withIdentifier(LOGGED_IN_PROFILE_ITEM)
                                                                     .withIcon(TextDrawable.builder()
                                                                                           .buildRound(String.valueOf(currentUser.getUserName().charAt(0)),
                                                                                                       mResources.getColor(R.color.colorPrimaryDark)))
                                                                     .withName(currentUser.getUserName());
        ProfileSettingDrawerItem logoutDrawerItem = new ProfileSettingDrawerItem().withIdentifier(LOG_OUT_PROFILE_ITEM)
                                                                                  .withName("Logout")
                                                                                  .withDescription("Logout of current account")
                                                                                  .withIcon(mResources.getDrawable(R.drawable.ic_close));

        mLoggedInProfiles[0] = profileDrawerItem;
        mLoggedInProfiles[1] = logoutDrawerItem;
    }

    return mLoggedInProfiles;
}
 
Example #3
Source File: CommandHistory.java    From grblcontroller with GNU General Public License v3.0 5 votes vote down vote up
public static void saveToHistory(String command, String gcode){
    CommandHistory commandHistory = Select.from(CommandHistory.class)
            .where(Condition.prop("gcode").eq(gcode))
            .first();

    if(commandHistory == null) commandHistory = new CommandHistory(command, gcode);
    commandHistory.usageCount++;
    commandHistory.updateLastUsedOn();

    commandHistory.save();
}
 
Example #4
Source File: AppsModel.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
public static int lastPosition() {
    AppsModel appsModel = Select.from(AppsModel.class).orderBy(NamingHelper.toSQLNameDefault("indexPosition") + " DESC").first();
    if (appsModel != null) {
        return appsModel.getIndexPosition();
    }
    return 0;
}
 
Example #5
Source File: AppsModel.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
public static boolean exists(@NonNull String activityInfoName, @NonNull String packageName) {
    return Select.from(AppsModel.class)
            .where(Condition.prop(NamingHelper.toSQLNameDefault("activityInfoName")).eq(activityInfoName))
            .and(Condition.prop(NamingHelper.toSQLNameDefault("packageName")).eq(packageName))
            .and(Condition.prop(NamingHelper.toSQLNameDefault("folderId")).eq(0))
            .first() != null;
}
 
Example #6
Source File: StoryListViewModel.java    From hacker-news-android with Apache License 2.0 5 votes vote down vote up
private Observable<Story> getStories(Observable<List<NodeHNAPIStory>> nodeHNAPIStoriesObservable) {
    return nodeHNAPIStoriesObservable.observeOn(AndroidSchedulers.mainThread())
                                     .subscribeOn(Schedulers.io())
                                     .flatMap(Observable::from)
                                     .map(Story::fromNodeHNAPIStory)
                                     .map(story -> {
                                         Story mStoryId = Select.from(Story.class)
                                                                .where(Condition.prop(StringUtil.toSQLName("mStoryId")).eq(story.getStoryId()))
                                                                .first();

                                         if (mStoryId != null) {
                                             story.setIsSaved(true);
                                         }

                                         return story;
                                     })
                                     .map(story -> {
                                         try {
                                             if (HackerNewsApplication.getAppComponent().getCacheManager().get(String.valueOf(story.getStoryId()), Story.class) != null) {
                                                 story.setIsRead(true);
                                             }
                                             return story;
                                         } catch (IOException e) {

                                         }

                                         return story;
                                     })
                                     .doOnNext(story -> {
                                         if (mStories == null) {
                                             mStories = new ArrayList<>(30);
                                         }
                                         mStories.add(story);
                                     });
}
 
Example #7
Source File: VideoDetailsFragment.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
private Map<String, List<Video>> getRelatedMovies(Video video) {
    List<Video> videos = Select
            .from(Video.class)
            .where(Condition.prop("is_matched").eq(1),
                    Condition.prop("is_movie").eq(1))
            .list();

    Map<String, List<Video>> relatedVideos = new HashMap<String, List<Video>>();
    String key = getString(R.string.related_videos);
    relatedVideos.put(key, new ArrayList<Video>());

    if (video.getMovie() != null && !TextUtils.isEmpty(video.getMovie().getFlattenedGenres())) {
        String[] genresArray = video.getMovie().getFlattenedGenres().split(",");
        Set<String> genres = new HashSet<String>(Arrays.asList(genresArray));

        for (Video vid : videos) {
            if (vid.getMovie() != null &&
                    !TextUtils.isEmpty(vid.getMovie().getFlattenedGenres())) {

                Set<String> intersection = new HashSet<String>(Arrays.asList(
                        vid.getMovie().getFlattenedGenres().split(",")));
                intersection.retainAll(genres);

                if (intersection.size() == genresArray.length &&
                        !video.getMovie().getTitle().equals(vid.getMovie().getTitle())) {

                    relatedVideos.get(key).add(vid);
                }
            }
        }
    }

    return relatedVideos;
}
 
Example #8
Source File: CommandHistory.java    From grblcontroller with GNU General Public License v3.0 4 votes vote down vote up
public static List<CommandHistory> getHistory(String offset, String limit){
    return Select.from(CommandHistory.class)
            .orderBy(NamingHelper.toSQLNameDefault("usageCount") + " DESC, " + NamingHelper.toSQLNameDefault("lastUsedOn") + " DESC")
            .limit(offset + ", " + limit).list();
}
 
Example #9
Source File: AppsModel.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
public static List<AppsModel> getApps() {
    return Select.from(AppsModel.class)
            .where(Condition.prop(NamingHelper.toSQLNameDefault("folderId")).eq(0))
            .orderBy(NamingHelper.toSQLNameDefault("indexPosition") + " ASC")
            .list();
}
 
Example #10
Source File: AppsModel.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
public static List<AppsModel> getApps(long folderId) {
    return Select.from(AppsModel.class)
            .where(Condition.prop(NamingHelper.toSQLNameDefault("folderId")).eq(folderId))
            .list();
}
 
Example #11
Source File: FolderModel.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
@Nullable public static FolderModel getFolder(@NonNull String folderName) {
    return Select.from(FolderModel.class).where(NamingHelper.toSQLNameDefault("folderName") + " = ? COLLATE NOCASE", new String[]{folderName})
            .first();
}
 
Example #12
Source File: FolderModel.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
public static List<FolderModel> getFolders() {
    return Select.from(FolderModel.class)
            .orderBy(NamingHelper.toSQLNameDefault("createdDate") + " DESC")
            .list();
}
 
Example #13
Source File: StoryListViewModel.java    From hacker-news-android with Apache License 2.0 4 votes vote down vote up
private Observable<List<NodeHNAPIStory>> getObservable() {
    Observable<List<NodeHNAPIStory>> observable = null;
    switch (mFeedType) {
        case FEED_TYPE_TOP:
            observable = mService.getTopStories();
            break;
        case FEED_TYPE_BEST:
            observable = mService.getBestStories();
            break;
        case FEED_TYPE_NEW:
            observable = mService.getNewestStories();
            break;
        case FEED_TYPE_SHOW:
            observable = mService.getShowStories();
            break;
        case FEED_TYPE_SHOW_NEW:
            observable = mService.getShowNewStories();
            break;
        case FEED_TYPE_ASK:
            observable = mService.getAskStories();
            break;
        case FEED_TYPE_SAVED:
            observable = Observable
                    .create(new Observable.OnSubscribe<List<Story>>() {
                        @Override
                        public void call(Subscriber<? super List<Story>> subscriber) {
                            if (!subscriber.isUnsubscribed()) {
                                List<Story> list = Select.from(Story.class)
                                                         .list();
                                subscriber.onNext(list);

                                subscriber.onCompleted();
                            }
                        }
                    })
                    .map(stories -> {
                        List<NodeHNAPIStory> nodeHNAPIStories = new ArrayList<>();
                        for (Story story : stories) {
                            nodeHNAPIStories.add(NodeHNAPIStory.fromStory(story));
                        }
                        return nodeHNAPIStories;
                    });
            break;
    }

    return observable;
}