test_class.declarator: ds
test_class.modifier: public static
test_class.original_string: public static DataSource ds;
test_class.type: DataSource
test_class.var_name: ds
test_class.declarator: session
test_class.modifier: private static
test_class.original_string: private static Session session;
test_class.type: Session
test_class.var_name: session
test_class.declarator: sessionConfig = (SessionConfig)SingletonServiceFactory.getBean(SessionConfig.class)
test_class.modifier: private static
test_class.original_string: private static SessionConfig sessionConfig = (SessionConfig)SingletonServiceFactory.getBean(SessionConfig.class);
test_class.type: SessionConfig
test_class.var_name: sessionConfig
test_class.declarator: sessionRepository = (SessionRepository)SingletonServiceFactory.getBean(SessionRepository.class)
test_class.modifier: private static
test_class.original_string: private static SessionRepository sessionRepository = (SessionRepository)SingletonServiceFactory.getBean(SessionRepository.class);
test_class.type: SessionRepository
test_class.var_name: sessionRepository
test_class.file: jdbc-manager/src/test/java/com/networknt/session/jdbc/JdbcSessionRepositoryTest.java
test_class.identifier: JdbcSessionRepositoryTest
test_case.body: @Test
      public void testSave() {
          session = sessionRepository.createSession();
  
      }
test_case.class_method_signature: JdbcSessionRepositoryTest.testSave()
test_case.full_signature: @Test public void testSave()
test_case.identifier: testSave
test_case.invocations: createSession
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSave()
focal_class.declarator: CREATE_SESSION_QUERY =
              "INSERT INTO light_session(SESSION_ID, CREATION_TIME, LAST_ACCESS_TIME, MAX_INACTIVE_INTERVAL, EXPIRY_TIME, PRINCIPAL_NAME) " +
                      "VALUES (?, ?, ?, ?, ?, ?)"
focal_class.modifier: private static final
focal_class.original_string: private static final String CREATE_SESSION_QUERY =
              "INSERT INTO light_session(SESSION_ID, CREATION_TIME, LAST_ACCESS_TIME, MAX_INACTIVE_INTERVAL, EXPIRY_TIME, PRINCIPAL_NAME) " +
                      "VALUES (?, ?, ?, ?, ?, ?)";
focal_class.type: String
focal_class.var_name: CREATE_SESSION_QUERY
focal_class.declarator: CREATE_SESSION_ATTRIBUTE_QUERY =
              "INSERT INTO light_session_attributes(SESSION_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) " +
                      "VALUES (?, ?, ?)"
focal_class.modifier: private static final
focal_class.original_string: private static final String CREATE_SESSION_ATTRIBUTE_QUERY =
              "INSERT INTO light_session_attributes(SESSION_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) " +
                      "VALUES (?, ?, ?)";
focal_class.type: String
focal_class.var_name: CREATE_SESSION_ATTRIBUTE_QUERY
focal_class.declarator: GET_SESSION_QUERY =
              "SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.SESSION_ID = SA.SESSION_ID " +
                      "WHERE S.SESSION_ID = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String GET_SESSION_QUERY =
              "SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.SESSION_ID = SA.SESSION_ID " +
                      "WHERE S.SESSION_ID = ?";
focal_class.type: String
focal_class.var_name: GET_SESSION_QUERY
focal_class.declarator: GET_ALL_SESSION_QUERY =
              "SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.SESSION_ID = SA.SESSION_ID " +
                      "WHERE EXPIRY_TIME > ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String GET_ALL_SESSION_QUERY =
              "SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.SESSION_ID = SA.SESSION_ID " +
                      "WHERE EXPIRY_TIME > ?";
focal_class.type: String
focal_class.var_name: GET_ALL_SESSION_QUERY
focal_class.declarator: UPDATE_SESSION_QUERY =
              "UPDATE light_session SET SESSION_ID = ?, LAST_ACCESS_TIME = ?, MAX_INACTIVE_INTERVAL = ?, EXPIRY_TIME = ?, PRINCIPAL_NAME = ? " +
                      "WHERE SESSION_ID = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String UPDATE_SESSION_QUERY =
              "UPDATE light_session SET SESSION_ID = ?, LAST_ACCESS_TIME = ?, MAX_INACTIVE_INTERVAL = ?, EXPIRY_TIME = ?, PRINCIPAL_NAME = ? " +
                      "WHERE SESSION_ID = ?";
