@Override public void delete(long id, String database) { IDatabaseCommands commands = database == null ? documentStore.getDatabaseCommands() : documentStore.getDatabaseCommands().forDatabase(database); try (HttpJsonRequest request = commands.createRequest(HttpMethods.DELETE, "/subscriptions?id=" + id)) { request.executeRequest(); } }
@SuppressWarnings("boxing") @Override public void release(long id, String database) { IDatabaseCommands commands = database == null ? documentStore.getDatabaseCommands() : documentStore.getDatabaseCommands().forDatabase(database); try (HttpJsonRequest request = commands.createRequest( HttpMethods.POST, String.format("/subscriptions/close?id=%d&connection=&force=true", id))) { request.executeRequest(); } }
@Override public List<SubscriptionConfig> getSubscriptions(int start, int take, String database) { IDatabaseCommands commands = database == null ? documentStore.getDatabaseCommands() : documentStore.getDatabaseCommands().forDatabase(database); try (HttpJsonRequest request = commands.createRequest(HttpMethods.GET, "/subscriptions")) { RavenJToken response = request.readResponseJson(); SubscriptionConfig[] subscriptionConfigs = documentStore .getConventions() .createSerializer() .deserialize(response, SubscriptionConfig[].class); return Arrays.asList(subscriptionConfigs); } }
@SuppressWarnings("boxing") @Override public long create(SubscriptionCriteria criteria, String database) { if (criteria == null) { throw new IllegalArgumentException("Cannot create a subscription if criteria is null"); } IDatabaseCommands commands = database == null ? documentStore.getDatabaseCommands() : documentStore.getDatabaseCommands().forDatabase(database); try (HttpJsonRequest request = commands.createRequest(HttpMethods.POST, "/subscriptions/create")) { request.write(RavenJObject.fromObject(criteria).toString()); return request.readResponseJson().value(Long.class, "Id"); } }
@SuppressWarnings("boxing") private static void sendOpenSubscriptionRequest( IDatabaseCommands commands, long id, SubscriptionConnectionOptions options) throws SubscriptionException { try (HttpJsonRequest request = commands.createRequest( HttpMethods.POST, String.format( "/subscriptions/open?id=%d&connection=%s", id, options.getConnectionId()))) { request.write(options.toRavenObject().toString()); request.executeRequest(); } catch (Exception e) { SubscriptionException subscriptionException = tryGetSubscriptionException(e); if (subscriptionException != null) { throw subscriptionException; } throw e; } }