Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.BinaryKey


    public void shouldFailWhenGettingTheTextOfBinaryWhichIsntStored() throws RepositoryException {
        getBinaryStore().getText(new StoredBinaryValue(getBinaryStore(), invalidBinaryKey(), 0));
    }

    private BinaryKey invalidBinaryKey() {
        return new BinaryKey(UUID.randomUUID().toString());
    }
View Full Code Here


    private BinaryKey key;

    @Before
    public void beforeEach() {
        key = new BinaryKey(CONTENT_SHA1);
    }
View Full Code Here

        assertThat(key.toBytes(), is(CONTENT_SHA1_BYTES));
    }

    @Test
    public void shouldEqualAnotherBinaryKeyWithSameSha1() {
        BinaryKey key2 = new BinaryKey(CONTENT_SHA1);
        assertThat(key2.equals(key), is(true));
        assertThat(key2.compareTo(key), is(0));
    }
View Full Code Here

        BinaryValue v = defaultStore.storeValue(new ByteArrayInputStream(randomContent()), false);
        BinaryValue v1 = alternativeStore.storeValue(new ByteArrayInputStream(randomContent()), false);

        assertEquals(defaultStore, store.findBinaryStoreContainingKey(v.getKey()));
        assertEquals(alternativeStore, store.findBinaryStoreContainingKey(v1.getKey()));
        assertNull(store.findBinaryStoreContainingKey(new BinaryKey("this-is-not-a-key")));
    }
View Full Code Here

        assertTrue(alternativeStore.hasBinary(v.getKey()));
    }

    @Test( expected = BinaryStoreException.class )
    public void shouldRaiseAnExceptionWhenMovingAKeyThatDoesntExist() throws BinaryStoreException {
        store.moveValue(new BinaryKey("this-doesnt-exist"), alternativeHint);
    }
View Full Code Here

    public BinaryValue storeValue( InputStream stream, boolean markAsUnused ) throws BinaryStoreException {
        // store into temporary file system store and get SHA-1
        BinaryValue temp = cache.storeValue(stream, markAsUnused);
        try {
            // prepare new binary key based on SHA-1
            BinaryKey key = new BinaryKey(temp.getKey().toString());

            // check for duplicate content
            if (this.contentExists(key, ALIVE)) {
                return new StoredBinaryValue(this, key, temp.getSize());
            }

            // check unused content
            if (this.contentExists(key, UNUSED)) {
                if (!markAsUnused) {
                    // mark it as used
                    session.execute("UPDATE modeshape.binary SET usage=1 WHERE cid='" + key + "';");
                }
                return new StoredBinaryValue(this, key, temp.getSize());
            }

            if (!markAsUnused) {
                // store content as used
                String stmt = "INSERT INTO modeshape.binary (cid, payload, usage) VALUES (?,?,1)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), buffer(stream)));
            } else {
                // store content as un-used
                String stmt = "INSERT INTO modeshape.binary (cid, usage_time, payload, usage) VALUES (?,?,?,0)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), new Date(), buffer(stream)));
            }
            return new StoredBinaryValue(this, key, temp.getSize());
        } catch (BinaryStoreException e) {
            throw e;
        } catch (Exception e) {
View Full Code Here

        try {
            ResultSet rs = session.execute("SELECT cid from modeshape.binary WHERE usage=1;");
            Iterator<Row> it = rs.iterator();
            HashSet<BinaryKey> keys = new HashSet<BinaryKey>();
            while (it.hasNext()) {
                keys.add(new BinaryKey(it.next().getString("cid")));
            }
            return keys;
        } catch (RuntimeException e) {
            throw new BinaryStoreException(e);
        }
View Full Code Here

                           String sourceName,
                           URL content,
                           long size,
                           String nameHint,
                           MimeTypeDetector mimeTypeDetector ) {
        super(new BinaryKey(sha1), sourceName, content.toExternalForm(), size, nameHint, mimeTypeDetector);
        this.url = content;
    }
View Full Code Here

    private final BinaryKey key;

    public static BinaryKey keyFor( byte[] sha1 ) {
        try {
            byte[] hash = SecureHash.getHash(Algorithm.SHA_1, sha1);
            return new BinaryKey(hash);
        } catch (NoSuchAlgorithmException e) {
            throw new SystemFailureException(e);
        }
    }
View Full Code Here

        Set<BinaryKey> keys = new LinkedHashSet<>();

        try {
            ResultSet rs = executeQuery(getBinaryKeysSql);
            while (rs.next()) {
                keys.add(new BinaryKey(rs.getString(1)));
            }
            return keys;
        } finally {
            tryToClose(getBinaryKeysSql);
        }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.BinaryKey

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.