focal_class.type: String
focal_class.var_name: UPDATE_SESSION_QUERY
focal_class.declarator: UPDATE_SESSION_ACCESS_TIME_QUERY =
              "UPDATE light_session SET  LAST_ACCESS_TIME = ? " +
                      "WHERE SESSION_ID = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String UPDATE_SESSION_ACCESS_TIME_QUERY =
              "UPDATE light_session SET  LAST_ACCESS_TIME = ? " +
                      "WHERE SESSION_ID = ?";
focal_class.type: String
focal_class.var_name: UPDATE_SESSION_ACCESS_TIME_QUERY
focal_class.declarator: UPDATE_SESSION_ATTRIBUTE_QUERY =
              "UPDATE light_session_attributes SET ATTRIBUTE_BYTES = ? " +
                      "WHERE SESSION_ID = ? " +
                      "AND ATTRIBUTE_NAME = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String UPDATE_SESSION_ATTRIBUTE_QUERY =
              "UPDATE light_session_attributes SET ATTRIBUTE_BYTES = ? " +
                      "WHERE SESSION_ID = ? " +
                      "AND ATTRIBUTE_NAME = ?";
focal_class.type: String
focal_class.var_name: UPDATE_SESSION_ATTRIBUTE_QUERY
focal_class.declarator: DELETE_SESSION_ATTRIBUTE_QUERY =
              "DELETE FROM light_session_attributes " +
                      "WHERE SESSION_ID = ? " +
                      "AND ATTRIBUTE_NAME = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String DELETE_SESSION_ATTRIBUTE_QUERY =
              "DELETE FROM light_session_attributes " +
                      "WHERE SESSION_ID = ? " +
                      "AND ATTRIBUTE_NAME = ?";
focal_class.type: String
focal_class.var_name: DELETE_SESSION_ATTRIBUTE_QUERY
focal_class.declarator: DELETE_SESSION_QUERY =
              "DELETE FROM light_session " +
                      "WHERE SESSION_ID = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String DELETE_SESSION_QUERY =
              "DELETE FROM light_session " +
                      "WHERE SESSION_ID = ?";
focal_class.type: String
focal_class.var_name: DELETE_SESSION_QUERY
focal_class.declarator: LIST_SESSIONS_BY_PRINCIPAL_NAME_QUERY =
              "SELECT S.PRIMARY_ID, S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.PRIMARY_ID = SA.SESSION_PRIMARY_ID " +
                      "WHERE S.PRINCIPAL_NAME = ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String LIST_SESSIONS_BY_PRINCIPAL_NAME_QUERY =
              "SELECT S.PRIMARY_ID, S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES " +
                      "FROM light_session S " +
                      "LEFT OUTER JOIN light_session_attributes SA ON S.PRIMARY_ID = SA.SESSION_PRIMARY_ID " +
                      "WHERE S.PRINCIPAL_NAME = ?";
focal_class.type: String
focal_class.var_name: LIST_SESSIONS_BY_PRINCIPAL_NAME_QUERY
focal_class.declarator: DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY =
              "DELETE FROM light_session " +
                      "WHERE EXPIRY_TIME < ?"
focal_class.modifier: private static final
focal_class.original_string: private static final String DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY =
              "DELETE FROM light_session " +
                      "WHERE EXPIRY_TIME < ?";
