use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class VersionTest method testGetProperties.
/**
* Tests if <code>Version.getProperties()</code> and
* <code>Version.getProperties(String)</code> return the right property
*/
public void testGetProperties() throws Exception {
PropertyIterator pi = version.getProperties();
boolean hasPropertyCreated = false;
while (pi.hasNext()) {
if (pi.nextProperty().getName().equals(jcrCreated)) {
hasPropertyCreated = true;
}
}
assertTrue("Version.getProperties() does not return property jcr:created", hasPropertyCreated);
pi = version.getProperties(superuser.getNamespacePrefix(NS_JCR_URI) + ":*");
hasPropertyCreated = false;
while (pi.hasNext()) {
if (pi.nextProperty().getName().equals(jcrCreated)) {
hasPropertyCreated = true;
}
}
assertTrue("Version.getProperties(String) does not return property jcr:created", hasPropertyCreated);
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class Dump method dump.
/**
* Dumps the given <code>Node</code> to the given <code>PrintWriter</code>
* @param out
* the <code>PrintWriter</code>
* @param n
* the <code>Node</code>
* @throws RepositoryException
*/
public void dump(PrintWriter out, Node n) throws RepositoryException {
out.println(n.getPath());
PropertyIterator pit = n.getProperties();
while (pit.hasNext()) {
Property p = pit.nextProperty();
out.print(p.getPath() + "=");
if (p.getDefinition().isMultiple()) {
Value[] values = p.getValues();
for (int i = 0; i < values.length; i++) {
if (i > 0)
out.println(",");
out.println(values[i].getString());
}
} else {
out.print(p.getString());
}
out.println();
}
NodeIterator nit = n.getNodes();
while (nit.hasNext()) {
Node cn = nit.nextNode();
dump(out, cn);
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class LsReferences method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String path = (String) ctx.get(this.pathKey);
Node n = CommandHelper.getNode(ctx, path);
// header
int[] width = new int[] { 60 };
String[] header = new String[] { bundle.getString("word.path") };
// print header
PrintHelper.printRow(ctx, width, header);
// print separator
PrintHelper.printSeparatorRow(ctx, width, '-');
PropertyIterator iter = n.getReferences();
while (iter.hasNext()) {
Property p = iter.nextProperty();
// print header
PrintHelper.printRow(ctx, width, new String[] { p.getPath() });
}
CommandHelper.getOutput(ctx).println();
CommandHelper.getOutput(ctx).println(iter.getSize() + " " + bundle.getString("word.references"));
return false;
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class ConcurrentReadRandomNodeAndItsPropertiesTest method randomRead.
protected void randomRead(Session testSession, List<String> allPaths, int cnt) throws RepositoryException {
boolean logout = false;
if (testSession == null) {
testSession = getTestSession();
logout = true;
}
try {
int nodeCnt = 0;
int propertyCnt = 0;
int noAccess = 0;
int size = allPaths.size();
long start = System.currentTimeMillis();
for (int i = 0; i < cnt; i++) {
double rand = size * Math.random();
int index = (int) Math.floor(rand);
String path = allPaths.get(index);
if (testSession.itemExists(path)) {
Item item = testSession.getItem(path);
if (item.isNode()) {
nodeCnt++;
Node n = (Node) item;
PropertyIterator it = n.getProperties();
while (it.hasNext()) {
Property p = it.nextProperty();
propertyCnt++;
}
}
} else {
noAccess++;
}
}
long end = System.currentTimeMillis();
if (doReport) {
System.out.println("Session " + testSession.getUserID() + " reading " + (cnt - noAccess) + " (Nodes: " + nodeCnt + "; Properties: " + propertyCnt + ") completed in " + (end - start));
}
} finally {
if (logout) {
logout(testSession);
}
}
}
use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.
the class ConcurrentReadIT method concurrentPropertyIteration.
@Test
public void concurrentPropertyIteration() throws RepositoryException, InterruptedException, ExecutionException {
final Session session = createAdminSession();
try {
final Node testRoot = session.getRootNode().addNode("test-root");
for (int k = 0; k < 50; k++) {
testRoot.setProperty("p" + k, k);
}
session.save();
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
List<ListenableFuture<?>> futures = Lists.newArrayList();
for (int k = 0; k < 20; k++) {
futures.add(executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int k = 0; k < 100000; k++) {
session.refresh(false);
PropertyIterator properties = testRoot.getProperties();
properties.hasNext();
}
return null;
}
}));
}
// Throws ExecutionException if any of the submitted task failed
Futures.allAsList(futures).get();
executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.DAYS);
} finally {
session.logout();
}
}
Aggregations