Search in sources :

Example 61 with EntryPersistenceException

use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.

the class ManualSqlEntryManagerTest method testBatchJob.

@Test(dependsOnMethods = "deleteSessionId", enabled = false)
public void testBatchJob() {
    String outsideSid = UUID.randomUUID().toString();
    for (int i = 0; i < 200; i++) {
        SessionId sessionId = buildSessionId();
        sessionId.setOutsideSid(outsideSid);
        Pair<Date, Integer> expirarion = expirationDate(new Date());
        sessionId.setExpirationDate(expirarion.getFirst());
        sessionId.setTtl(expirarion.getSecond());
        manager.persist(sessionId);
    }
    totalProcessedCount = 0;
    ProcessBatchOperation<SessionId> sessionBatchOperation = new ProcessBatchOperation<SessionId>() {

        int processedCount = 0;

        @Override
        public void performAction(List<SessionId> objects) {
            for (SessionId simpleSession : objects) {
                try {
                    Calendar calendar = Calendar.getInstance();
                    Date jansLastAccessTimeDate = simpleSession.getExpirationDate();
                    calendar.setTime(jansLastAccessTimeDate);
                    calendar.add(Calendar.SECOND, -1);
                    simpleSession.setExpirationDate(calendar.getTime());
                    manager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    System.err.println("Failed to update entry: " + ex.getMessage());
                }
            }
            System.out.println("Total processed: " + processedCount);
            assertEquals(processedCount, 100);
            totalProcessedCount += processedCount;
        }
    };
    Filter filter1 = Filter.createANDFilter(Filter.createPresenceFilter("exp"), Filter.createEqualityFilter("sid", outsideSid));
    manager.findEntries("o=jans", SessionId.class, filter1, SearchScope.SUB, new String[] { "exp" }, sessionBatchOperation, 0, 500, 100);
    assertEquals(totalProcessedCount, 200);
}
Also used : Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) Calendar(java.util.Calendar) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) List(java.util.List) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)61 SearchException (io.jans.orm.exception.operation.SearchException)33 AuthenticationException (io.jans.orm.exception.AuthenticationException)31 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)30 MappingException (io.jans.orm.exception.MappingException)30 Filter (io.jans.orm.search.filter.Filter)24 AttributeData (io.jans.orm.model.AttributeData)16 DateTimeParseException (java.time.format.DateTimeParseException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)13 ParsedKey (io.jans.orm.impl.model.ParsedKey)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)10 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)9 JsonObject (com.couchbase.client.java.document.json.JsonObject)8 ConnectionException (io.jans.orm.exception.operation.ConnectionException)8 ParseException (java.text.ParseException)8 DateTimeException (java.time.DateTimeException)7 List (java.util.List)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)6 EntryData (io.jans.orm.model.EntryData)6