focal_class.type: String
focal_class.var_name: DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY
focal_class.declarator: logger = LoggerFactory.getLogger(JdbcSessionRepository.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(JdbcSessionRepository.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: createSessionQuery
focal_class.modifier: private
focal_class.original_string: private String createSessionQuery;
focal_class.type: String
focal_class.var_name: createSessionQuery
focal_class.declarator: createSessionAttributeQuery
focal_class.modifier: private
focal_class.original_string: private String createSessionAttributeQuery;
focal_class.type: String
focal_class.var_name: createSessionAttributeQuery
focal_class.declarator: getSessionQuery
focal_class.modifier: private
focal_class.original_string: private String getSessionQuery;
focal_class.type: String
focal_class.var_name: getSessionQuery
focal_class.declarator: getAllSessionQuery
focal_class.modifier: private
focal_class.original_string: private String getAllSessionQuery;
focal_class.type: String
focal_class.var_name: getAllSessionQuery
focal_class.declarator: updateSessionQuery
focal_class.modifier: private
focal_class.original_string: private String updateSessionQuery;
focal_class.type: String
focal_class.var_name: updateSessionQuery
focal_class.declarator: updateSessionAttributeQuery
focal_class.modifier: private
focal_class.original_string: private String updateSessionAttributeQuery;
focal_class.type: String
focal_class.var_name: updateSessionAttributeQuery
focal_class.declarator: deleteSessionAttributeQuery
focal_class.modifier: private
focal_class.original_string: private String deleteSessionAttributeQuery;
focal_class.type: String
focal_class.var_name: deleteSessionAttributeQuery
focal_class.declarator: deleteSessionQuery
focal_class.modifier: private
focal_class.original_string: private String deleteSessionQuery;
focal_class.type: String
focal_class.var_name: deleteSessionQuery
focal_class.declarator: listSessionsByPrincipalNameQuery
focal_class.modifier: private
focal_class.original_string: private String listSessionsByPrincipalNameQuery;
focal_class.type: String
focal_class.var_name: listSessionsByPrincipalNameQuery
focal_class.declarator: deleteSessionsByExpiryTimeQuery
focal_class.modifier: private
focal_class.original_string: private String deleteSessionsByExpiryTimeQuery;
focal_class.type: String
focal_class.var_name: deleteSessionsByExpiryTimeQuery
focal_class.declarator: defaultMaxInactiveInterval = 30 * 60
focal_class.modifier: private
focal_class.original_string: private Integer defaultMaxInactiveInterval = 30 * 60;
focal_class.type: Integer
focal_class.var_name: defaultMaxInactiveInterval
focal_class.declarator: startTime
focal_class.modifier: private volatile
focal_class.original_string: private volatile long startTime;
focal_class.type: long
focal_class.var_name: startTime
focal_class.declarator: converter = new ValueBytesConverter()
focal_class.modifier: private
focal_class.original_string: private ValueBytesConverter converter = new ValueBytesConverter();
focal_class.type: ValueBytesConverter
focal_class.var_name: converter
focal_class.declarator: dataSource
focal_class.modifier: private
focal_class.original_string: private DataSource dataSource;
focal_class.type: DataSource
focal_class.var_name: dataSource
focal_class.file: jdbc-manager/src/main/java/com/networknt/session/jdbc/JdbcSessionRepository.java
focal_class.identifier: JdbcSessionRepository
focal_class.interfaces: implements
          SessionRepository<JdbcSessionRepository.JdbcSession>
focal_class.class_method_signature: JdbcSessionRepository.JdbcSessionRepository(DataSource dataSource)
focal_class.full_signature: public  JdbcSessionRepository(DataSource dataSource)
focal_class.identifier: JdbcSessionRepository
focal_class.modifiers: public
focal_class.parameters: (DataSource dataSource)
focal_class.signature:  JdbcSessionRepository(DataSource dataSource)
focal_class.class_method_signature: JdbcSessionRepository.setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
focal_class.full_signature: public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
focal_class.identifier: setDefaultMaxInactiveInterval
focal_class.modifiers: public
focal_class.parameters: (int defaultMaxInactiveInterval)
focal_class.return: void
focal_class.signature: void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
focal_class.class_method_signature: JdbcSessionRepository.createSession()
focal_class.full_signature: @Override public JdbcSession createSession()
focal_class.identifier: createSession
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: JdbcSession
focal_class.signature: JdbcSession createSession()
focal_class.class_method_signature: JdbcSessionRepository.getSessions()
focal_class.full_signature: public Map<String, Session> getSessions()
focal_class.identifier: getSessions
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Map<String, Session>
focal_class.signature: Map<String, Session> getSessions()
focal_class.class_method_signature: JdbcSessionRepository.save(JdbcSession session)
focal_class.full_signature: @Override public void save(JdbcSession session)
focal_class.identifier: save
focal_class.modifiers: @Override public
focal_class.parameters: (JdbcSession session)
focal_class.return: void
focal_class.signature: void save(JdbcSession session)
focal_class.class_method_signature: JdbcSessionRepository.findById(final String id)
focal_class.full_signature: @Override public JdbcSession findById(final String id)
focal_class.identifier: findById
focal_class.modifiers: @Override public
focal_class.parameters: (final String id)
focal_class.return: JdbcSession
focal_class.signature: JdbcSession findById(final String id)
focal_class.class_method_signature: JdbcSessionRepository.deleteById(final String id)
focal_class.full_signature: @Override public void deleteById(final String id)
focal_class.identifier: deleteById
focal_class.modifiers: @Override public
focal_class.parameters: (final String id)
focal_class.return: void
focal_class.signature: void deleteById(final String id)
focal_class.class_method_signature: JdbcSessionRepository.cleanUpExpiredSessions()
focal_class.full_signature: public void cleanUpExpiredSessions()
focal_class.identifier: cleanUpExpiredSessions
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void cleanUpExpiredSessions()
focal_class.class_method_signature: JdbcSessionRepository.updateSessionLastAccessTime(final String id)
focal_class.full_signature: public void updateSessionLastAccessTime(final String id)
focal_class.identifier: updateSessionLastAccessTime
focal_class.modifiers: public
focal_class.parameters: (final String id)
focal_class.return: void
focal_class.signature: void updateSessionLastAccessTime(final String id)
focal_class.class_method_signature: JdbcSessionRepository.getQuery(String base)
focal_class.full_signature: private String getQuery(String base)
focal_class.identifier: getQuery
focal_class.modifiers: private
focal_class.parameters: (String base)
focal_class.return: String
focal_class.signature: String getQuery(String base)
focal_class.class_method_signature: JdbcSessionRepository.prepareQueries()
focal_class.full_signature: private void prepareQueries()
focal_class.identifier: prepareQueries
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void prepareQueries()
focal_class.class_method_signature: JdbcSessionRepository.serialize(PreparedStatement ps, int paramIndex, Object attributeValue)
focal_class.full_signature: private void serialize(PreparedStatement ps, int paramIndex, Object attributeValue)
focal_class.identifier: serialize
focal_class.modifiers: private
focal_class.parameters: (PreparedStatement ps, int paramIndex, Object attributeValue)
focal_class.return: void
focal_class.signature: void serialize(PreparedStatement ps, int paramIndex, Object attributeValue)
focal_class.class_method_signature: JdbcSessionRepository.deserialize(ResultSet rs, String columnName)
focal_class.full_signature: private Object deserialize(ResultSet rs, String columnName)
focal_class.identifier: deserialize
focal_class.modifiers: private
focal_class.parameters: (ResultSet rs, String columnName)
focal_class.return: Object
focal_class.signature: Object deserialize(ResultSet rs, String columnName)
focal_class.class_method_signature: JdbcSessionRepository.extractData(ResultSet rs)
focal_class.full_signature: public List<JdbcSession> extractData(ResultSet rs)
focal_class.identifier: extractData
focal_class.modifiers: public
focal_class.parameters: (ResultSet rs)
focal_class.return: List<JdbcSession>
focal_class.signature: List<JdbcSession> extractData(ResultSet rs)
focal_class.class_method_signature: JdbcSessionRepository.getLast(List<JdbcSession> sessions)
focal_class.full_signature: private JdbcSession getLast(List<JdbcSession> sessions)
focal_class.identifier: getLast
focal_class.modifiers: private
focal_class.parameters: (List<JdbcSession> sessions)
focal_class.return: JdbcSession
focal_class.signature: JdbcSession getLast(List<JdbcSession> sessions)
focal_method.body: @Override
      public void save(JdbcSession session) {
          if (session.isNew()) {
              try (final Connection connection = dataSource.getConnection()) {
                  connection.setAutoCommit(false);
  
                  PreparedStatement stmt = connection.prepareStatement(this.createSessionQuery);
                  stmt.setString(1, session.getId());
                  stmt.setLong(2, session.getCreationTime());
                  stmt.setLong(3, session.getLastAccessedTime());
                  stmt.setInt(4, session.getMaxInactiveInterval());
                  stmt.setLong(5, session.getExpiryTime());
                  stmt.setString(6, session.getPrincipalName());
                  int count = stmt.executeUpdate();
                  if (!session.getAttributeNames().isEmpty()) {
                      final List<String> attributeNames = new ArrayList<>(session.getAttributeNames());
                      try (PreparedStatement psAtt = connection.prepareStatement(this.createSessionAttributeQuery)) {
                          for (String attributeName : attributeNames) {
                              psAtt.setString(1, session.getId());
                              psAtt.setString(2, attributeName);
                              serialize(psAtt, 3, session.getAttribute(attributeName));
                              psAtt.addBatch();
                          }
                          psAtt.executeBatch();
                      }
                  }
                  connection.commit();
  
                  if (count != 1) {
                      logger.error("Failed to insert session: {}", session.getId());
                  }
              } catch (SQLException e) {
                  logger.error("SqlException:", e);
              }
          } else {
              try (final Connection connection = dataSource.getConnection()) {
  
                  connection.setAutoCommit(false);
                  PreparedStatement stmt = connection.prepareStatement(this.updateSessionQuery);
                  stmt.setString(1, session.getId());
                  stmt.setLong(2, session.getLastAccessedTime());
                  stmt.setInt(3, session.getMaxInactiveInterval());
                  stmt.setLong(4, session.getExpiryTime());
                  stmt.setString(5, session.getPrincipalName());
                  stmt.setString(6, session.getId());
                  int count = stmt.executeUpdate();
  
                  Map<String, Object> delta = session.getDelta();
                  if (!delta.isEmpty()) {
                      for (final Map.Entry<String, Object> entry : delta.entrySet()) {
                          if (entry.getValue() == null) {
                              try (PreparedStatement psAtt = connection.prepareStatement(this.deleteSessionAttributeQuery)) {
                                  psAtt.setString(1, session.getId());
                                  psAtt.setString(2, entry.getKey());
                                  psAtt.executeUpdate();
                              }
                          } else {
                              int updatedCount = 0;
                              try (PreparedStatement psAtt = connection.prepareStatement(this.updateSessionAttributeQuery)) {
                                  serialize(psAtt, 1, entry.getValue());
                                  psAtt.setString(2, session.getId());
                                  psAtt.setString(3, entry.getKey());
                                  updatedCount = psAtt.executeUpdate();
                              }
                              if (updatedCount == 0) {
                                  try (PreparedStatement psAtt = connection.prepareStatement(this.createSessionAttributeQuery)) {
                                      psAtt.setString(1, session.getId());
                                      psAtt.setString(2, entry.getKey());
                                      serialize(psAtt, 3, entry.getValue());
  
                                      psAtt.executeUpdate();
                                  }
                              }
  
                          }
                      }
                  }
                  connection.commit();
              } catch (SQLException e) {
                  logger.error("SqlException:", e);
              }
          }
          session.clearChangeFlags();
      }
focal_method.class_method_signature: JdbcSessionRepository.save(JdbcSession session)
focal_method.full_signature: @Override public void save(JdbcSession session)
focal_method.identifier: save
focal_method.invocations: isNew getConnection setAutoCommit prepareStatement setString getId setLong getCreationTime setLong getLastAccessedTime setInt getMaxInactiveInterval setLong getExpiryTime setString getPrincipalName executeUpdate isEmpty getAttributeNames getAttributeNames prepareStatement setString getId setString serialize getAttribute addBatch executeBatch commit error getId error getConnection setAutoCommit prepareStatement setString getId setLong getLastAccessedTime setInt getMaxInactiveInterval setLong getExpiryTime setString getPrincipalName setString getId executeUpdate getDelta isEmpty entrySet getValue prepareStatement setString getId setString getKey executeUpdate prepareStatement serialize getValue setString getId setString getKey executeUpdate prepareStatement setString getId setString getKey serialize getValue executeUpdate commit error clearChangeFlags
focal_method.modifiers: @Override public
focal_method.parameters: (JdbcSession session)
focal_method.return: void
focal_method.signature: void save(JdbcSession session)