@Override
    public synchronized void addTermDocument(String term, String document) throws RuntimeException {
        if  (!documents.containsKey(document)) {
            long documentId = addDocument(document);
            documents.put(document, documentId);
        }

        if (!terms.containsKey(term)) {
            long termId = addTerm(term);
            terms.put(term, termId);
        }

        long termId = terms.get(term);
        long docId = documents.get(document);

        try {
            precompiledAddTermDocument.setLong(1, termId);
            precompiledAddTermDocument.setLong(2, docId);
            precompiledAddTermDocument.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }