{"action":"created","comment":{"url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/comments/24087583","id":24087583,"diff_hunk":"@@ -0,0 +1,433 @@\n+/*\n+ * JBoss, Home of Professional Open Source.\n+ * See the COPYRIGHT.txt file distributed with this work for information\n+ * regarding copyright ownership.  Some portions may be licensed\n+ * to Red Hat, Inc. under one or more contributor license agreements.\n+ *\n+ * This library is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2.1 of the License, or (at your option) any later version.\n+ *\n+ * This library is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this library; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n+ * 02110-1301 USA.\n+ */\n+package org.komodo.repository.search;\n+\n+import java.util.ArrayList;\n+import java.util.Collection;\n+import java.util.Collections;\n+import java.util.Iterator;\n+import java.util.LinkedHashSet;\n+import java.util.List;\n+import java.util.Set;\n+import javax.jcr.Node;\n+import javax.jcr.NodeIterator;\n+import javax.jcr.Session;\n+import javax.jcr.query.Query;\n+import javax.jcr.query.QueryManager;\n+import javax.jcr.query.QueryResult;\n+import org.komodo.repository.ObjectImpl;\n+import org.komodo.repository.RepositoryImpl.UnitOfWorkImpl;\n+import org.komodo.repository.search.Clause.LogicalOperator;\n+import org.komodo.spi.KException;\n+import org.komodo.spi.query.sql.SQLConstants;\n+import org.komodo.spi.repository.KomodoObject;\n+import org.komodo.spi.repository.Repository;\n+import org.komodo.spi.repository.Repository.KeywordCriteria;\n+import org.komodo.spi.repository.Repository.UnitOfWork;\n+import org.komodo.utils.ArgCheck;\n+import org.komodo.utils.StringUtils;\n+\n+/**\n+ * Finder class for searching a repository\n+ */\n+public class ObjectSearcher implements SQLConstants {\n+\n+    private final Repository repository;\n+\n+    private Set<FromType> fromTypes;\n+\n+    private List<Clause> whereClauses;\n+\n+    private String customWhereClause;\n+\n+    /**\n+     * @param repository the repository to search\n+     */\n+    public ObjectSearcher(Repository repository) {\n+        ArgCheck.isNotNull(repository);\n+        this.repository = repository;\n+    }\n+\n+    private Session getSession(final UnitOfWork transaction) {\n+        return ((UnitOfWorkImpl)transaction).getSession();\n+    }\n+\n+    private boolean isEmpty(Collection<?> list) {\n+        return list == null || list.isEmpty();\n+    }\n+\n+    /**\n+     * @return the repository\n+     */\n+    public Repository getRepository() {\n+        return this.repository;\n+    }\n+\n+    /**\n+     * Add a node type to the From clause\n+     *\n+     * @param type the type to be added\n+     * @param alias the alias of the type\n+     */\n+    public void addFromType(String type, String alias) {\n+        ArgCheck.isNotEmpty(type);\n+        String failMsg = \"From clause data should be added prior to where clause data\"; //$NON-NLS-1$\n+        ArgCheck.isTrue(whereClauses == null, failMsg);\n+        ArgCheck.isTrue(customWhereClause == null, failMsg);\n+\n+        if (fromTypes == null)\n+            fromTypes = new LinkedHashSet<FromType>();\n+\n+        fromTypes.add(new FromType(type, alias));\n+    }\n+\n+    /**\n+     * Add a node type to the From clause\n+     *\n+     * @param type the type to be added\n+     */\n+    public void addFromType(String type) {\n+        addFromType(type, null);\n+    }\n+\n+    /**\n+     * @return set of node types for the From clause\n+     */\n+    private Set<FromType> getFromTypes() {\n+        if (fromTypes == null || fromTypes.isEmpty()) {\n+            return Collections.emptySet();\n+        }\n+\n+        return fromTypes;\n+    }\n+\n+    private String checkWhereAlias(String alias) {\n+        //\n+        // Check that where type alias is valid for set of from types\n+        //\n+        if (getFromTypes().size() == 1 && StringUtils.isEmpty(alias)) {\n+            // Only 1 from type and alias is empty so assume alias of single from type\n+            alias = getFromTypes().iterator().next().getAlias();\n+        } else {\n+            //\n+            // More than 1 from type or alias is not empty\n+            //\n+            ArgCheck.isNotEmpty(alias);\n+\n+            boolean aliasTypeFound = false;\n+            for (FromType fromType : getFromTypes()) {\n+                if (fromType.getAlias().equals(alias)) {","path":"plugins/org.komodo.core/src/org/komodo/repository/search/ObjectSearcher.java","position":138,"original_position":138,"commit_id":"973ea29ce3e443dcc15e38bf756d5a656d13389b","original_commit_id":"973ea29ce3e443dcc15e38bf756d5a656d13389b","user":{"login":"elvisisking","id":557336,"avatar_url":"https://avatars.githubusercontent.com/u/557336?v=3","gravatar_id":"","url":"https://api.github.com/users/elvisisking","html_url":"https://github.com/elvisisking","followers_url":"https://api.github.com/users/elvisisking/followers","following_url":"https://api.github.com/users/elvisisking/following{/other_user}","gists_url":"https://api.github.com/users/elvisisking/gists{/gist_id}","starred_url":"https://api.github.com/users/elvisisking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elvisisking/subscriptions","organizations_url":"https://api.github.com/users/elvisisking/orgs","repos_url":"https://api.github.com/users/elvisisking/repos","events_url":"https://api.github.com/users/elvisisking/events{/privacy}","received_events_url":"https://api.github.com/users/elvisisking/received_events","type":"User","site_admin":false},"body":"Based on looking at the `FromType` class I know its alias is not `null`. But I might have changed the order of things here to `alias.equals(fromType.getAlias())` because of the `ArgCheck` right above.","created_at":"2015-02-04T14:49:36Z","updated_at":"2015-02-04T14:49:36Z","html_url":"https://github.com/Teiid-Designer/komodo/pull/53#discussion_r24087583","pull_request_url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/comments/24087583"},"html":{"href":"https://github.com/Teiid-Designer/komodo/pull/53#discussion_r24087583"},"pull_request":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53","id":28564956,"html_url":"https://github.com/Teiid-Designer/komodo/pull/53","diff_url":"https://github.com/Teiid-Designer/komodo/pull/53.diff","patch_url":"https://github.com/Teiid-Designer/komodo/pull/53.patch","issue_url":"https://api.github.com/repos/Teiid-Designer/komodo/issues/53","number":53,"state":"open","locked":false,"title":"Object search","user":{"login":"phantomjinx","id":1634180,"avatar_url":"https://avatars.githubusercontent.com/u/1634180?v=3","gravatar_id":"","url":"https://api.github.com/users/phantomjinx","html_url":"https://github.com/phantomjinx","followers_url":"https://api.github.com/users/phantomjinx/followers","following_url":"https://api.github.com/users/phantomjinx/following{/other_user}","gists_url":"https://api.github.com/users/phantomjinx/gists{/gist_id}","starred_url":"https://api.github.com/users/phantomjinx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phantomjinx/subscriptions","organizations_url":"https://api.github.com/users/phantomjinx/orgs","repos_url":"https://api.github.com/users/phantomjinx/repos","events_url":"https://api.github.com/users/phantomjinx/events{/privacy}","received_events_url":"https://api.github.com/users/phantomjinx/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-03T16:13:12Z","updated_at":"2015-02-04T14:49:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ce1b7d01a523b4e6e133aa116379ead537422fd8","assignee":{"login":"elvisisking","id":557336,"avatar_url":"https://avatars.githubusercontent.com/u/557336?v=3","gravatar_id":"","url":"https://api.github.com/users/elvisisking","html_url":"https://github.com/elvisisking","followers_url":"https://api.github.com/users/elvisisking/followers","following_url":"https://api.github.com/users/elvisisking/following{/other_user}","gists_url":"https://api.github.com/users/elvisisking/gists{/gist_id}","starred_url":"https://api.github.com/users/elvisisking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elvisisking/subscriptions","organizations_url":"https://api.github.com/users/elvisisking/orgs","repos_url":"https://api.github.com/users/elvisisking/repos","events_url":"https://api.github.com/users/elvisisking/events{/privacy}","received_events_url":"https://api.github.com/users/elvisisking/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53/commits","review_comments_url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53/comments","review_comment_url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Teiid-Designer/komodo/issues/53/comments","statuses_url":"https://api.github.com/repos/Teiid-Designer/komodo/statuses/973ea29ce3e443dcc15e38bf756d5a656d13389b","head":{"label":"phantomjinx:object-search","ref":"object-search","sha":"973ea29ce3e443dcc15e38bf756d5a656d13389b","user":{"login":"phantomjinx","id":1634180,"avatar_url":"https://avatars.githubusercontent.com/u/1634180?v=3","gravatar_id":"","url":"https://api.github.com/users/phantomjinx","html_url":"https://github.com/phantomjinx","followers_url":"https://api.github.com/users/phantomjinx/followers","following_url":"https://api.github.com/users/phantomjinx/following{/other_user}","gists_url":"https://api.github.com/users/phantomjinx/gists{/gist_id}","starred_url":"https://api.github.com/users/phantomjinx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phantomjinx/subscriptions","organizations_url":"https://api.github.com/users/phantomjinx/orgs","repos_url":"https://api.github.com/users/phantomjinx/repos","events_url":"https://api.github.com/users/phantomjinx/events{/privacy}","received_events_url":"https://api.github.com/users/phantomjinx/received_events","type":"User","site_admin":false},"repo":{"id":20478824,"name":"komodo","full_name":"phantomjinx/komodo","owner":{"login":"phantomjinx","id":1634180,"avatar_url":"https://avatars.githubusercontent.com/u/1634180?v=3","gravatar_id":"","url":"https://api.github.com/users/phantomjinx","html_url":"https://github.com/phantomjinx","followers_url":"https://api.github.com/users/phantomjinx/followers","following_url":"https://api.github.com/users/phantomjinx/following{/other_user}","gists_url":"https://api.github.com/users/phantomjinx/gists{/gist_id}","starred_url":"https://api.github.com/users/phantomjinx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phantomjinx/subscriptions","organizations_url":"https://api.github.com/users/phantomjinx/orgs","repos_url":"https://api.github.com/users/phantomjinx/repos","events_url":"https://api.github.com/users/phantomjinx/events{/privacy}","received_events_url":"https://api.github.com/users/phantomjinx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phantomjinx/komodo","description":"teiid modeling tool development utilizing ddl-based metamodel","fork":true,"url":"https://api.github.com/repos/phantomjinx/komodo","forks_url":"https://api.github.com/repos/phantomjinx/komodo/forks","keys_url":"https://api.github.com/repos/phantomjinx/komodo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phantomjinx/komodo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phantomjinx/komodo/teams","hooks_url":"https://api.github.com/repos/phantomjinx/komodo/hooks","issue_events_url":"https://api.github.com/repos/phantomjinx/komodo/issues/events{/number}","events_url":"https://api.github.com/repos/phantomjinx/komodo/events","assignees_url":"https://api.github.com/repos/phantomjinx/komodo/assignees{/user}","branches_url":"https://api.github.com/repos/phantomjinx/komodo/branches{/branch}","tags_url":"https://api.github.com/repos/phantomjinx/komodo/tags","blobs_url":"https://api.github.com/repos/phantomjinx/komodo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phantomjinx/komodo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phantomjinx/komodo/git/refs{/sha}","trees_url":"https://api.github.com/repos/phantomjinx/komodo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phantomjinx/komodo/statuses/{sha}","languages_url":"https://api.github.com/repos/phantomjinx/komodo/languages","stargazers_url":"https://api.github.com/repos/phantomjinx/komodo/stargazers","contributors_url":"https://api.github.com/repos/phantomjinx/komodo/contributors","subscribers_url":"https://api.github.com/repos/phantomjinx/komodo/subscribers","subscription_url":"https://api.github.com/repos/phantomjinx/komodo/subscription","commits_url":"https://api.github.com/repos/phantomjinx/komodo/commits{/sha}","git_commits_url":"https://api.github.com/repos/phantomjinx/komodo/git/commits{/sha}","comments_url":"https://api.github.com/repos/phantomjinx/komodo/comments{/number}","issue_comment_url":"https://api.github.com/repos/phantomjinx/komodo/issues/comments/{number}","contents_url":"https://api.github.com/repos/phantomjinx/komodo/contents/{+path}","compare_url":"https://api.github.com/repos/phantomjinx/komodo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phantomjinx/komodo/merges","archive_url":"https://api.github.com/repos/phantomjinx/komodo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phantomjinx/komodo/downloads","issues_url":"https://api.github.com/repos/phantomjinx/komodo/issues{/number}","pulls_url":"https://api.github.com/repos/phantomjinx/komodo/pulls{/number}","milestones_url":"https://api.github.com/repos/phantomjinx/komodo/milestones{/number}","notifications_url":"https://api.github.com/repos/phantomjinx/komodo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phantomjinx/komodo/labels{/name}","releases_url":"https://api.github.com/repos/phantomjinx/komodo/releases{/id}","created_at":"2014-06-04T10:16:47Z","updated_at":"2014-12-09T17:16:36Z","pushed_at":"2015-02-04T09:46:22Z","git_url":"git://github.com/phantomjinx/komodo.git","ssh_url":"git@github.com:phantomjinx/komodo.git","clone_url":"https://github.com/phantomjinx/komodo.git","svn_url":"https://github.com/phantomjinx/komodo","homepage":null,"size":46295,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Teiid-Designer:master","ref":"master","sha":"d91f340ca704c63e7a3b8cbc3866421b26975ba4","user":{"login":"Teiid-Designer","id":1641911,"avatar_url":"https://avatars.githubusercontent.com/u/1641911?v=3","gravatar_id":"","url":"https://api.github.com/users/Teiid-Designer","html_url":"https://github.com/Teiid-Designer","followers_url":"https://api.github.com/users/Teiid-Designer/followers","following_url":"https://api.github.com/users/Teiid-Designer/following{/other_user}","gists_url":"https://api.github.com/users/Teiid-Designer/gists{/gist_id}","starred_url":"https://api.github.com/users/Teiid-Designer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teiid-Designer/subscriptions","organizations_url":"https://api.github.com/users/Teiid-Designer/orgs","repos_url":"https://api.github.com/users/Teiid-Designer/repos","events_url":"https://api.github.com/users/Teiid-Designer/events{/privacy}","received_events_url":"https://api.github.com/users/Teiid-Designer/received_events","type":"Organization","site_admin":false},"repo":{"id":14528678,"name":"komodo","full_name":"Teiid-Designer/komodo","owner":{"login":"Teiid-Designer","id":1641911,"avatar_url":"https://avatars.githubusercontent.com/u/1641911?v=3","gravatar_id":"","url":"https://api.github.com/users/Teiid-Designer","html_url":"https://github.com/Teiid-Designer","followers_url":"https://api.github.com/users/Teiid-Designer/followers","following_url":"https://api.github.com/users/Teiid-Designer/following{/other_user}","gists_url":"https://api.github.com/users/Teiid-Designer/gists{/gist_id}","starred_url":"https://api.github.com/users/Teiid-Designer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teiid-Designer/subscriptions","organizations_url":"https://api.github.com/users/Teiid-Designer/orgs","repos_url":"https://api.github.com/users/Teiid-Designer/repos","events_url":"https://api.github.com/users/Teiid-Designer/events{/privacy}","received_events_url":"https://api.github.com/users/Teiid-Designer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Teiid-Designer/komodo","description":"teiid modeling tool development utilizing ddl-based metamodel","fork":false,"url":"https://api.github.com/repos/Teiid-Designer/komodo","forks_url":"https://api.github.com/repos/Teiid-Designer/komodo/forks","keys_url":"https://api.github.com/repos/Teiid-Designer/komodo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Teiid-Designer/komodo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Teiid-Designer/komodo/teams","hooks_url":"https://api.github.com/repos/Teiid-Designer/komodo/hooks","issue_events_url":"https://api.github.com/repos/Teiid-Designer/komodo/issues/events{/number}","events_url":"https://api.github.com/repos/Teiid-Designer/komodo/events","assignees_url":"https://api.github.com/repos/Teiid-Designer/komodo/assignees{/user}","branches_url":"https://api.github.com/repos/Teiid-Designer/komodo/branches{/branch}","tags_url":"https://api.github.com/repos/Teiid-Designer/komodo/tags","blobs_url":"https://api.github.com/repos/Teiid-Designer/komodo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Teiid-Designer/komodo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Teiid-Designer/komodo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Teiid-Designer/komodo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Teiid-Designer/komodo/statuses/{sha}","languages_url":"https://api.github.com/repos/Teiid-Designer/komodo/languages","stargazers_url":"https://api.github.com/repos/Teiid-Designer/komodo/stargazers","contributors_url":"https://api.github.com/repos/Teiid-Designer/komodo/contributors","subscribers_url":"https://api.github.com/repos/Teiid-Designer/komodo/subscribers","subscription_url":"https://api.github.com/repos/Teiid-Designer/komodo/subscription","commits_url":"https://api.github.com/repos/Teiid-Designer/komodo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Teiid-Designer/komodo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Teiid-Designer/komodo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Teiid-Designer/komodo/issues/comments/{number}","contents_url":"https://api.github.com/repos/Teiid-Designer/komodo/contents/{+path}","compare_url":"https://api.github.com/repos/Teiid-Designer/komodo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Teiid-Designer/komodo/merges","archive_url":"https://api.github.com/repos/Teiid-Designer/komodo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Teiid-Designer/komodo/downloads","issues_url":"https://api.github.com/repos/Teiid-Designer/komodo/issues{/number}","pulls_url":"https://api.github.com/repos/Teiid-Designer/komodo/pulls{/number}","milestones_url":"https://api.github.com/repos/Teiid-Designer/komodo/milestones{/number}","notifications_url":"https://api.github.com/repos/Teiid-Designer/komodo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Teiid-Designer/komodo/labels{/name}","releases_url":"https://api.github.com/repos/Teiid-Designer/komodo/releases{/id}","created_at":"2013-11-19T15:32:23Z","updated_at":"2015-01-28T17:09:05Z","pushed_at":"2015-01-28T17:09:05Z","git_url":"git://github.com/Teiid-Designer/komodo.git","ssh_url":"git@github.com:Teiid-Designer/komodo.git","clone_url":"https://github.com/Teiid-Designer/komodo.git","svn_url":"https://github.com/Teiid-Designer/komodo","homepage":null,"size":46283,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53"},"html":{"href":"https://github.com/Teiid-Designer/komodo/pull/53"},"issue":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/issues/53"},"comments":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/Teiid-Designer/komodo/statuses/973ea29ce3e443dcc15e38bf756d5a656d13389b"}}}}