/** * Gets the all prepared queries. * * @param userName the user name * @param queryName the query name * @param fromDate the from date * @param toDate the to date * @return the all prepared queries */ public List<QueryPrepareHandle> getAllPreparedQueries(String userName, String queryName, String fromDate, String toDate) { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); return target.queryParam("sessionid", connection.getSessionHandle()) .queryParam("user", userName).queryParam("queryName", queryName).queryParam("fromDate", fromDate) .queryParam("toDate", toDate).request().get(new GenericType<List<QueryPrepareHandle>>() {}); }
/** * Gets the all prepared queries. * * @param userName the user name * @param queryName the query name * @param fromDate the from date * @param toDate the to date * @return the all prepared queries */ public List<QueryPrepareHandle> getAllPreparedQueries(String userName, String queryName, String fromDate, String toDate) { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); return target.queryParam("sessionid", connection.getSessionHandle()) .queryParam("user", userName).queryParam("queryName", queryName).queryParam("fromDate", fromDate) .queryParam("toDate", toDate).request().get(new GenericType<List<QueryPrepareHandle>>() {}); }
/** * Gets the prepared query. * * @param handle the handle * @return the prepared query */ public LensPreparedQuery getPreparedQuery(QueryPrepareHandle handle) { try { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget((client)); return target.path(handle.toString()).queryParam("sessionid", connection.getSessionHandle()).request() .get(LensPreparedQuery.class); } catch (Exception e) { log.error("Failed to get prepared query, cause:", e); throw new IllegalStateException("Failed to get prepared query, cause:" + e.getMessage()); } }
/** * Gets the prepared query. * * @param handle the handle * @return the prepared query */ public LensPreparedQuery getPreparedQuery(QueryPrepareHandle handle) { try { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget((client)); return target.path(handle.toString()).queryParam("sessionid", connection.getSessionHandle()).request() .get(LensPreparedQuery.class); } catch (Exception e) { log.error("Failed to get prepared query, cause:", e); throw new IllegalStateException("Failed to get prepared query, cause:" + e.getMessage()); } }
/** * Prepare query. * * @param sql the sql * @param queryName the query name * @return the query prepare handle * @throws LensAPIException */ public LensAPIResult<QueryPrepareHandle> prepareQuery(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post(Entity.entity(prepareForm(sql, "PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPrepareHandle>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
/** * Prepare query. * * @param sql the sql * @param queryName the query name * @return the query prepare handle * @throws LensAPIException */ public LensAPIResult<QueryPrepareHandle> prepareQuery(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post(Entity.entity(prepareForm(sql, "PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPrepareHandle>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
/** * Explain and prepare. * * @param sql the sql * @param queryName the query name * @param conf config to be used for the query * @return the query plan * @throws LensAPIException */ public LensAPIResult<QueryPlan> explainAndPrepare(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post( Entity.entity(prepareForm(sql, "EXPLAIN_AND_PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE), Response.class); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPlan>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
/** * Explain and prepare. * * @param sql the sql * @param queryName the query name * @param conf config to be used for the query * @return the query plan * @throws LensAPIException */ public LensAPIResult<QueryPlan> explainAndPrepare(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post( Entity.entity(prepareForm(sql, "EXPLAIN_AND_PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE), Response.class); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPlan>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
/** * Destroy prepared. * * @param phandle the phandle * @return true, if successful */ public boolean destroyPrepared(QueryPrepareHandle phandle) { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); APIResult result = target.path(phandle.toString()).queryParam("sessionid", connection.getSessionHandle()).request() .delete(APIResult.class); return result.getStatus() == APIResult.Status.SUCCEEDED; }
/** * Destroy prepared. * * @param phandle the phandle * @return true, if successful */ public boolean destroyPrepared(QueryPrepareHandle phandle) { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); APIResult result = target.path(phandle.toString()).queryParam("sessionid", connection.getSessionHandle()).request() .delete(APIResult.class); return result.getStatus() == APIResult.Status.SUCCEEDED; }
/** * Execute query. * * @param phandle the phandle * @param queryName the query name * @param conf config to be used for the query * @return the query handle */ private QueryHandle submitQuery(QueryPrepareHandle phandle, String queryName, LensConf conf) { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be " + "established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget((client)).path(phandle.toString()); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection .getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), queryName == null ? "" : queryName)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, MediaType.APPLICATION_XML_TYPE)); QueryHandle handle = target.request() .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class); this.query = new ProxyLensQuery(this, handle); return handle; }
/** * Execute query. * * @param phandle the phandle * @param queryName the query name * @param conf config to be used for the query * @return the query handle */ private QueryHandle submitQuery(QueryPrepareHandle phandle, String queryName, LensConf conf) { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be " + "established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget((client)).path(phandle.toString()); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection .getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), queryName == null ? "" : queryName)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, MediaType.APPLICATION_XML_TYPE)); QueryHandle handle = target.request() .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class); this.query = new ProxyLensQuery(this, handle); return handle; }