Search in sources :

Example 1 with SimpleCacheEntry

use of io.jans.orm.sql.model.SimpleCacheEntry in project jans by JanssenProject.

the class SqlUpateCacheEntrySample 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 key = UUID.randomUUID().toString();
    final String cacheDn = String.format("uuid=%s,%s", key, "ou=cache,o=gluu");
    int expirationInSeconds = 60;
    Calendar expirationDate = Calendar.getInstance();
    expirationDate.setTime(new Date());
    expirationDate.add(Calendar.SECOND, expirationInSeconds);
    SimpleCacheEntry entity = new SimpleCacheEntry();
    entity.setTtl(expirationInSeconds);
    entity.setData("sample_data");
    entity.setId(key);
    entity.setDn(cacheDn);
    entity.setCreationDate(new Date());
    entity.setExpirationDate(expirationDate.getTime());
    entity.setDeletable(true);
    sqlEntryManager.persist(entity);
    // Try to update
    sqlEntryManager.merge(entity);
    // Try to update with removed value
    entity.setData(null);
    sqlEntryManager.merge(entity);
}
Also used : SimpleCacheEntry(io.jans.orm.sql.model.SimpleCacheEntry) Calendar(java.util.Calendar) SqlEntryManagerSample(io.jans.orm.sql.persistence.SqlEntryManagerSample) SqlEntryManager(io.jans.orm.sql.impl.SqlEntryManager) Date(java.util.Date)

Aggregations

SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)1 SimpleCacheEntry (io.jans.orm.sql.model.SimpleCacheEntry)1 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1