<commit_before>//
// Copyright (c) 2011 Linkeos.
//
// This file is part of Elveos.org.
// Elveos.org is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// Elveos.org is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
// You should have received a copy of the GNU General Public License along
// with Elveos.org. If not, see http://www.gnu.org/licenses/.
//
package com.bloatit.model.managers;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.bloatit.data.DaoIdentifiable;
import com.bloatit.data.SessionManager;
import com.bloatit.model.ConstructorVisitor;
import com.bloatit.model.Identifiable;

/**
 * The Class GenericManager is a utility class with static method to load data
 * from the DB. It is generic because the methods are not specific for a class.
 */
public final class GenericManager {

    /**
     * Desactivate constructor on utility class.
     */
    private GenericManager() {
        // desactivate CTOR
    }

    /**
     * Create an identifiable using its Id. If the identifiable is found in the
     * cache then no new object is created (It will return the one from the
     * cache).
     * 
     * @param id the id
     * @return the {@link Identifiable}, or <code>null</code> if not found.
     */
    public static Identifiable<?> getById(final Integer id) {
        final Criteria criteria = SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoIdentifiable.class);
        criteria.add(Restrictions.eq("id", id));
        return ((DaoIdentifiable) criteria.uniqueResult()).accept(new ConstructorVisitor());
    }
}
<commit_msg>prevent crash when trying to acces to a identifiable with an invalid id<commit_after>//
// Copyright (c) 2011 Linkeos.
//
// This file is part of Elveos.org.
// Elveos.org is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// Elveos.org is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
// You should have received a copy of the GNU General Public License along
// with Elveos.org. If not, see http://www.gnu.org/licenses/.
//
package com.bloatit.model.managers;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.bloatit.data.DaoIdentifiable;
import com.bloatit.data.SessionManager;
import com.bloatit.model.ConstructorVisitor;
import com.bloatit.model.Identifiable;

/**
 * The Class GenericManager is a utility class with static method to load data
 * from the DB. It is generic because the methods are not specific for a class.
 */
public final class GenericManager {

    /**
     * Desactivate constructor on utility class.
     */
    private GenericManager() {
        // desactivate CTOR
    }

    /**
     * Create an identifiable using its Id. If the identifiable is found in the
     * cache then no new object is created (It will return the one from the
     * cache).
     *
     * @param id the id
     * @return the {@link Identifiable}, or <code>null</code> if not found.
     */
    public static Identifiable<?> getById(final Integer id) {
        final Criteria criteria = SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoIdentifiable.class);
        criteria.add(Restrictions.eq("id", id));
        DaoIdentifiable daoIdentifiable = (DaoIdentifiable) criteria.uniqueResult();
        if(daoIdentifiable == null) {
            return null;
        }
        return daoIdentifiable.accept(new ConstructorVisitor());
    }
}

{'fraction_non_alphanumeric': 0.09016590526568886, 'fraction_numerical': 0.0024044241404183697, 'mean_word_length': 3.2492339121552605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '828616', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1103, 'n_words': 457}