MCPcopy Index your code
hub / github.com/apache/tomcat / save

Method save

java/org/apache/catalina/session/DataSourceStore.java:484–523  ·  view source on GitHub ↗
(Session session)

Source from the content-addressed store, hash-verified

482 }
483
484 @Override
485 public void save(Session session) throws IOException {
486 String saveSql = "INSERT INTO " + sessionTable + " (" + sessionIdCol + ", " + sessionAppCol + ", " +
487 sessionDataCol + ", " + sessionValidCol + ", " + sessionMaxInactiveCol + ", " + sessionLastAccessedCol +
488 ") VALUES (?, ?, ?, ?, ?, ?)";
489
490 synchronized (session) {
491
492 // First serialize session
493 ByteArrayOutputStream bos = new ByteArrayOutputStream();
494 try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos))) {
495 ((StandardSession) session).writeObjectData(oos);
496 }
497 byte[] obs = bos.toByteArray();
498
499 withRetry(conn -> {
500 // Remove session if it exists and insert again.
501 remove(session.getIdInternal(), conn);
502
503 int size = obs.length;
504 try (ByteArrayInputStream bis = new ByteArrayInputStream(obs, 0, size);
505 InputStream in = new BufferedInputStream(bis, size);
506 PreparedStatement preparedSaveSql = conn.prepareStatement(saveSql)) {
507 preparedSaveSql.setString(1, session.getIdInternal());
508 preparedSaveSql.setString(2, getName());
509 preparedSaveSql.setBinaryStream(3, in, size);
510 preparedSaveSql.setString(4, session.isValid() ? "1" : "0");
511 preparedSaveSql.setInt(5, session.getMaxInactiveInterval());
512 preparedSaveSql.setLong(6, session.getLastAccessedTime());
513 preparedSaveSql.execute();
514 }
515 return null;
516 });
517 }
518
519 if (manager.getContext().getLogger().isTraceEnabled()) {
520 manager.getContext().getLogger()
521 .trace(sm.getString("dataSourceStore.saving", session.getIdInternal(), sessionTable));
522 }
523 }
524
525
526 // --------------------------------------------------------- Protected Methods

Callers

nothing calls this directly

Calls 15

toByteArrayMethod · 0.95
withRetryMethod · 0.95
removeMethod · 0.95
getNameMethod · 0.95
getIdInternalMethod · 0.65
isValidMethod · 0.65
getLastAccessedTimeMethod · 0.65
executeMethod · 0.65
isTraceEnabledMethod · 0.65
getLoggerMethod · 0.65
getContextMethod · 0.65

Tested by

no test coverage detected