Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. CREATE TABLE `test_gazette` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `grower_id` bigint(20) DEFAULT NULL,
  4. `crop_day` bigint(20) DEFAULT NULL,
  5. `uuid` varchar(50) DEFAULT NULL,
  6. PRIMARY KEY (`id`),
  7. UNIQUE KEY `UNIQUE` (`uuid`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=6601 DEFAULT CHARSET=utf8
  9.  
  10. ----------------------------------------
  11. def generateGazetteWithNewAlgorithmeImplementation(){
  12.  
  13. // Get Grower list of this UNIT
  14. Mill mill = Mill.findById(18); //Mill.findById(18);
  15. Unit unit = Unit.findById(1112); // Unit.findById(1112);
  16. List<Grower> growers = Grower.findAllByMillAndUnit(mill, unit);
  17.  
  18. def sql = new Sql(dataSource)
  19.  
  20. //Create Config Object
  21. Config config = new Config(55, 6, 2, 5, 5, 15,
  22. 20, 7, 10, 12, 18);
  23.  
  24. GazetteGenerator gazetteGenerator = new GazetteGenerator(unit.id, unit.name, getAlgorithmSensitiveGrowerList(unit.name, growers), config)
  25. long[][] cropdayWiseGrowersList = gazetteGenerator.getGazetteAsGrowerIdArray();
  26.  
  27. String sqlString ="insert into test_gazette(grower_id, crop_day, uuid) ";
  28.  
  29. StringBuilder stringBuilder = new StringBuilder(sqlString);
  30.  
  31. for(int i=0; i<cropdayWiseGrowersList.length; i++) {
  32. // System.out.println("Crop day--" + (i + 1));
  33. long[] a = cropdayWiseGrowersList[i];
  34. for (int j = 0; j < a.length; j++) {
  35. stringBuilder.append("values(");
  36. stringBuilder.append(cropdayWiseGrowersList[i][j]);
  37. stringBuilder.append(",");
  38. stringBuilder.append(i);
  39. stringBuilder.append(",");
  40. stringBuilder.append("UUID()");
  41. stringBuilder.append(")");
  42. if(j != a.length - 1){
  43. stringBuilder.append(",")
  44. }
  45. }
  46. }
  47.  
  48. System.out.println(stringBuilder);
  49.  
  50. sql.execute(stringBuilder.toString());
  51. /*def updateCounts = sql.withBatch('insert into test_gazette(grower_id, crop_day, uuid) values (?, ?, UUID())') { ps ->
  52.  
  53. for(int i=0; i<cropdayWiseGrowersList.length; i++) {
  54. // System.out.println("Crop day--" + (i + 1));
  55. long[] a = cropdayWiseGrowersList[i];
  56. for (int j = 0; j < a.length; j++) {
  57. ps.addBatch([cropdayWiseGrowersList[i][j], i]);
  58. }
  59. }
  60. }*/
  61.  
  62.  
  63.  
  64. for(int i=0; i<cropdayWiseGrowersList.length; i++) {
  65. System.out.println("Crop day-- "+ (i));
  66. long[] a = cropdayWiseGrowersList[i];
  67. for(int j=0; j<a.length; j++) {
  68. System.out.print(cropdayWiseGrowersList[i][j] + "\t");
  69. }
  70. System.out.println("");
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement