Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. package org.openxdata.gis.server;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.sql.*;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Properties;
  12.  
  13. import org.openxdata.gis.client.data.MarkerData;
  14. import org.openxdata.gis.client.data.Report;
  15. import org.openxdata.gis.client.data.ReportData;
  16. import org.openxdata.gis.client.service.ConnectionService;
  17. import org.openxdata.gis.client.service.ConnectionServiceAsync;
  18. import org.openxdata.gis.client.service.MappingService;
  19.  
  20. import com.extjs.gxt.ui.client.widget.MessageBox;
  21. import com.google.gwt.core.client.GWT;
  22. import com.google.gwt.user.client.rpc.ServiceDefTarget;
  23. import com.google.gwt.user.server.rpc.RemoteServiceServlet;
  24.  
  25. public class MappingServiceImpl extends RemoteServiceServlet implements MappingService {
  26.  
  27. private Connection connection;
  28. private Statement statement;
  29. private ResultSet resultSet;
  30.  
  31. private String connectionDriver = "";
  32. private String connectionURL = "";
  33. private String databaseName = "";
  34. private String userName = "";
  35. private String password = "";
  36.  
  37. private String querySQL = "";
  38. private ResultSetMetaData rsmd;
  39.  
  40. private Properties oxdProperties;
  41.  
  42. public void getOXDProperties() {
  43. oxdProperties = new Properties();
  44. try {
  45. oxdProperties.load(new FileInputStream("OPENXDATA_SETTINGS.properties"));
  46. this.userName = oxdProperties.getProperty("hibernate.connection.username");
  47. this.password = oxdProperties.getProperty("hibernate.connection.password");
  48. this.connectionDriver = oxdProperties.getProperty("hibernate.connection.driver_class");
  49. this.connectionURL = oxdProperties.getProperty("hibernate.connection.url");
  50.  
  51. } catch (FileNotFoundException e) {
  52. e.printStackTrace();
  53. } catch (IOException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57.  
  58. public List<String> getReportsNames() {
  59.  
  60. List<String> reportsNames = new ArrayList<String>();
  61. getOXDProperties();
  62. try {
  63. Class.forName(connectionDriver);
  64. connection = DriverManager.getConnection(connectionURL, userName, password);
  65. statement = connection.createStatement();
  66.  
  67. String sql = "SELECT name FROM report";
  68. resultSet = statement.executeQuery(sql);
  69.  
  70. while (resultSet.next()) {
  71. reportsNames.add(resultSet.getString("name"));
  72. }
  73. resultSet.close();
  74. statement.close();
  75. connection.close();
  76. } catch (Exception e) {
  77. MessageBox.alert("Error","Something went wrong! Error as follows: " + e, null);
  78. }
  79. return reportsNames;
  80. }
  81.  
  82. public List<String> getSelectedReportFields(String reportName) {
  83. List<String> reportFields = new ArrayList<String>();
  84. getOXDProperties();
  85. try {
  86. Class.forName(connectionDriver);
  87. connection = DriverManager.getConnection(connectionURL, userName, password);
  88. statement = connection.createStatement();
  89.  
  90. String sql = "SELECT * FROM report WHERE name='" + reportName + "'";
  91. resultSet = statement.executeQuery(sql);
  92. while (resultSet.next()) { //TODO what if there are many reports of the same name? nkv
  93. querySQL = resultSet.getString("query_sql");
  94. }
  95. if (querySQL.length() != 0) { //i.e. the string is not null nkv
  96. resultSet = statement.executeQuery(querySQL);
  97. rsmd = resultSet.getMetaData();
  98. int numberOfColumns = rsmd.getColumnCount();
  99. for (int i=1; i<=numberOfColumns; i++) {
  100. reportFields.add(rsmd.getColumnName(i));
  101. }
  102. }
  103. } catch (Exception e) {
  104. MessageBox.alert("Error","Something went wrong! Error as follows: " + e, null);
  105. }
  106. return reportFields;
  107. }
  108.  
  109. public List<String> getReportDataRow(String reportName, String reportField, String reportFieldValue) {
  110. List<String> reportDataRow = new ArrayList<String>();
  111. getOXDProperties();
  112. try {
  113. Class.forName(connectionDriver);
  114. connection = DriverManager.getConnection(connectionURL, userName, password);
  115. statement = connection.createStatement();
  116.  
  117. String sql = "SELECT * FROM report WHERE name='" + reportName + "'";
  118. resultSet = statement.executeQuery(sql);
  119. while (resultSet.next()) { //TODO what if there are many reports of the same name? nkv
  120. querySQL = resultSet.getString("query_sql");
  121. }
  122. if (querySQL.length() != 0) { //i.e. the string is not null nkv
  123. resultSet = statement.executeQuery(querySQL);
  124. rsmd = resultSet.getMetaData();
  125. System.out.println("this is the report field value from shape file: " + reportFieldValue);
  126. int numberOfColumns = rsmd.getColumnCount();
  127. System.out.println("these are report field values in the database: ");
  128. while (resultSet.next()) {
  129. System.out.println(resultSet.getObject(reportField).toString());
  130. if (resultSet.getObject(reportField).toString().equalsIgnoreCase(reportFieldValue)) {
  131. for (int i=1; i<=numberOfColumns; i++) {
  132. reportDataRow.add(rsmd.getColumnName(i));
  133. reportDataRow.add(resultSet.getObject(i).toString());
  134. }
  135. }
  136. }
  137. }
  138. } catch (Exception e) {
  139. MessageBox.alert("Error","Something went wrong! Error as follows: " + e, null);
  140. }
  141. return reportDataRow;
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement