當前位置: 首頁>>代碼示例>>Java>>正文


Java Handle.close方法代碼示例

本文整理匯總了Java中org.skife.jdbi.v2.Handle.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Handle.close方法的具體用法?Java Handle.close怎麽用?Java Handle.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.skife.jdbi.v2.Handle的用法示例。


在下文中一共展示了Handle.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUndoPixels

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
public List<DBPixelPlacement> getUndoPixels(User who) {
    Handle h = dbi.open();
    List<Map<String, Object>> output = h
            .createQuery("SELECT DISTINCT secondary_id FROM pixels WHERE rollback_action AND who = :who AND secondary_id IS NOT NULL")
            .bind("who", who.getId())
            .list(); // this selects all pixels that we previously have rolled back.
    List<DBPixelPlacement> pixels = new ArrayList<>();
    for (Map<String, Object> entry : output) {
        int fromId = toIntExact((long) entry.get("secondary_id"));
        DBPixelPlacement fromPixel = getHandle().getPixel(fromId); // get the original pixel, the one that we previously rolled back
        
        boolean can_undo = getHandle().getCanUndo(fromPixel.x, fromPixel.y, fromPixel.id);
        if (can_undo) { // this basically checks if there are pixels that are more recent
            pixels.add(fromPixel); // add and later return
        }
    }
    h.close();
    return pixels;
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:20,代碼來源:Database.java

示例2: createTestData

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
@Before
public void createTestData() throws Exception {
  Handle handle = dbiProvider.get().open();

  Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));

  Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database);
  liquibase.update((String) null);

  try {
    database.close();
  } catch (Throwable t) {
  }

  handle.close();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:SingularityHistoryTest.java

示例3: doReadDerby

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Derby does not allow to read from the blob after the connection has been closed.
 * It also requires an outcome of commit/rollback.
 */
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream doReadDerby(String id) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM icon_filestore WHERE id=?", id);

        Optional<Blob> blob = res.stream()
            .map(row -> row.get("data"))
            .map(Blob.class::cast)
            .findFirst();

        if (blob.isPresent()) {
            return new HandleCloserInputStream(h, blob.get().getBinaryStream());
        } else {
            h.commit();
            h.close();
            return null;
        }

    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        // Do cleanup
        try {
            h.rollback();
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
            // ignore
        }
        IOUtils.closeQuietly(h);

        throw IconDataAccessException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:38,代碼來源:SqlIconFileStore.java

示例4: doReadPostgres

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Postgres does not allow to read from the large object after the connection has been closed.
 */
private InputStream doReadPostgres(String id) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM icon_filestore WHERE id=?", id);

        Optional<Long> oid = res.stream()
            .map(row -> row.get("data"))
            .map(Long.class::cast)
            .findFirst();

        if (oid.isPresent()) {
            LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI();
            LargeObject obj = lobj.open(oid.get(), LargeObjectManager.READ);
            return new HandleCloserInputStream(h, obj.getInputStream());
        } else {
            h.close();
            return null;
        }

    } catch (SQLException e) {
        IOUtils.closeQuietly(h);
        throw IconDataAccessException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:30,代碼來源:SqlIconFileStore.java

示例5: doReadDerby

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Derby does not allow to read from the blob after the connection has been closed.
 * It also requires an outcome of commit/rollback.
 */
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream doReadDerby(String path) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);

        Optional<Blob> blob = res.stream()
            .map(row -> row.get("data"))
            .map(Blob.class::cast)
            .findFirst();

        if (blob.isPresent()) {
            return new HandleCloserInputStream(h, blob.get().getBinaryStream());
        } else {
            h.commit();
            h.close();
            return null;
        }

    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        // Do cleanup
        try {
            h.rollback();
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
            // ignore
        }
        IOUtils.closeQuietly(h);

        throw ExtensionDataAccessException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:38,代碼來源:SqlExtensionFileStore.java

示例6: doReadPostgres

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Postgres does not allow to read from the large object after the connection has been closed.
 */
