All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.credibledoc.log.labelizer.github.VisitedUrlRepository Maven / Gradle / Ivy

There is a newer version: 1.0.51
Show newest version
package com.credibledoc.log.labelizer.github;

import com.credibledoc.log.labelizer.datastore.DatastoreService;
import dev.morphia.Datastore;

import java.util.List;

/**
 * Data Access Object for the {@link VisitedUrl} records.
 * 
 * @author Kyrylo Semenko
 */
public class VisitedUrlRepository {
    /** Refers to a {@link DatastoreService#getDatastore()} object */
    private Datastore datastore;

    /**
     * Singleton.
     */
    private static VisitedUrlRepository instance;

    /**
     * @return The {@link VisitedUrlRepository} singleton.
     */
    public static VisitedUrlRepository getInstance() {
        if (instance == null) {
            instance = new VisitedUrlRepository();
            instance.datastore = DatastoreService.getInstance().getDatastore();
        }
        return instance;
    }

    /**
     * @return 'true' if the database contains a {@link VisitedUrl} object with such {@link VisitedUrl#getUrl()}.
     * @param url the filter
     */
    public boolean contains(String url) {
        return datastore.createQuery(VisitedUrl.class)
            .field(VisitedUrl.URL)
            .equal(url).count() > 0;
    }

    /**
     * Save entities to the database.
     * @param visitedUrlList entities to be saved
     */
    public void save(List visitedUrlList) {
        datastore.save(visitedUrlList);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy