JcrWorkspace implements org.modeshape.jcr.api.Workspace { @Override public JcrQueryManager getQueryManager() throws RepositoryException { session.checkLive(); if (this.queryManager == null) { try { lock.lock(); if (queryManager == null) queryManager = new JcrQueryManager(session); } finally { lock.unlock(); } } return queryManager; } JcrWorkspace( JcrSession session,
                  String workspaceName ); @Override final JcrSession getSession(); @Override final String getName(); @Override void copy( String srcAbsPath,
                      String destAbsPath ); @Override void copy( String srcWorkspace,
                      String srcAbsPath,
                      String destAbsPath ); @Override void clone( String srcWorkspace,
                       String srcAbsPath,
                       String destAbsPath,
                       boolean removeExisting ); @Override void move( String srcAbsPath,
                      String destAbsPath ); @Override @SuppressWarnings("deprecation") void restore( Version[] versions,
                         boolean removeExisting ); @Override JcrLockManager getLockManager(); @Override JcrQueryManager getQueryManager(); @Override javax.jcr.NamespaceRegistry getNamespaceRegistry(); @Override IndexManager getIndexManager(); @Override JcrNodeTypeManager getNodeTypeManager(); @Override ObservationManager getObservationManager(); @Override JcrVersionManager getVersionManager(); @Override JcrRepositoryManager getRepositoryManager(); @Override ContentHandler getImportContentHandler( String parentAbsPath,
                                                   int uuidBehavior ); @Override void importXML( String parentAbsPath,
                           InputStream in,
                           int uuidBehavior ); @Override String[] getAccessibleWorkspaceNames(); @Override void createWorkspace( String name ); @Override void createWorkspace( String name,
                                 String srcWorkspace ); @Override void deleteWorkspace( String name ); @Override void reindex(); @Override void reindex( String pathStr ); @Override void reindexSince( long timestamp ); @Override Future<Boolean> reindexSinceAsync( long timestamp ); @Override Future<Boolean> reindexAsync(); @Override Future<Boolean> reindexAsync( String pathStr ); @Override FederationManager getFederationManager();  }
@Test public void shouldProvideQueryManager() throws Exception { assertThat(workspace.getQueryManager(), notNullValue()); }
@Test public void shouldCreateQuery() throws Exception { String statement = "SELECT * FROM [nt:unstructured]"; QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.JCR_SQL2); assertThat(query, is(notNullValue())); assertThat(query.getLanguage(), is(Query.JCR_SQL2)); assertThat(query.getStatement(), is(statement)); }
@Test public void shouldLoadStoredQuery() throws Exception { String statement = "SELECT * FROM [nt:unstructured]"; QueryManager queryManager = workspace.getQueryManager(); Query query = queryManager.createQuery(statement, Query.JCR_SQL2); Node node = query.storeAsNode("/storedQuery"); Query loaded = queryManager.getQuery(node); assertThat(loaded, is(notNullValue())); assertThat(loaded.getLanguage(), is(Query.JCR_SQL2)); assertThat(loaded.getStatement(), is(statement)); assertThat(loaded.getStoredQueryPath(), is(node.getPath())); }