use of io.jans.orm.sql.model.SimpleSessionState in project jans by JanssenProject.
the class SqlUpateMissingEntrySample method main.
public static void main(String[] args) {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
// Create SQL entry manager
SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
String sessionId = UUID.randomUUID().toString();
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
try {
sqlEntryManager.merge(simpleSessionState);
System.out.println("Updated");
} catch (EntryPersistenceException ex) {
LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
}
}
use of io.jans.orm.sql.model.SimpleSessionState in project jans by JanssenProject.
the class SqlConcurentSessionUpdateSample method main.
public static void main(String[] args) throws InterruptedException {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
// Create SQL entry manager
final SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
try {
String sessionId = UUID.randomUUID().toString();
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
final String userDn = "inum=@!E8F2.853B.1E7B.ACE2!0001!39A4.C163!0000!A8F2.DE1E.D7FB,ou=people,o=jans";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
sqlEntryManager.persist(simpleSessionState);
System.out.println("Persisted");
int threadCount = 500;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount, daemonThreadFactory());
for (int i = 0; i < threadCount; i++) {
final int count = i;
executorService.execute(new Runnable() {
@Override
public void run() {
final SimpleSessionState simpleSessionStateFromSQL = sqlEntryManager.find(SimpleSessionState.class, sessionDn);
String beforeUserDn = simpleSessionStateFromSQL.getUserDn();
String randomUserDn = count % 2 == 0 ? userDn : "";
try {
simpleSessionStateFromSQL.setUserDn(randomUserDn);
simpleSessionStateFromSQL.setLastUsedAt(new Date());
sqlEntryManager.merge(simpleSessionStateFromSQL);
System.out.println("Merged thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn);
} catch (Throwable e) {
System.out.println("ERROR !!!, thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn + ", error:" + e.getMessage());
// e.printStackTrace();
}
}
});
}
Thread.sleep(5000L);
} finally {
sqlEntryManager.destroy();
}
}
Aggregations