Source:
public void save(CassandraHttpSession session) { Map<String, String> serializedAttributes = this.sessionAttributeSerializer.convert(session); Insert insert = QueryBuilder.insertInto("session") .value("id", UUID.fromString(session.getId())) .value("creation_time", session.getCreationTime()) .value("last_accessed", session.getLastAccessedTime()) .value("max_inactive_interval_in_seconds", session.getMaxInactiveIntervalInSeconds()) .value("attributes", serializedAttributes); TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - session.getLastAccessedTime()); try { int ttl = this.ttlCalculator.calculateTtlInSeconds(System.currentTimeMillis(), session); insert.using(QueryBuilder.ttl(ttl)); } catch (IllegalArgumentException e) { log.info("Session has already expired, skipping save"); return; } BatchStatement batch = new BatchStatement(); batch.add(insert); String savedPrincipalName = session.getSavedPrincipalName(); String currentPrincipalName = session.getCurrentPrincipalName(); boolean shouldDeleteIdx = savedPrincipalName != null && !savedPrincipalName.equals(currentPrincipalName); boolean shouldInsertIdx = currentPrincipalName != null; if (shouldDeleteIdx) { Statement idxDelete = QueryBuilder.delete().from("session_by_name") .where(QueryBuilder.eq("principal_name", savedPrincipalName)); batch.add(idxDelete); } if (shouldInsertIdx) { Insert idxInsert = QueryBuilder.insertInto("session_by_name") .value("id", UUID.fromString(session.getId())) .value("principal_name", currentPrincipalName); idxInsert.using(QueryBuilder.ttl(session.getMaxInactiveIntervalInSeconds())); batch.add(idxInsert); } this.template.execute(batch); session.onSave(); }

Target:
public void save(CassandraHttpSession session) { int ttl; try { ttl = this.ttlCalculator.calculateTtlInSeconds(System.currentTimeMillis(), session); } catch (IllegalArgumentException e) { log.info("Session has already expired, skipping save"); return; } Map<String, String> serializedAttributes = this.sessionAttributeSerializer.convert(session); Insert insert = QueryBuilder.insertInto(this.tableName) .value("id", UUID.fromString(session.getId())) .value("creation_time", session.getCreationTime()) .value("last_accessed", session.getLastAccessedTime()) .value("max_inactive_interval_in_seconds", session.getMaxInactiveIntervalInSeconds()) .value("attributes", serializedAttributes); insert.using(QueryBuilder.ttl(ttl)); BatchStatement batch = new BatchStatement(); batch.setConsistencyLevel(this.consistencyLevel); batch.add(insert); String savedPrincipalName = session.getSavedPrincipalName(); String currentPrincipalName = session.getCurrentPrincipalName(); boolean shouldDeleteIdx = savedPrincipalName != null && !savedPrincipalName.equals(currentPrincipalName); boolean shouldInsertIdx = currentPrincipalName != null; if (shouldDeleteIdx) { Statement idxDelete = QueryBuilder.delete().from(this.getIndexTableName()) .where(QueryBuilder.eq("principal_name", savedPrincipalName)); batch.add(idxDelete); } if (shouldInsertIdx) { Insert idxInsert = QueryBuilder.insertInto(this.getIndexTableName()) .value("id", UUID.fromString(session.getId())) .value("principal_name", currentPrincipalName); idxInsert.using(QueryBuilder.ttl(session.getMaxInactiveIntervalInSeconds())); batch.add(idxInsert); } this.cassandraOperations.execute(batch); session.onSave(); }