Search in sources :

Example 1 with RiakException

use of com.basho.riak.client.RiakException in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    try {
        IRiakClient client = RiakFactory.pbcClient("localhost", 8087);
        myBucket = client.fetchBucket("test").execute();
    } catch (RiakException ex) {
        Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : IRiakClient(com.basho.riak.client.IRiakClient) RiakException(com.basho.riak.client.RiakException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with RiakException

use of com.basho.riak.client.RiakException in project qi4j-sdk by Qi4j.

the class AbstractRiakMapEntityStore method applyChanges.

@Override
public void applyChanges(MapChanges changes) throws IOException {
    try {
        final Bucket bucket = riakClient.fetchBucket(bucketKey).execute();
        changes.visitMap(new MapChanger() {

            @Override
            public Writer newEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
                return new StringWriter(1000) {

                    @Override
                    public void close() throws IOException {
                        try {
                            super.close();
                            bucket.store(ref.identity(), toString()).execute();
                        } catch (RiakException ex) {
                            throw new EntityStoreException("Unable to apply entity change: newEntity", ex);
                        }
                    }
                };
            }

            @Override
            public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
                return new StringWriter(1000) {

                    @Override
                    public void close() throws IOException {
                        try {
                            super.close();
                            IRiakObject entity = bucket.fetch(ref.identity()).execute();
                            if (entity == null) {
                                throw new EntityNotFoundException(ref);
                            }
                            bucket.store(ref.identity(), toString()).execute();
                        } catch (RiakException ex) {
                            throw new EntityStoreException("Unable to apply entity change: updateEntity", ex);
                        }
                    }
                };
            }

            @Override
            public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
                try {
                    IRiakObject entity = bucket.fetch(ref.identity()).execute();
                    if (entity == null) {
                        throw new EntityNotFoundException(ref);
                    }
                    bucket.delete(ref.identity()).execute();
                } catch (RiakException ex) {
                    throw new EntityStoreException("Unable to apply entity change: removeEntity", ex);
                }
            }
        });
    } catch (RiakRetryFailedException ex) {
        throw new EntityStoreException("Unable to apply entity changes.", ex);
    }
}
Also used : IRiakObject(com.basho.riak.client.IRiakObject) IOException(java.io.IOException) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) StringWriter(java.io.StringWriter) Bucket(com.basho.riak.client.bucket.Bucket) EntityReference(org.qi4j.api.entity.EntityReference) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException) RiakRetryFailedException(com.basho.riak.client.RiakRetryFailedException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RiakException(com.basho.riak.client.RiakException)

Aggregations

RiakException (com.basho.riak.client.RiakException)2 IRiakClient (com.basho.riak.client.IRiakClient)1 IRiakObject (com.basho.riak.client.IRiakObject)1 RiakRetryFailedException (com.basho.riak.client.RiakRetryFailedException)1 Bucket (com.basho.riak.client.bucket.Bucket)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 PostConstruct (javax.annotation.PostConstruct)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 EntityReference (org.qi4j.api.entity.EntityReference)1 EntityNotFoundException (org.qi4j.spi.entitystore.EntityNotFoundException)1 EntityStoreException (org.qi4j.spi.entitystore.EntityStoreException)1