/** * Initialize the instance with the given configuration. * * <p>This can configure managed (DS/SCR) instances, as well as explicitly instantiated * (bootstrap) instances. * * @param config the configuration */ void init(JsonValue config) { synchronized (dbLock) { try { dbURL = getDBUrl(config); logger.info("Use DB at dbURL: {}", dbURL); user = config.get(CONFIG_USER).defaultTo("admin").asString(); password = config.get(CONFIG_PASSWORD).defaultTo("admin").asString(); poolMinSize = config.get(CONFIG_POOL_MIN_SIZE).defaultTo(DEFAULT_POOL_MIN_SIZE).asInteger(); poolMaxSize = config.get(CONFIG_POOL_MAX_SIZE).defaultTo(DEFAULT_POOL_MAX_SIZE).asInteger(); Map<String, String> queryMap = config.get(CONFIG_QUERIES).defaultTo(new HashMap<String, String>()).asMap(String.class); queries.setConfiguredQueries(queryMap); Map<String, String> commandMap = config .get(CONFIG_COMMANDS) .defaultTo(new HashMap<String, String>()) .asMap(String.class); commands.setConfiguredQueries(commandMap); } catch (RuntimeException ex) { logger.warn("Configuration invalid, can not start OrientDB repository", ex); throw ex; } try { pool = DBHelper.getPool(dbURL, user, password, poolMinSize, poolMaxSize, config, true); logger.debug("Obtained pool {}", pool); } catch (RuntimeException ex) { logger.warn("Initializing database pool failed", ex); throw ex; } } }
/** * Execute a database command according to the details in the action request. * * @param request the ActionRequest * @return the number of affected rows/records. * @throws ResourceException on failure to resolved query */ public Object command(ActionRequest request) throws ResourceException { ODatabaseDocumentTx db = getConnection(); try { return commands.query(request.getResourcePath(), request, db); } finally { if (db != null) { db.close(); } } }