use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class LevelDBEntityStoreMixin method applyChanges.
@Override
public void applyChanges(MapChanges changes) throws IOException {
final WriteBatch writeBatch = db.createWriteBatch();
try {
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 {
super.close();
String jsonState = toString();
writeBatch.put(ref.identity().getBytes(charset), jsonState.getBytes(charset));
}
};
}
@Override
public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
return new StringWriter(1000) {
@Override
public void close() throws IOException {
super.close();
String jsonState = toString();
writeBatch.put(ref.identity().getBytes(charset), jsonState.getBytes(charset));
}
};
}
@Override
public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
writeBatch.delete(ref.identity().getBytes(charset));
}
});
db.write(writeBatch);
} finally {
writeBatch.close();
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class SQLEntityStoreMixin method getValue.
protected EntityValueResult getValue(EntityReference ref) {
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
connection = database.getConnection();
ps = database.prepareGetEntityStatement(connection);
database.populateGetEntityStatement(ps, ref);
rs = ps.executeQuery();
if (!rs.next()) {
throw new EntityNotFoundException(ref);
}
EntityValueResult result = database.getEntityValue(rs);
return result;
} catch (SQLException sqle) {
throw new EntityStoreException("Unable to get Entity " + ref, sqle);
} finally {
SQLUtil.closeQuietly(rs);
SQLUtil.closeQuietly(ps);
SQLUtil.closeQuietly(connection);
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException 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);
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class AbstractRiakMapEntityStore method get.
@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
try {
Bucket bucket = riakClient.fetchBucket(bucketKey).execute();
IRiakObject entity = bucket.fetch(entityReference.identity()).execute();
if (entity == null) {
throw new EntityNotFoundException(entityReference);
}
String jsonState = entity.getValueAsString();
return new StringReader(jsonState);
} catch (RiakRetryFailedException ex) {
throw new EntityStoreException("Unable to get Entity " + entityReference.identity(), ex);
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class VoldemortEntityStoreMixin method get.
@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
try {
Versioned<byte[]> versioned = client.get(entityReference.identity());
if (versioned == null) {
throw new EntityNotFoundException(entityReference);
}
byte[] serializedState = versioned.getValue();
return new StringReader(new String(serializedState, "UTF-8"));
} catch (IOException e) {
throw new EntityStoreException(e);
}
}
Aggregations