use of com.bluenimble.platform.db.DatabaseException in project serverless by bluenimble.
the class OrientDatabase method exp.
@Override
public void exp(Set<String> entities, OutputStream out, Map<ExchangeOption, Boolean> options, final ExchangeListener listener) throws DatabaseException {
OCommandOutputListener olistener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
if (listener != null) {
listener.onMessage(iText);
}
}
};
ODatabaseExport export = null;
try {
export = new ODatabaseExport(db, out, olistener);
} catch (IOException e) {
throw new DatabaseException(e.getMessage(), e);
}
export.setIncludeInfo(option(options, ExchangeOption.info, false));
export.setIncludeClusterDefinitions(option(options, ExchangeOption.entities, false));
export.setIncludeSchema(option(options, ExchangeOption.schema, false));
export.setIncludeIndexDefinitions(option(options, ExchangeOption.indexes, false));
export.setIncludeManualIndexes(option(options, ExchangeOption.indexes, false));
export.setPreserveRids(option(options, ExchangeOption.ids, false));
export.setOptions("-compressionLevel=9");
if (entities != null && !entities.isEmpty()) {
export.setIncludeClasses(entities);
}
export.exportDatabase();
export.close();
}
use of com.bluenimble.platform.db.DatabaseException in project serverless by bluenimble.
the class OrientDatabase method imp.
@Override
public void imp(Set<String> entities, InputStream in, Map<ExchangeOption, Boolean> options, final ExchangeListener listener) throws DatabaseException {
OCommandOutputListener olistener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
if (listener != null) {
listener.onMessage(iText);
}
}
};
ODatabaseImport _import = null;
try {
_import = new ODatabaseImport(db, in, olistener);
} catch (IOException e) {
throw new DatabaseException(e.getMessage(), e);
}
_import.setIncludeInfo(option(options, ExchangeOption.info, false));
_import.setIncludeClusterDefinitions(option(options, ExchangeOption.entities, false));
_import.setIncludeSchema(option(options, ExchangeOption.schema, false));
_import.setIncludeIndexDefinitions(option(options, ExchangeOption.indexes, false));
_import.setIncludeManualIndexes(option(options, ExchangeOption.indexes, false));
_import.setPreserveRids(option(options, ExchangeOption.ids, false));
_import.setDeleteRIDMapping(false);
if (entities != null && !entities.isEmpty()) {
_import.setIncludeClasses(entities);
}
_import.importDatabase();
_import.close();
}
use of com.bluenimble.platform.db.DatabaseException in project serverless by bluenimble.
the class OrientDatabase method createIndex.
@Override
public void createIndex(String eType, IndexType type, String name, Field... fields) throws DatabaseException {
eType = checkNotNull(eType);
if (fields == null || fields.length == 0) {
throw new DatabaseException("entity " + eType + ". fields required to create an index");
}
boolean save = false;
OClass oClass = db.getMetadata().getSchema().getClass(eType);
if (oClass == null) {
oClass = db.getMetadata().getSchema().createClass(eType);
save = true;
}
String[] props = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
props[i] = f.name();
if (f.type() != null) {
oClass.createProperty(f.name(), FieldTypes.get(f.type()));
}
}
switch(type) {
case Text:
oClass.createIndex(eType + Lang.DOT + name, "FULLTEXT", null, null, Lucene, props);
break;
case Spacial:
oClass.createIndex(eType + Lang.DOT + name, "SPATIAL", null, null, Lucene, props);
break;
default:
oClass.createIndex(eType + Lang.DOT + name, IndexTypes.get(type), props);
break;
}
if (save) {
db.getMetadata().getSchema().save();
}
}
use of com.bluenimble.platform.db.DatabaseException in project serverless by bluenimble.
the class OrientDatabase method delete.
@Override
public int delete(String eType, Object id) throws DatabaseException {
checkNotNull(eType);
if (id == null) {
throw new DatabaseException("can't delete object (missing object id)");
}
if (!db.getMetadata().getSchema().existsClass(eType)) {
return 0;
}
OCommandSQL command = new OCommandSQL(format(DeleteQuery, eType));
Map<String, Object> params = new HashMap<String, Object>();
params.put(Fields.Id, id);
return db.command(command).execute(params);
}
use of com.bluenimble.platform.db.DatabaseException in project serverless by bluenimble.
the class QueryEntitySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
String serializer = (String) request.get(CommonSpec.Serializer);
String[] levels = Lang.split(serializer, Lang.COMMA);
int allStopLevel = 2;
if (levels != null && levels.length > 0) {
try {
allStopLevel = Integer.valueOf(levels[0]);
} catch (Exception ex) {
}
}
int minStopLevel = 3;
if (levels != null && levels.length > 0) {
try {
minStopLevel = Integer.valueOf(levels[1]);
} catch (Exception ex) {
}
}
JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
payload.set(Database.Fields.Entity, sEntity);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
List<DatabaseObject> records = null;
try {
Database db = space.feature(Database.class, provider, request);
records = db.find(null, new JsonQuery(payload), null);
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
JsonObject result = new JsonObject();
JsonArray aRecords = new JsonArray();
result.set(Output.Records, aRecords);
if (records == null || records.isEmpty()) {
return new JsonApiOutput(result);
}
for (int i = 0; i < records.size(); i++) {
aRecords.add(records.get(i).toJson(new DefaultDatabaseObjectSerializer(allStopLevel, minStopLevel)));
}
return new JsonApiOutput(result);
}
Aggregations