Package org.akubraproject

Examples of org.akubraproject.BlobStoreConnection


  }

  @Test
  public void testIdMapperStore() throws UnsupportedOperationException,
      IOException {
    BlobStoreConnection connnection = blobStore.openConnection(null, null);
    Blob blob = null;
    try {
      blob = connnection.getBlob(new URI(
          "info:fedora/bhle:10706-a000test/OLEF"), null);
    } catch (UnsupportedIdException e) {
      e.printStackTrace();
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    OutputStream out = null;
    try {
      out = blob.openOutputStream(-1, true);
    } catch (DuplicateBlobException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    try {
      out.write("SOMETHING ID!".getBytes());
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      blob = connnection.getBlob(new URI(
          "info:fedora/bhle:10706-a000test/OLEF"), null);
      Assert.assertTrue(blob.exists());
      blob.delete();
      Assert.assertFalse(blob.exists());
      connnection.close();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
  }
View Full Code Here


  @Test
  @ExpectedException(UnsupportedOperationException.class)
  public void testGettingBlobWithoutProperConvertor()
      throws UnsupportedOperationException, IOException {
    BlobStoreConnection connnection = blobStore.openConnection(null, null);
    try {
      Blob blob = connnection.getBlob(new URI(
          "info:fedora/bhle:10706-a000test/JPG"), null);
      blob.openOutputStream(-1, true);
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
View Full Code Here

  public LowLevelStorageImpl(BlobStore blobStore) {
    this.blobStore = blobStore;
  }

  public void add(String pid, String dsId, InputStream in) throws IOException {
    BlobStoreConnection connection = openConnection(blobStore);
    Blob blob = getBlob(connection, pid, dsId);
    OutputStream out = openOutputStream(blob);
    IOUtils.copy(in, out);
    connection.close();
  }
View Full Code Here

    return null;
  }

  public Blob getBlob(String pid, String dsId) {
    try {
      BlobStoreConnection connection = blobStore.openConnection(null, null);
      return getBlob(connection, pid, dsId);
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

      return URI.create("info:fedora/" + pid + "/" + dsId);
    }
  }

  public void remove(String pid, String dsId) throws IOException {
    BlobStoreConnection connection = openConnection(blobStore);
    Blob blob = getBlob(connection, pid, dsId);
    if (blob.exists()) {
      blob.delete();
    }
    connection.close();
  }
View Full Code Here

    connection.close();
  }

  public void replace(String pid, String dsId, InputStream in)
      throws IOException {
    BlobStoreConnection connection = openConnection(blobStore);
    Blob blob = getBlob(connection, pid, dsId);
    OutputStream out = openOutputStream(blob);
    IOUtils.copy(in, out);
    out.close();
    in.close();
    connection.close();
  }
View Full Code Here

    in.close();
    connection.close();
  }

  public InputStream get(String pid, String dsId) throws IOException {
    BlobStoreConnection connection = openConnection(blobStore);
    Blob blob = getBlob(connection, pid, dsId);
    return blob.openInputStream();
  }
View Full Code Here

    return blob.openInputStream();
  }

  public List<URI> list(String filterPrefix) throws IOException {
    List<URI> ids = new ArrayList<URI>();
    BlobStoreConnection connection = openConnection(blobStore);
    for (Iterator<URI> iterator = connection.listBlobIds(filterPrefix); iterator
        .hasNext();) {
      URI uri = iterator.next();
      ids.add(uri);
    }
    connection.close();
    return ids;
  }
View Full Code Here

    final URI id2 = createId("blobClosedConn2");

    // test con.isClosed() and idempotence of con.close()
    runTests(new Action() {
      public void run(Transaction txn) throws Exception {
        BlobStoreConnection con = store.openConnection(txn, null);
        assertFalse(con.isClosed());

        con.close();
        assertTrue(con.isClosed());

        con.close();
        assertTrue(con.isClosed());

        con.close();
        assertTrue(con.isClosed());
      }
    });

    // test connection operations on a closed connection
    runTests(new Action() {
      public void run(Transaction txn) throws Exception {
        final BlobStoreConnection con = store.openConnection(txn, null);

        for (int idx = 0; idx < 3; idx++) {
          con.close();
          assertTrue(con.isClosed());

          assertEquals(con.getBlobStore(), store);

          shouldFail(new ERunnable() {
            @Override
            public void erun() throws Exception {
              con.getBlob(id1, null);
            }
          }, IllegalStateException.class, null);

          shouldFail(new ERunnable() {
            @Override
            public void erun() throws Exception {
              con.getBlob(null, null);
            }
          }, IllegalStateException.class, null);

          shouldFail(new ERunnable() {
            @Override
            public void erun() throws Exception {
              con.getBlob(new ByteArrayInputStream(new byte[0]), -1, null);
            }
          }, IllegalStateException.class, null);

          if (isListIdsSupp) {
            shouldFail(new ERunnable() {
              @Override
              public void erun() throws Exception {
                con.listBlobIds("foo");
              }
            }, IllegalStateException.class, null);

            shouldFail(new ERunnable() {
              @Override
              public void erun() throws Exception {
                con.listBlobIds(null);
              }
            }, IllegalStateException.class, null);
          }

          if (isSyncSupp) {
            shouldFail(new ERunnable() {
              @Override
              public void erun() throws Exception {
                con.sync();
              }
            }, IllegalStateException.class, null);
          }
        }
      }
    });

    // test non-existent blob operations on a closed connection
    runTests(new Action() {
      public void run(Transaction txn) throws Exception {
        final BlobStoreConnection con = store.openConnection(txn, null);
        final Blob b = getBlob(con, id1, false);

        for (int idx = 0; idx < 3; idx++) {
          con.close();
          assertTrue(con.isClosed());

          assertEquals(b.getConnection(), con);
          assertEquals(b.getId(), id1);

          if (isOutputSupp) {
            shouldFail(new ERunnable() {
              @Override
              public void erun() throws Exception {
                b.openOutputStream(-1, true);
              }
            }, IllegalStateException.class, null);
          }

          shouldFail(new ERunnable() {
            @Override
            public void erun() throws Exception {
              b.exists();
            }
          }, IllegalStateException.class, null);
        }
      }
    });

    // test existing blob operations on a closed connection
    runTests(new Action() {
      public void run(Transaction txn) throws Exception {
        final BlobStoreConnection con = store.openConnection(txn, null);
        final Blob b  = getBlob(con, id1, false);
        final Blob b2 = getBlob(con, id2, false);
        createBlob(con, b, "foo");

        for (int idx = 0; idx < 3; idx++) {
          con.close();
          assertTrue(con.isClosed());

          assertEquals(b.getConnection(), con);
          assertEquals(b.getId(), id1);

          shouldFail(new ERunnable() {
View Full Code Here

  }

  protected void runTests(final ConAction test, boolean commit) throws Exception {
    runTests(new Action() {
      public void run(Transaction txn) throws Exception {
        BlobStoreConnection con = store.openConnection(txn, null);
        assertSame(con.getBlobStore(), store);
        assertFalse(con.isClosed());

        boolean success = false;
        try {
          test.run(con);
          success = true;
        } finally {
          try {
            con.close();
            assertTrue(con.isClosed());
          } catch (Throwable t) {
            if (success)
              rethrow(t);
            t.printStackTrace();
          }
View Full Code Here

TOP

Related Classes of org.akubraproject.BlobStoreConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.