use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class JCloudsMapEntityStoreMixin method get.
@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
InputStreamMap isMap = storeContext.createInputStreamMap(container);
InputStream input = isMap.get(entityReference.identity());
if (input == null) {
throw new EntityNotFoundException(entityReference);
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Inputs.byteBuffer(input, 4096).transferTo(Outputs.byteBuffer(baos));
return new StringReader(baos.toString("UTF-8"));
} catch (IOException ex) {
throw new EntityStoreException("Unable to read entity state for: " + entityReference, ex);
} finally {
try {
input.close();
} catch (IOException ignored) {
}
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class JdbmEntityStoreMixin method get.
@ReadLock
@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
try {
Long stateIndex = getStateIndex(entityReference.identity());
if (stateIndex == null) {
throw new EntityNotFoundException(entityReference);
}
byte[] serializedState = (byte[]) recordManager.fetch(stateIndex, serializer);
if (serializedState == null) {
throw new EntityNotFoundException(entityReference);
}
return new StringReader(new String(serializedState, "UTF-8"));
} catch (IOException e) {
throw new EntityStoreException(e);
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class GaeEntityStoreMixin method get.
@Override
public Reader get(EntityReference ref) throws EntityStoreException {
try {
Key key = KeyFactory.createKey(entityKind, ref.toURI());
Entity entity = datastore.get(key);
Text serializedState = (Text) entity.getProperty("value");
if (serializedState == null) {
throw new EntityNotFoundException(ref);
}
return new StringReader(serializedState.getValue());
} catch (com.google.appengine.api.datastore.EntityNotFoundException e) {
e.printStackTrace();
throw new EntityNotFoundException(ref);
}
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class MongoMapEntityStoreMixin method applyChanges.
@Override
public void applyChanges(MapChanges changes) throws IOException {
db.requestStart();
final DBCollection entities = db.getCollection(collectionName);
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();
System.out.println("############################################");
try {
System.out.println(new JSONObject(jsonState).toString(2));
} catch (JSONException ex) {
ex.printStackTrace();
}
System.out.println("############################################");
DBObject bsonState = (DBObject) JSON.parse(jsonState);
BasicDBObject entity = new BasicDBObject();
entity.put(IDENTITY_COLUMN, ref.identity());
entity.put(STATE_COLUMN, bsonState);
entities.save(entity, writeConcern);
}
};
}
@Override
public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
return new StringWriter(1000) {
@Override
public void close() throws IOException {
super.close();
DBObject bsonState = (DBObject) JSON.parse(toString());
BasicDBObject entity = new BasicDBObject();
entity.put(IDENTITY_COLUMN, ref.identity());
entity.put(STATE_COLUMN, bsonState);
entities.update(byIdentity(ref), entity, true, false, writeConcern);
}
};
}
@Override
public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
DBObject entity = entities.findOne(byIdentity(ref));
if (entity == null) {
throw new EntityNotFoundException(ref);
}
entities.remove(entity, writeConcern);
}
});
db.requestDone();
}
use of org.qi4j.spi.entitystore.EntityNotFoundException in project qi4j-sdk by Qi4j.
the class FileEntityStoreMixin method get.
@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
try {
File f = getDataFile(entityReference);
if (!f.exists()) {
throw new EntityNotFoundException(entityReference);
}
byte[] serializedState = fetch(f);
return new StringReader(new String(serializedState, "UTF-8"));
} catch (IOException e) {
throw new EntityStoreException(e);
}
}
Aggregations