001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.api.database;
021
022 import org.sonar.api.BatchComponent;
023
024 import javax.persistence.EntityManager;
025 import javax.persistence.Query;
026 import java.util.List;
027
028 /**
029 * This component should not accessible from plugin API
030 *
031 * @since 1.10
032 */
033 public abstract class DatabaseSession implements BatchComponent {
034
035
036 // IMPORTANT : this value must be the same than the property
037 // hibernate.jdbc.batch_size from /META-INF/persistence.xml (module sonar-database)
038 public static final int BATCH_SIZE = 30;
039
040
041 public abstract EntityManager getEntityManager();
042
043 public abstract void start();
044
045 public abstract void stop();
046
047 public abstract void commit();
048
049 public abstract void rollback();
050
051 public abstract <T> T save(T entity);
052
053 public abstract Object saveWithoutFlush(Object entity);
054
055 public abstract boolean contains(Object entity);
056
057 public abstract void save(Object... entities);
058
059 public abstract Object merge(Object entity);
060
061 public abstract void remove(Object entity);
062
063 public abstract void removeWithoutFlush(Object entity);
064
065 public abstract <T> T reattach(Class<T> entityClass, Object primaryKey);
066
067 public abstract Query createQuery(String hql);
068
069 public abstract <T> T getSingleResult(Query query, T defaultValue);
070
071 public abstract <T> T getEntity(Class<T> entityClass, Object id);
072
073 public abstract <T> T getSingleResult(Class<T> entityClass, Object... criterias);
074
075 public abstract <T> List<T> getResults(Class<T> entityClass, Object... criterias);
076
077 public abstract <T> List<T> getResults(Class<T> entityClass);
078 }