Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ogiqvo;
- import com.ogiqvo.vtm.tile.ISQLite3Tile2blobHandler;
- import org.oscim.core.Tile;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.io.InputStream;
- import java.sql.Blob;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class BlobH2Handler implements ISQLite3Tile2blobHandler {
- static final Logger log = LoggerFactory.getLogger(BlobH2Handler.class);
- String path;
- Connection connection;
- PreparedStatement preparedStatement;
- public BlobH2Handler(String path) {
- this.path = path;
- }
- @Override
- public void load() {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- try {
- connection = DriverManager.getConnection("jdbc:h2:" + this.path + ";USER=sa;PASSWORD=Passw0rd");
- preparedStatement = connection.prepareStatement("SELECT b FROM a WHERE x=? AND y=? AND z=?");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- @Override
- public InputStream inputStreamForTile(Tile tile) {
- synchronized (org.h2.jdbcx.JdbcConnectionPool.class) {
- int x = tile.tileX;
- int y = tile.tileY;
- int z = tile.zoomLevel;
- ResultSet resultSet = null;
- try {
- preparedStatement.setInt(1, x);
- preparedStatement.setInt(2, y);
- preparedStatement.setInt(3, z);
- resultSet = preparedStatement.executeQuery();
- while (resultSet.next()) {
- Blob b = resultSet.getBlob(1);
- return b.getBinaryStream();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement