{"action":"created","comment":{"url":"https://api.github.com/repos/dbfit/dbfit/pulls/comments/90764658","pull_request_review_id":11283681,"id":90764658,"diff_hunk":"@@ -51,40 +53,176 @@ public Pattern getParameterPattern() {\n         return paramRegex;\n     }\n \n-    public Map<String, DbParameterAccessor> getAllColumns(\n-            final String tableOrViewName) throws SQLException {\n-        String qry = \"SELECT COLUMNNAME, COLUMNDATATYPE \"\n-                + \"FROM SYS.SYSCOLUMNS WHERE REFERENCEID = \"\n-                + \"(SELECT TABLEID FROM SYS.SYSTABLES WHERE TABLENAME = ?)\";\n-        return readIntoParams(tableOrViewName.toUpperCase(), qry);\n+    public Map<String, DbParameterAccessor> getAllColumns(String tableName)\n+                                                        throws SQLException {\n+        DatabaseTable t = new DatabaseTable(getConnection(), getConnection().getSchema(), tableName.toUpperCase());\n+        return t.getParams();\n     }\n \n-    private Map<String, DbParameterAccessor> readIntoParams(\n-            String tableOrViewName, String query) throws SQLException {\n-        try (PreparedStatement dc = getConnection().prepareStatement(query)) {\n-            dc.setString(1, tableOrViewName);\n+    private abstract class DatabaseObject {\n+        protected Connection con;\n+        protected DbObjectName name;\n+        Map<String, DbParameterAccessor> allParams = new HashMap<String, DbParameterAccessor>();\n+\n+        private DatabaseObject(Connection conn, String defaultSchemaName, String objName) {\n+            con = conn;\n+            name = new DbObjectName(defaultSchemaName, objName);\n+        }\n \n-            ResultSet rs = dc.executeQuery();\n-            Map<String, DbParameterAccessor> allParams = new HashMap<String, DbParameterAccessor>();\n-            int position = 0;\n+        abstract protected boolean exists() throws SQLException;\n+\n+        abstract protected ResultSet getColumns() throws SQLException;\n+\n+        public Map<String, DbParameterAccessor> getParams() throws SQLException {\n+            ResultSet rs = getColumns();\n             while (rs.next()) {\n-                String columnName = rs.getString(1);\n-                String dataType = rs.getString(2);\n-                DbParameterAccessor dbp = createDbParameterAccessor(\n-                        columnName,\n-                        Direction.INPUT,\n-                        typeMapper.getJDBCSQLTypeForDBType(dataType),\n-                        getJavaClass(dataType), position++);\n-                allParams.put(NameNormaliser.normaliseName(columnName), dbp);\n+                String paramName = defaultIfNull(rs.getString(\"COLUMN_NAME\"), \"\");\n+                allParams.put(NameNormaliser.normaliseName(paramName),\n+                              createDbParamAccessor(paramName, rs, getParamDirection(rs)));\n             }\n-            rs.close();\n             return allParams;\n         }\n+\n+        abstract Direction getParamDirection(ResultSet rs) throws SQLException;\n+\n+        private DbParameterAccessor createDbParamAccessor(String paramName, ResultSet rs,\n+                                                          Direction paramDirection)\n+                                                                throws SQLException {\n+            String paramTypeName = rs.getString(\"TYPE_NAME\");\n+            int position = rs.getInt(\"ORDINAL_POSITION\");\n+            return createDbParameterAccessor(paramName, paramDirection,\n+                                             typeMapper.getJDBCSQLTypeForDBType(paramTypeName),\n+                                             getJavaClass(paramTypeName), position - 1);\n+        }\n+    }\n+\n+    private class DatabaseTable extends DatabaseObject {\n+\n+        private DatabaseTable(Connection conn, String defaultSchemaName, String objName) {\n+            super(conn, defaultSchemaName, objName);\n+        }\n+\n+        @Override\n+        public boolean exists() throws SQLException {\n+            ResultSet rs = con.getMetaData().getTables(null, name.getSchemaName(), name.getObjectName(), null);\n+            return rs.next();\n+        }\n+\n+        @Override\n+        public ResultSet getColumns() throws SQLException {\n+            return con.getMetaData().getColumns(null, name.getSchemaName(), name.getObjectName(), \"%\");\n+        }\n+\n+        @Override\n+        protected Direction getParamDirection(ResultSet rs) {\n+            return Direction.INPUT;\n+        }\n+    }\n+\n+    private class DatabaseProcedure extends DatabaseObject {\n+\n+        private DatabaseProcedure(Connection conn, String defaultSchemaName, String objName) {\n+            super(conn, defaultSchemaName, objName);\n+        }\n+\n+        @Override\n+        public boolean exists() throws SQLException {\n+            ResultSet rs = con.getMetaData().getProcedures(null, name.getSchemaName(), name.getObjectName());\n+            return rs.next();\n+        }\n+\n+        @Override\n+        public ResultSet getColumns() throws SQLException {\n+            return con.getMetaData().getProcedureColumns(null, name.getSchemaName(), name.getObjectName(), \"%\");\n+        }\n+\n+        @Override\n+        protected Direction getParamDirection(ResultSet rs)\n+                                        throws SQLException {\n+            Direction dir = null;\n+            switch (rs.getInt(\"COLUMN_TYPE\")) {\n+                case DatabaseMetaData.procedureColumnIn:\n+                    dir = Direction.INPUT;\n+                    break;","path":"dbfit-java/derby/src/main/java/dbfit/environment/DerbyEnvironment.java","position":null,"original_position":138,"commit_id":"b4dd444e127bde7264c1999a08229f983a4457a9","original_commit_id":"a4f31b637b5cc55ebf627a3dcb553dd12115155c","user":{"login":"MMatten","id":1895701,"avatar_url":"https://avatars.githubusercontent.com/u/1895701?v=3","gravatar_id":"","url":"https://api.github.com/users/MMatten","html_url":"https://github.com/MMatten","followers_url":"https://api.github.com/users/MMatten/followers","following_url":"https://api.github.com/users/MMatten/following{/other_user}","gists_url":"https://api.github.com/users/MMatten/gists{/gist_id}","starred_url":"https://api.github.com/users/MMatten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MMatten/subscriptions","organizations_url":"https://api.github.com/users/MMatten/orgs","repos_url":"https://api.github.com/users/MMatten/repos","events_url":"https://api.github.com/users/MMatten/events{/privacy}","received_events_url":"https://api.github.com/users/MMatten/received_events","type":"User","site_admin":false},"body":"> Shouldn't it be throwing an exception?\r\n\r\nYes. Theoretically it can't happen but I'll raise a `SQLException` for the `default` option.","created_at":"2016-12-03T20:43:37Z","updated_at":"2016-12-03T20:43:37Z","html_url":"https://github.com/dbfit/dbfit/pull/524#discussion_r90764658","pull_request_url":"https://api.github.com/repos/dbfit/dbfit/pulls/524","_links":{"self":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/comments/90764658"},"html":{"href":"https://github.com/dbfit/dbfit/pull/524#discussion_r90764658"},"pull_request":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/524"}}},"pull_request":{"url":"https://api.github.com/repos/dbfit/dbfit/pulls/524","id":96398304,"html_url":"https://github.com/dbfit/dbfit/pull/524","diff_url":"https://github.com/dbfit/dbfit/pull/524.diff","patch_url":"https://github.com/dbfit/dbfit/pull/524.patch","issue_url":"https://api.github.com/repos/dbfit/dbfit/issues/524","number":524,"state":"open","locked":false,"title":"Support stored and function parameters in Derby","user":{"login":"MMatten","id":1895701,"avatar_url":"https://avatars.githubusercontent.com/u/1895701?v=3","gravatar_id":"","url":"https://api.github.com/users/MMatten","html_url":"https://github.com/MMatten","followers_url":"https://api.github.com/users/MMatten/followers","following_url":"https://api.github.com/users/MMatten/following{/other_user}","gists_url":"https://api.github.com/users/MMatten/gists{/gist_id}","starred_url":"https://api.github.com/users/MMatten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MMatten/subscriptions","organizations_url":"https://api.github.com/users/MMatten/orgs","repos_url":"https://api.github.com/users/MMatten/repos","events_url":"https://api.github.com/users/MMatten/events{/privacy}","received_events_url":"https://api.github.com/users/MMatten/received_events","type":"User","site_admin":false},"body":"Initial draft of one approach to using only JDBC method for querying Derby object metadata.\r\n\r\nPotential for reuse for a generic DB adapter(?)\r\n","created_at":"2016-12-03T13:49:00Z","updated_at":"2016-12-03T20:43:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6939143a4e0281791de115f2626ed7ac8c4e1130","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dbfit/dbfit/pulls/524/commits","review_comments_url":"https://api.github.com/repos/dbfit/dbfit/pulls/524/comments","review_comment_url":"https://api.github.com/repos/dbfit/dbfit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dbfit/dbfit/issues/524/comments","statuses_url":"https://api.github.com/repos/dbfit/dbfit/statuses/b4dd444e127bde7264c1999a08229f983a4457a9","head":{"label":"dbfit:support-derby-stored-unit-calls","ref":"support-derby-stored-unit-calls","sha":"b4dd444e127bde7264c1999a08229f983a4457a9","user":{"login":"dbfit","id":6273536,"avatar_url":"https://avatars.githubusercontent.com/u/6273536?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfit","html_url":"https://github.com/dbfit","followers_url":"https://api.github.com/users/dbfit/followers","following_url":"https://api.github.com/users/dbfit/following{/other_user}","gists_url":"https://api.github.com/users/dbfit/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfit/subscriptions","organizations_url":"https://api.github.com/users/dbfit/orgs","repos_url":"https://api.github.com/users/dbfit/repos","events_url":"https://api.github.com/users/dbfit/events{/privacy}","received_events_url":"https://api.github.com/users/dbfit/received_events","type":"Organization","site_admin":false},"repo":{"id":7283919,"name":"dbfit","full_name":"dbfit/dbfit","owner":{"login":"dbfit","id":6273536,"avatar_url":"https://avatars.githubusercontent.com/u/6273536?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfit","html_url":"https://github.com/dbfit","followers_url":"https://api.github.com/users/dbfit/followers","following_url":"https://api.github.com/users/dbfit/following{/other_user}","gists_url":"https://api.github.com/users/dbfit/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfit/subscriptions","organizations_url":"https://api.github.com/users/dbfit/orgs","repos_url":"https://api.github.com/users/dbfit/repos","events_url":"https://api.github.com/users/dbfit/events{/privacy}","received_events_url":"https://api.github.com/users/dbfit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dbfit/dbfit","description":"DbFit is a database testing framework that supports easy test-driven development of your database code.","fork":false,"url":"https://api.github.com/repos/dbfit/dbfit","forks_url":"https://api.github.com/repos/dbfit/dbfit/forks","keys_url":"https://api.github.com/repos/dbfit/dbfit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbfit/dbfit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbfit/dbfit/teams","hooks_url":"https://api.github.com/repos/dbfit/dbfit/hooks","issue_events_url":"https://api.github.com/repos/dbfit/dbfit/issues/events{/number}","events_url":"https://api.github.com/repos/dbfit/dbfit/events","assignees_url":"https://api.github.com/repos/dbfit/dbfit/assignees{/user}","branches_url":"https://api.github.com/repos/dbfit/dbfit/branches{/branch}","tags_url":"https://api.github.com/repos/dbfit/dbfit/tags","blobs_url":"https://api.github.com/repos/dbfit/dbfit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbfit/dbfit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbfit/dbfit/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbfit/dbfit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbfit/dbfit/statuses/{sha}","languages_url":"https://api.github.com/repos/dbfit/dbfit/languages","stargazers_url":"https://api.github.com/repos/dbfit/dbfit/stargazers","contributors_url":"https://api.github.com/repos/dbfit/dbfit/contributors","subscribers_url":"https://api.github.com/repos/dbfit/dbfit/subscribers","subscription_url":"https://api.github.com/repos/dbfit/dbfit/subscription","commits_url":"https://api.github.com/repos/dbfit/dbfit/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbfit/dbfit/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbfit/dbfit/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbfit/dbfit/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbfit/dbfit/contents/{+path}","compare_url":"https://api.github.com/repos/dbfit/dbfit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbfit/dbfit/merges","archive_url":"https://api.github.com/repos/dbfit/dbfit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbfit/dbfit/downloads","issues_url":"https://api.github.com/repos/dbfit/dbfit/issues{/number}","pulls_url":"https://api.github.com/repos/dbfit/dbfit/pulls{/number}","milestones_url":"https://api.github.com/repos/dbfit/dbfit/milestones{/number}","notifications_url":"https://api.github.com/repos/dbfit/dbfit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbfit/dbfit/labels{/name}","releases_url":"https://api.github.com/repos/dbfit/dbfit/releases{/id}","deployments_url":"https://api.github.com/repos/dbfit/dbfit/deployments","created_at":"2012-12-22T08:26:13Z","updated_at":"2016-12-01T15:49:25Z","pushed_at":"2016-12-03T20:25:10Z","git_url":"git://github.com/dbfit/dbfit.git","ssh_url":"git@github.com:dbfit/dbfit.git","clone_url":"https://github.com/dbfit/dbfit.git","svn_url":"https://github.com/dbfit/dbfit","homepage":"http://dbfit.github.io/dbfit","size":8879,"stargazers_count":124,"watchers_count":124,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":58,"mirror_url":null,"open_issues_count":96,"forks":58,"open_issues":96,"watchers":124,"default_branch":"master"}},"base":{"label":"dbfit:master","ref":"master","sha":"fa0df92b42afc17611b3267fb7694a8de85e8b3a","user":{"login":"dbfit","id":6273536,"avatar_url":"https://avatars.githubusercontent.com/u/6273536?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfit","html_url":"https://github.com/dbfit","followers_url":"https://api.github.com/users/dbfit/followers","following_url":"https://api.github.com/users/dbfit/following{/other_user}","gists_url":"https://api.github.com/users/dbfit/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfit/subscriptions","organizations_url":"https://api.github.com/users/dbfit/orgs","repos_url":"https://api.github.com/users/dbfit/repos","events_url":"https://api.github.com/users/dbfit/events{/privacy}","received_events_url":"https://api.github.com/users/dbfit/received_events","type":"Organization","site_admin":false},"repo":{"id":7283919,"name":"dbfit","full_name":"dbfit/dbfit","owner":{"login":"dbfit","id":6273536,"avatar_url":"https://avatars.githubusercontent.com/u/6273536?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfit","html_url":"https://github.com/dbfit","followers_url":"https://api.github.com/users/dbfit/followers","following_url":"https://api.github.com/users/dbfit/following{/other_user}","gists_url":"https://api.github.com/users/dbfit/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfit/subscriptions","organizations_url":"https://api.github.com/users/dbfit/orgs","repos_url":"https://api.github.com/users/dbfit/repos","events_url":"https://api.github.com/users/dbfit/events{/privacy}","received_events_url":"https://api.github.com/users/dbfit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dbfit/dbfit","description":"DbFit is a database testing framework that supports easy test-driven development of your database code.","fork":false,"url":"https://api.github.com/repos/dbfit/dbfit","forks_url":"https://api.github.com/repos/dbfit/dbfit/forks","keys_url":"https://api.github.com/repos/dbfit/dbfit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbfit/dbfit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbfit/dbfit/teams","hooks_url":"https://api.github.com/repos/dbfit/dbfit/hooks","issue_events_url":"https://api.github.com/repos/dbfit/dbfit/issues/events{/number}","events_url":"https://api.github.com/repos/dbfit/dbfit/events","assignees_url":"https://api.github.com/repos/dbfit/dbfit/assignees{/user}","branches_url":"https://api.github.com/repos/dbfit/dbfit/branches{/branch}","tags_url":"https://api.github.com/repos/dbfit/dbfit/tags","blobs_url":"https://api.github.com/repos/dbfit/dbfit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbfit/dbfit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbfit/dbfit/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbfit/dbfit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbfit/dbfit/statuses/{sha}","languages_url":"https://api.github.com/repos/dbfit/dbfit/languages","stargazers_url":"https://api.github.com/repos/dbfit/dbfit/stargazers","contributors_url":"https://api.github.com/repos/dbfit/dbfit/contributors","subscribers_url":"https://api.github.com/repos/dbfit/dbfit/subscribers","subscription_url":"https://api.github.com/repos/dbfit/dbfit/subscription","commits_url":"https://api.github.com/repos/dbfit/dbfit/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbfit/dbfit/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbfit/dbfit/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbfit/dbfit/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbfit/dbfit/contents/{+path}","compare_url":"https://api.github.com/repos/dbfit/dbfit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbfit/dbfit/merges","archive_url":"https://api.github.com/repos/dbfit/dbfit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbfit/dbfit/downloads","issues_url":"https://api.github.com/repos/dbfit/dbfit/issues{/number}","pulls_url":"https://api.github.com/repos/dbfit/dbfit/pulls{/number}","milestones_url":"https://api.github.com/repos/dbfit/dbfit/milestones{/number}","notifications_url":"https://api.github.com/repos/dbfit/dbfit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbfit/dbfit/labels{/name}","releases_url":"https://api.github.com/repos/dbfit/dbfit/releases{/id}","deployments_url":"https://api.github.com/repos/dbfit/dbfit/deployments","created_at":"2012-12-22T08:26:13Z","updated_at":"2016-12-01T15:49:25Z","pushed_at":"2016-12-03T20:25:10Z","git_url":"git://github.com/dbfit/dbfit.git","ssh_url":"git@github.com:dbfit/dbfit.git","clone_url":"https://github.com/dbfit/dbfit.git","svn_url":"https://github.com/dbfit/dbfit","homepage":"http://dbfit.github.io/dbfit","size":8879,"stargazers_count":124,"watchers_count":124,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":58,"mirror_url":null,"open_issues_count":96,"forks":58,"open_issues":96,"watchers":124,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/524"},"html":{"href":"https://github.com/dbfit/dbfit/pull/524"},"issue":{"href":"https://api.github.com/repos/dbfit/dbfit/issues/524"},"comments":{"href":"https://api.github.com/repos/dbfit/dbfit/issues/524/comments"},"review_comments":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/524/comments"},"review_comment":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dbfit/dbfit/pulls/524/commits"},"statuses":{"href":"https://api.github.com/repos/dbfit/dbfit/statuses/b4dd444e127bde7264c1999a08229f983a4457a9"}}}}
{"actor":{"display_login":"MMatten"}}