Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package com.ogiqvo;
  2.  
  3. import com.ogiqvo.vtm.tile.ISQLite3Tile2blobHandler;
  4.  
  5. import org.oscim.core.Tile;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8.  
  9. import java.io.InputStream;
  10. import java.sql.Blob;
  11. import java.sql.Connection;
  12. import java.sql.DriverManager;
  13. import java.sql.PreparedStatement;
  14. import java.sql.ResultSet;
  15. import java.sql.SQLException;
  16.  
  17. public class BlobH2Handler implements ISQLite3Tile2blobHandler {
  18. static final Logger log = LoggerFactory.getLogger(BlobH2Handler.class);
  19.  
  20. String path;
  21. Connection connection;
  22. PreparedStatement preparedStatement;
  23.  
  24. public BlobH2Handler(String path) {
  25. this.path = path;
  26. }
  27.  
  28. @Override
  29. public void load() {
  30. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  31. try {
  32. connection = DriverManager.getConnection("jdbc:h2:" + this.path + ";USER=sa;PASSWORD=Passw0rd");
  33. preparedStatement = connection.prepareStatement("SELECT b FROM a WHERE x=? AND y=? AND z=?");
  34. } catch (SQLException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38. }
  39.  
  40. @Override
  41. public InputStream inputStreamForTile(Tile tile) {
  42. synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
  43. int x = tile.tileX;
  44. int y = tile.tileY;
  45. int z = tile.zoomLevel;
  46. ResultSet resultSet = null;
  47. try {
  48. preparedStatement.setInt(1, x);
  49. preparedStatement.setInt(2, y);
  50. preparedStatement.setInt(3, z);
  51. resultSet = preparedStatement.executeQuery();
  52. while (resultSet.next()) {
  53. Blob b = resultSet.getBlob(1);
  54. return b.getBinaryStream();
  55. }
  56. } catch (SQLException e) {
  57. e.printStackTrace();
  58. } finally {
  59. if (resultSet != null) {
  60. try {
  61. resultSet.close();
  62. } catch (SQLException e) {
  63. e.printStackTrace();
  64. }
  65. }
  66. }
  67. return null;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement