<commit_before>package com.github.ricardobaumann.security;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import javax.inject.Inject;

import org.hibernate.SessionFactory;
import org.joda.time.DateTime;

import com.github.ricardobaumann.db.AccessToken;
import com.github.ricardobaumann.db.User;

import io.dropwizard.hibernate.AbstractDAO;

public class AccessTokenDAO extends AbstractDAO<AccessToken>{

    private SessionFactory sessionFactory;

    @Inject
    public AccessTokenDAO(SessionFactory sessionFactory) {
        super(sessionFactory);
        this.sessionFactory = sessionFactory;
    }

    private static Map<String, AccessToken> accessTokenTable = new HashMap<>();

    public Optional<AccessToken> findAccessTokenById(final UUID accessTokenId) {
        AccessToken accessToken = accessTokenTable.get(accessTokenId);
        if (accessToken == null) {
           
            accessToken = sessionFactory.openSession().get(AccessToken.class,accessTokenId.toString());
            if (accessToken==null) {
                return Optional.empty();
            }
            accessTokenTable.put(accessToken.getAccessTokenId(), accessToken);
        }
        return Optional.of(accessToken);
    }

    public AccessToken generateNewAccessToken(final User user, final DateTime dateTime) {
        AccessToken accessToken = new AccessToken(UUID.randomUUID().toString(), user.getId(), dateTime);
        accessTokenTable.put(accessToken.getAccessTokenId(), accessToken);
        persist(accessToken);
        return accessToken;
    }

    public void setLastAccessTime(final UUID accessTokenUUID, final DateTime dateTime) {
        AccessToken accessToken = accessTokenTable.get(accessTokenUUID);
        AccessToken updatedAccessToken = accessToken.withLastAccessUTC(dateTime);
        persist(updatedAccessToken);
        accessTokenTable.put(accessTokenUUID.toString(), updatedAccessToken);
    }

}
<commit_msg>changing token access<commit_after>package com.github.ricardobaumann.security;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import javax.inject.Inject;

import org.hibernate.SessionFactory;
import org.joda.time.DateTime;

import com.github.ricardobaumann.db.AccessToken;
import com.github.ricardobaumann.db.User;

import io.dropwizard.hibernate.AbstractDAO;

public class AccessTokenDAO extends AbstractDAO<AccessToken>{

    private SessionFactory sessionFactory;

    @Inject
    public AccessTokenDAO(SessionFactory sessionFactory) {
        super(sessionFactory);
        this.sessionFactory = sessionFactory;
    }

    private static Map<String, AccessToken> accessTokenTable = new HashMap<>();

    public Optional<AccessToken> findAccessTokenById(final UUID accessTokenId) {
        String key = accessTokenId.toString();
        System.out.println("fetching key: "+key);
        AccessToken accessToken = accessTokenTable.get(accessTokenId.toString());
        if (accessToken == null) {
           
            accessToken = sessionFactory.openSession().get(AccessToken.class,accessTokenId.toString());
            if (accessToken==null) {
                return Optional.empty();
            }
            accessTokenTable.put(accessToken.getAccessTokenId(), accessToken);
        }
        return Optional.of(accessToken);
    }

    public AccessToken generateNewAccessToken(final User user, final DateTime dateTime) {
        AccessToken accessToken = new AccessToken(UUID.randomUUID().toString(), user.getId(), dateTime);
        accessTokenTable.put(accessToken.getAccessTokenId(), accessToken);
        persist(accessToken);
        currentSession().flush();
        return accessToken;
    }

    public void setLastAccessTime(final UUID accessTokenUUID, final DateTime dateTime) {
        AccessToken accessToken = accessTokenTable.get(accessTokenUUID.toString());
        if (accessToken==null) {
            accessToken = sessionFactory.openSession().get(AccessToken.class,accessTokenUUID.toString());
            
        }
        AccessToken updatedAccessToken = accessToken.withLastAccessUTC(dateTime);
        persist(updatedAccessToken);
        currentSession().flush();
        accessTokenTable.put(accessTokenUUID.toString(), updatedAccessToken);
    }

}

{'fraction_non_alphanumeric': 0.09410404624277456, 'fraction_numerical': 0.0, 'mean_word_length': 3.6366559485530545, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2277305', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1130, 'n_words': 216}