private void exportApplicationsForOrg(Entry<UUID, String> orgIdAndName, String queryString) throws Exception { LOG.info("organization: {} / {}", orgIdAndName.getValue(), orgIdAndName.getKey()); String orgName = orgIdAndName.getValue(); BiMap<UUID, String> applications = managementService.getApplicationsForOrganization(orgIdAndName.getKey()); for (Entry<UUID, String> appIdAndName : applications.entrySet()) { String appName = appIdAndName.getValue(); appName = appName.substring(appName.indexOf('/') + 1); LOG.info("application {} / {}", appName, appIdAndName.getKey()); EntityManager em = emf.getEntityManager(appIdAndName.getKey()); Map<String, String[]> cfm = getCollectionFieldMap(); // Loop through the collections of the Application Set<String> collections = em.getApplicationCollections(); for (String collectionName : collections) { // set up for retrieving only the necessary properties String entityType = InflectionUtils.singularize(collectionName); String[] props = cfm.get(entityType); Collection<String> properties = new ArrayList<String>(BASE_ATTRIBUTES.length + (props != null ? props.length : 0)); properties.addAll(Arrays.asList(BASE_ATTRIBUTES)); if (props != null) { properties.addAll(Arrays.asList(props)); } Query query = Query.fromQL(queryString); query.setLimit(MAX_ENTITY_FETCH); query.setResultsLevel(Level.REFS); Results results = em.searchCollection(em.getApplicationRef(), collectionName, query); while (results.size() > 0) { List<Entity> entities = em.getPartialEntities(results.getIds(), properties); for (Entity entity : entities) { write(orgName, appName, entity, em); } if (results.getCursor() == null) { break; } query.setCursor(results.getCursor()); results = em.searchCollection(em.getApplicationRef(), collectionName, query); } } } }
@Test public void badOperand() throws QueryParseException { // from isn't allowed String s = "select * where name != 'bob'"; String error = null; try { Query.fromQL(s); fail("should throw an exception"); } catch (RuntimeException qpe) { error = qpe.getMessage(); } assertEquals( "NoViableAltException('!'@[1:1: Tokens : ( T__31 | T__32 | T__33 | T__34 | T__35 | T__36 | T__37 | T__38 | T__39 | T__40 | LT | LTE | EQ | GT | GTE | BOOLEAN | AND | OR | NOT | ASC | DESC | CONTAINS | WITHIN | OF | UUID | ID | LONG | FLOAT | STRING | WS );])", error); }
@Test public void badOrderByGrammar() throws QueryParseException { // from isn't allowed String s = "select * where name = 'bob' order by"; String error = null; try { Query.fromQL(s); } catch (QueryParseException qpe) { error = qpe.getMessage(); } assertEquals( "The query cannot be parsed. The token '<EOF>' " + "at column 13 on line 1 cannot be parsed", error); }