private InputStream doReadPostgres(String path) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);

        Optional<Long> oid = res.stream()
            .map(row -> row.get("data"))
            .map(Long.class::cast)
            .findFirst();

        if (oid.isPresent()) {
            LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI();
            LargeObject obj = lobj.open(oid.get(), LargeObjectManager.READ);
            return new HandleCloserInputStream(h, obj.getInputStream());
        } else {
            h.close();
            return null;
        }

    } catch (SQLException e) {
        IOUtils.closeQuietly(h);
        throw ExtensionDataAccessException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:30,代碼來源:SqlExtensionFileStore.java

示例7: getRollbackPixels

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
public List<DBRollbackPixel> getRollbackPixels(User who, int fromSeconds) {
    Handle h = dbi.open();
    List<Map<String, Object>> output = h
            .createQuery("SELECT id, secondary_id FROM pixels WHERE most_recent AND who = :who AND (time + INTERVAL :seconds SECOND > NOW())")
            .bind("who", who.getId())
            .bind("seconds", fromSeconds)
            .list(); //this selects all pixels by the banned user that are the most_recent
    List<DBRollbackPixel> pixels = new ArrayList<>();
    for (Map<String, Object> entry : output) {
        DBPixelPlacement toPixel;
        try {
            int prevId = toIntExact((long) entry.get("secondary_id"));
            toPixel = getHandle().getPixel(prevId); //if previous pixel exists

            // while the user who placed the previous pixel is banned or previous pixel was undone
            while (toPixel.role.lessThan(Role.GUEST) || toPixel.ban_expiry > Instant.now().toEpochMilli() || toPixel.userId == who.getId() || toPixel.undoAction) {
                if (toPixel.secondaryId != 0) {
                    toPixel = getHandle().getPixel(toPixel.secondaryId); //if is banned gets previous pixel
                } else {
                    toPixel = null; // if is banned but no previous pixel exists return blank pixel
                    break; // and no reason to loop because blank pixel isn't placed by an user
                }
            }
        } catch (NullPointerException e) { // .get() throws NullPointerException if secondary_id is NULL
            toPixel = null; //blank pixel
        }
        pixels.add(new DBRollbackPixel(toPixel, toIntExact((long) entry.get("id")))); //add and later return
    }
    h.close();
    return pixels;
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:32,代碼來源:Database.java

示例8: get

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
public String get() {
    String name;
    Handle handle = dbi.open();
    try {
        name = handle.createQuery("select description from my_test")
                .map(StringMapper.FIRST)
                .first();
    } finally {
        handle.close();
    }
    return name;
}
 
開發者ID:dhagge,項目名稱:spring-boot-jdbi-seed,代碼行數:14,代碼來源:TestResource.java

示例9: blowDBAway

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
@After
public void blowDBAway() {
  Handle handle = dbiProvider.get().open();

  handle.execute("DELETE FROM taskHistory;DELETE FROM requestHistory;DELETE FROM deployHistory;");

  handle.close();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:9,代碼來源:SingularityHistoryTest.java

示例10: createTables

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * execute the schemaCreationScript using JDBI library.
 */
public void createTables() {
	final DBI dbi = LocalRegistry.getDbi();
	final Handle handle = dbi.open();
	try {
		handle.execute(this.schemaCreationScript);
	} finally {
		handle.close();
	}
}
 
開發者ID:kiswanij,項目名稱:jk-drop-wizard-full-example,代碼行數:13,代碼來源:SchemaBuilder.java

示例11: dropTables

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * execute the schemaDroppScript using JDBI library.
 */
public void dropTables() {
	final DBI dbi = LocalRegistry.getDbi();
	final Handle handle = dbi.open();
	try {
		handle.execute(this.schemaDroppScript);
	} finally {
		handle.close();
	}
}
 
開發者ID:kiswanij,項目名稱:jk-drop-wizard-full-example,代碼行數:13,代碼來源:SchemaBuilder.java

示例12: doReadDerby

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Derby does not allow to read from the blob after the connection has been closed.
 * It also requires an outcome of commit/rollback.
 */
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream doReadDerby(String path) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);

        Optional<Blob> blob = res.stream()
            .map(row -> row.get("data"))
            .map(Blob.class::cast)
            .findFirst();

        if (blob.isPresent()) {
            return new HandleCloserInputStream(h, blob.get().getBinaryStream());
        } else {
            h.commit();
            h.close();
            return null;
        }

    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        // Do cleanup
        try {
            h.rollback();
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) {
            // ignore
        }
        IOUtils.closeQuietly(h);

        throw FileStoreException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis-rest,代碼行數:38,代碼來源:SqlFileStore.java

示例13: doReadPostgres

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
/**
 * Postgres does not allow to read from the large object after the connection has been closed.
 */
private InputStream doReadPostgres(String path) {
    Handle h = dbi.open();
    try {
        h.getConnection().setAutoCommit(false);

        List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);

        Optional<Long> oid = res.stream()
            .map(row -> row.get("data"))
            .map(Long.class::cast)
            .findFirst();

        if (oid.isPresent()) {
            LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI();
            LargeObject obj = lobj.open(oid.get(), LargeObjectManager.READ);
            return new HandleCloserInputStream(h, obj.getInputStream());
        } else {
            h.close();
            return null;
        }

    } catch (SQLException e) {
        IOUtils.closeQuietly(h);
        throw FileStoreException.launderThrowable(e);
    }
}
 
開發者ID:syndesisio,項目名稱:syndesis-rest,代碼行數:30,代碼來源:SqlFileStore.java

示例14: deleteRepairRun

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
@Override
public Optional<RepairRun> deleteRepairRun(UUID id) {
  RepairRun result = null;
  Handle handle = null;
  try {
    handle = jdbi.open();
    handle.begin();
    IStoragePostgreSql pg = getPostgresStorage(handle);
    RepairRun runToDelete = pg.getRepairRun(UuidUtil.toSequenceId(id));
    if (runToDelete != null) {
      int segmentsRunning
          = pg.getSegmentAmountForRepairRunWithState(UuidUtil.toSequenceId(id), RepairSegment.State.RUNNING);
      if (segmentsRunning == 0) {
        pg.deleteRepairSegmentsForRun(UuidUtil.toSequenceId(runToDelete.getId()));
        pg.deleteRepairRun(UuidUtil.toSequenceId(id));
        result = runToDelete.with().runState(RepairRun.RunState.DELETED).build(id);
      } else {
        LOG.warn("not deleting RepairRun \"{}\" as it has segments running: {}", id, segmentsRunning);
      }
    }
    handle.commit();
  } catch (DBIException ex) {
    LOG.warn("DELETE failed", ex);
    ex.printStackTrace();
    if (handle != null) {
      handle.rollback();
    }
  } finally {
    if (handle != null) {
      handle.close();
    }
  }
  if (result != null) {
    tryDeletingRepairUnit(result.getRepairUnitId());
  }
  return Optional.fromNullable(result);
}
 
開發者ID:thelastpickle,項目名稱:cassandra-reaper,代碼行數:38,代碼來源:PostgresStorage.java

示例15: getAsStreamingOutput

import org.skife.jdbi.v2.Handle; //導入方法依賴的package包/類
@Override
public Consumer<OutputStream> getAsStreamingOutput(String path, GetOptions options) {

    GetOptions o;
    if (options != null) {
        o = options;
    } else {
        o = new GetOptions();
    }

    // Lets normalize the path a bit
    String baseDBPath = JsonRecordSupport.convertToDBPath(path);
    String like = baseDBPath + "%";

    Consumer<OutputStream> result = null;
    final Handle h = dbi.open();
    try {
        // Creating the iterator could fail with a runtime exception,
        String sql = "select path,value,kind from jsondb where path LIKE :like order by path";
        ResultIterator<JsonRecord> iterator = h.createQuery(sql)
            .bind("like", like)
            .map(JsonRecordMapper.INSTANCE)
            .iterator();
        try {
            // At this point we know if we can produce results..
            if (iterator.hasNext()) {
                result = output -> {
                    try {
                        Consumer<JsonRecord> toJson = JsonRecordSupport.recordsToJsonStream(baseDBPath, output, o);
                        iterator.forEachRemaining(toJson);
                        toJson.accept(null);
                    } catch (IOException e) {
                        throw new JsonDBException(e);
                    } finally {
                        iterator.close();
                        h.close();
                    }
                };
            }
        } finally {
            // if we are producing results, then defer closing the iterator
            if (result == null) {
                iterator.close();
            }
        }
    } finally {
        // if we are producing results, then defer closing the handle
        if (result == null) {
            h.close();
        }
    }
    return result;
}
 
開發者ID:syndesisio,項目名稱:syndesis-rest,代碼行數:54,代碼來源:SqlJsonDB.java


注:本文中的org.skife.jdbi.v2.Handle.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。