{"action":"created","issue":{"url":"https://api.github.com/repos/datastax/java-driver/issues/679","repository_url":"https://api.github.com/repos/datastax/java-driver","labels_url":"https://api.github.com/repos/datastax/java-driver/issues/679/labels{/name}","comments_url":"https://api.github.com/repos/datastax/java-driver/issues/679/comments","events_url":"https://api.github.com/repos/datastax/java-driver/issues/679/events","html_url":"https://github.com/datastax/java-driver/pull/679","id":156429807,"number":679,"title":"Allow to set default value when getting primitive type value is null","user":{"login":"jiafu1115","id":5654180,"avatar_url":"https://avatars.githubusercontent.com/u/5654180?v=3","gravatar_id":"","url":"https://api.github.com/users/jiafu1115","html_url":"https://github.com/jiafu1115","followers_url":"https://api.github.com/users/jiafu1115/followers","following_url":"https://api.github.com/users/jiafu1115/following{/other_user}","gists_url":"https://api.github.com/users/jiafu1115/gists{/gist_id}","starred_url":"https://api.github.com/users/jiafu1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiafu1115/subscriptions","organizations_url":"https://api.github.com/users/jiafu1115/orgs","repos_url":"https://api.github.com/users/jiafu1115/repos","events_url":"https://api.github.com/users/jiafu1115/events{/privacy}","received_events_url":"https://api.github.com/users/jiafu1115/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-05-24T06:34:48Z","updated_at":"2016-05-25T01:09:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/datastax/java-driver/pulls/679","html_url":"https://github.com/datastax/java-driver/pull/679","diff_url":"https://github.com/datastax/java-driver/pull/679.diff","patch_url":"https://github.com/datastax/java-driver/pull/679.patch"},"body":"Motivation:\r\n\r\nWhen we got primitive type such as calling getInt(int i),\r\nwe would get ‘0’ when the value is null. We can’t set the default value\r\nif the value is null when expected the value isn't 0/false .\r\nIf we want to distinguish 0 and null , we should use isNull() or get(i,\r\nInteger.class). It isn’t convenient for coding.\r\nSo add new methods to allow to setting the default value when got value\r\nis Null.\r\n\r\nModifications:\r\n\r\nadd extra new methods with default value such as: \r\npublic int getInt(int i, int defaultValue);\r\n\r\nResult:\r\n\r\nMore flexible and convenient."},"comment":{"url":"https://api.github.com/repos/datastax/java-driver/issues/comments/221447159","html_url":"https://github.com/datastax/java-driver/pull/679#issuecomment-221447159","issue_url":"https://api.github.com/repos/datastax/java-driver/issues/679","id":221447159,"user":{"login":"jiafu1115","id":5654180,"avatar_url":"https://avatars.githubusercontent.com/u/5654180?v=3","gravatar_id":"","url":"https://api.github.com/users/jiafu1115","html_url":"https://github.com/jiafu1115","followers_url":"https://api.github.com/users/jiafu1115/followers","following_url":"https://api.github.com/users/jiafu1115/following{/other_user}","gists_url":"https://api.github.com/users/jiafu1115/gists{/gist_id}","starred_url":"https://api.github.com/users/jiafu1115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiafu1115/subscriptions","organizations_url":"https://api.github.com/users/jiafu1115/orgs","repos_url":"https://api.github.com/users/jiafu1115/repos","events_url":"https://api.github.com/users/jiafu1115/events{/privacy}","received_events_url":"https://api.github.com/users/jiafu1115/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T01:09:49Z","updated_at":"2016-05-25T01:09:49Z","body":"@olim7t \r\n\r\nThanks for your comment. Everybody wants to make code clean/simple/thin. So when I use the driver's api in my project, If not add new methods it will looks not very beautiful.\r\n\r\nFor example:\r\n\r\n` return  new DO(\r\n                        row.isNull(\"a\") ? 0 : row.getInt(\"a\"),\r\n                        row.isNull(\"b\") ? 0 : row.getLong(\"b\"),\r\n                        row.isNull(\"c\") ? 0 : row.getShort(\"c\"),\r\n                        row.isNull(\"d\") ? 0.0 : row.getDouble(\"d\"),\r\n                        row.isNull(\"e\") ? false : row.getBoolean(\"e\"),\r\n                       );`\r\n\r\n` return  new DO(\r\n                        row.getInt(\"a\",0),\r\n                        row.getLong(\"b\",0),\r\n                        row.getShort(\"c\",0),\r\n                        row.getDouble(\"d\",0.0),\r\n                        row.getBoolean(\"e\",false),\r\n                       );`\r\n\r\nWith the new apis, it looks more simpler. \r\n\r\nAnd with only one getInt(\"a\") existed, It will may involved bug  easier due to not pay attention to distinguish the null an 0 when the coder doesn't read the api doc: when null return 0. But the api added, it will make the coder pay more attention about it. He/She may know there must existed Null.\r\n\r\nWhat's more, most APIs consider the default value setting instead of call 2 apis together such as:\r\n\r\nhttp://grepcode.com/file/repo1.maven.org/maven2/commons-configuration/commons-configuration/1.10/org/apache/commons/configuration/Configuration.java#Configuration\r\n\r\n    byte getByte(String key);\r\n    byte getByte(String key, byte defaultValue);\r\n\r\nWhatever, as you talked, it is balance between thin and convenience. So it is up to your decision.\r\nI just give my suggestions.\r\n"}}
{"actor":{"display_login":"jiafu1115"}}