Search in sources :

Example 6 with DatabaseException

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();
}
Also used : IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) DatabaseException(com.bluenimble.platform.db.DatabaseException) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport)

Example 7 with DatabaseException

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();
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) DatabaseException(com.bluenimble.platform.db.DatabaseException)

Example 8 with DatabaseException

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();
    }
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) DatabaseException(com.bluenimble.platform.db.DatabaseException)

Example 9 with DatabaseException

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JsonObject(com.bluenimble.platform.json.JsonObject) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) DatabaseException(com.bluenimble.platform.db.DatabaseException)

Example 10 with DatabaseException

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);
}
Also used : JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) JsonObject(com.bluenimble.platform.json.JsonObject) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) DatabaseException(com.bluenimble.platform.db.DatabaseException) JsonArray(com.bluenimble.platform.json.JsonArray) ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) DefaultDatabaseObjectSerializer(com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) DatabaseException(com.bluenimble.platform.db.DatabaseException) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Aggregations

DatabaseException (com.bluenimble.platform.db.DatabaseException)19 JsonObject (com.bluenimble.platform.json.JsonObject)11 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)8 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)8 ApiSpace (com.bluenimble.platform.api.ApiSpace)8 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)8 Database (com.bluenimble.platform.db.Database)8 DatabaseObject (com.bluenimble.platform.db.DatabaseObject)8 JsonArray (com.bluenimble.platform.json.JsonArray)3 IOException (java.io.IOException)3 JsonQuery (com.bluenimble.platform.db.query.impls.JsonQuery)2 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 Document (org.bson.Document)2 Field (com.bluenimble.platform.db.Database.Field)1 DefaultDatabaseObjectSerializer (com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer)1 DeleteResult (com.mongodb.client.result.DeleteResult)1 ODatabaseExport (com.orientechnologies.orient.core.db.tool.ODatabaseExport)1 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)1