Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. public class DataConverter {
  2.  
  3. ...
  4.  
  5. case Types.NUMERIC:
  6. if (mapNumerics) {
  7. int precision = metadata.getPrecision(col);
  8. if (precision < 19) {
  9. Schema schema;
  10. if (metadata.getScale(col) == 0) { // integer
  11. if (precision > 9) {
  12. schema = (optional) ? Schema.OPTIONAL_INT64_SCHEMA :
  13. Schema.INT64_SCHEMA;
  14. } else if (precision > 4) {
  15. schema = (optional) ? Schema.OPTIONAL_INT32_SCHEMA :
  16. Schema.INT32_SCHEMA;
  17. } else if (precision > 2) {
  18. schema = (optional) ? Schema.OPTIONAL_INT16_SCHEMA :
  19. Schema.INT16_SCHEMA;
  20. } else {
  21. schema = (optional) ? Schema.OPTIONAL_INT8_SCHEMA :
  22. Schema.INT8_SCHEMA;
  23. }
  24. } else { // double
  25. schema = (optional) ? Schema.OPTIONAL_FLOAT64_SCHEMA :
  26. Schema.FLOAT64_SCHEMA;
  27. }
  28.  
  29. builder.field(fieldName, schema);
  30. break;
  31. }
  32. }
  33.  
  34. ...
  35.  
  36. case Types.NUMERIC:
  37. if (mapNumerics) {
  38. ResultSetMetaData metadata = resultSet.getMetaData();
  39. int precision = metadata.getPrecision(col);
  40. if (precision < 19) {
  41. if (metadata.getScale(col) == 0) { // integer
  42. if (precision > 9) {
  43. colValue = resultSet.getLong(col);
  44. } else if (precision > 4) {
  45. colValue = resultSet.getInt(col);
  46. } else if (precision > 2) {
  47. colValue = resultSet.getShort(col);
  48. } else {
  49. colValue = resultSet.getByte(col);
  50. }
  51. break;
  52. } else { // double
  53. colValue = resultSet.getDouble(col);
  54. break;
  55. }
  56. }
  57. }
  58.  
  59. ...
  60.  
  61. }
Add Comment
Please, Sign In to add comment