001    /*
002     * Copyright 2004 Chris Nelson
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
007     * Unless required by applicable law or agreed to in writing,
008     * software distributed under the License is distributed on an "AS IS" BASIS,
009     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010     * See the License for the specific language governing permissions and limitations under the License.
011     */
012    package org.tynamo.hibernate.services;
013    
014    import org.hibernate.criterion.DetachedCriteria;
015    import org.tynamo.descriptor.TynamoClassDescriptor;
016    import org.tynamo.services.PersistenceService;
017    import org.apache.tapestry5.hibernate.annotations.CommitAfter;
018    
019    import java.util.List;
020    
021    public interface HibernatePersistenceService extends PersistenceService
022    {
023    
024            @CommitAfter
025            <T> T save(T instance);
026    
027            @CommitAfter
028            void remove(Object instance);
029    
030            public <T> T getInstance(Class<T> type, DetachedCriteria criteria);
031    
032            public <T> List<T> getInstances(Class<T> type, DetachedCriteria criteria);
033    
034            public <T> List<T> getInstances(Class<T> type, DetachedCriteria criteria, int startIndex, int maxResults);
035    
036            public int count(Class type, DetachedCriteria criteria);
037    
038            /**
039             * @param model to attach to the current persistence session
040             */
041            public void reattach(Object model);
042    
043            /**
044             * Does a query by example
045             *
046             * @param example
047             * @return
048             */
049            public <T> List<T> getInstances(T example, TynamoClassDescriptor classDescriptor);
050    
051            public <T> T merge(T instance);
052    
053            public <T> T saveOrUpdate(T instance);
054    
055            public List findByQuery(String queryString);
056    
057            public List findByQuery(String queryString, QueryParameter... parameters);
058    
059            public List findByQuery(String queryString, int startIndex, int maxResults, QueryParameter... parameters);
060    }