use of io.jans.orm.couchbase.model.SimpleClient in project jans by JanssenProject.
the class CouchbaseBatchJobSample method main.
public static void main(String[] args) {
// Prepare sample connection details
CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
// Create Couchbase entry manager
final CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
BatchOperation<SimpleTokenCouchbase> tokenCouchbaseBatchOperation = new ProcessBatchOperation<SimpleTokenCouchbase>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleTokenCouchbase> objects) {
for (SimpleTokenCouchbase simpleTokenCouchbase : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(couchbaseEntryManager, simpleTokenCouchbase.getDn(), "exp", simpleTokenCouchbase.getAttribute("exp"));
simpleTokenCouchbase.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
couchbaseEntryManager.merge(simpleTokenCouchbase);
processedCount++;
} catch (EntryPersistenceException ex) {
LOG.error("Failed to update entry", ex);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter1 = Filter.createPresenceFilter("exp");
couchbaseEntryManager.findEntries("o=jans", SimpleTokenCouchbase.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenCouchbaseBatchOperation, 0, 0, 100);
BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleSession> objects) {
for (SimpleSession simpleSession : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(couchbaseEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
couchbaseEntryManager.merge(simpleSession);
processedCount++;
} catch (EntryPersistenceException ex) {
LOG.error("Failed to update entry", ex);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
couchbaseEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter3 = Filter.createPresenceFilter("exp");
List<SimpleClient> result3 = couchbaseEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
LOG.info("Result count (without collecting results): " + result3.size());
BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter4 = Filter.createPresenceFilter("exp");
List<SimpleClient> result4 = couchbaseEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
LOG.info("Result count (with collecting results): " + result4.size());
}
use of io.jans.orm.couchbase.model.SimpleClient in project jans by JanssenProject.
the class ManualCouchbaseEntryManagerTest method sample.
// manual
@Test(enabled = false)
public void sample() throws IOException {
CouchbaseEntryManager manager = createCouchbaseEntryManager();
try {
List<SimpleClient> attributeList = manager.findEntries("o=jans", SimpleClient.class, null);
System.out.println(attributeList);
} finally {
manager.destroy();
}
}
Aggregations