<commit_before>package org.cryptonit.cloud.timestamping;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.cryptonit.cloud.ExecutionContext;
import org.cryptonit.cloud.interfaces.TimestampingPolicy;
import org.cryptonit.cloud.interfaces.TimestampingPolicyFactory;

public class PolicyFactory implements TimestampingPolicyFactory {
    ExecutionContext context;

    public PolicyFactory(ExecutionContext context) {
        this.context = context;
    }

    @Override
    public TimestampingPolicy getTimestampingPolicy(String domain) {
        TimestampingPolicy r = null;

        try {
            Connection c = context.database.getConnection();
            PreparedStatement ps = c.prepareStatement("SELECT identityId, policyId, algorithm FROM timestamping_policy WHERE domain=? and identityId is NULL");
            ps.setString(1, domain);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                r = new Policy(rs.getString(1), rs.getString(2), rs.getString(3));
            }
        } catch (Exception e) {
            // TODO: Log error
        }

        return r;
    }

    @Override
    public TimestampingPolicy getTimestampingPolicy(String domain, ASN1ObjectIdentifier policyId) {<commit_msg>Fix SQL query and simplify function<commit_after>package org.cryptonit.cloud.timestamping;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.cryptonit.cloud.ExecutionContext;
import org.cryptonit.cloud.interfaces.TimestampingPolicy;
import org.cryptonit.cloud.interfaces.TimestampingPolicyFactory;

public class PolicyFactory implements TimestampingPolicyFactory {
    ExecutionContext context;

    public PolicyFactory(ExecutionContext context) {
        this.context = context;
    }

    @Override
    public TimestampingPolicy getTimestampingPolicy(String domain) {
        TimestampingPolicy r = null;

        try {
            Connection c = context.database.getConnection();
            PreparedStatement ps = c.prepareStatement("SELECT identityId, algorithm FROM timestamping_policy WHERE domain=? and policyId is NULL");
            ps.setString(1, domain);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                r = new Policy(rs.getString(1), null, rs.getString(2));
            }
        } catch (Exception e) {
            // TODO: Log error
        }

        return r;
    }

    @Override
    public TimestampingPolicy getTimestampingPolicy(String domain, ASN1ObjectIdentifier policyId) {
{'fraction_non_alphanumeric': 0.08324285197249366, 'fraction_numerical': 0.004705030763662686, 'mean_word_length': 3.2134146341463414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3872252', 'n_tokens_mistral': 742, 'n_tokens_neox': 718, 'n_words': 170}