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.services;
013    
014    import java.io.Serializable;
015    import java.util.Collection;
016    import java.util.List;
017    
018    import org.tynamo.descriptor.TynamoClassDescriptor;
019    
020    public interface PersistenceService
021    {
022    
023            public <T> T getInstance(Class<T> type, Serializable id);
024    
025            <T> T loadInstance(final Class<T> type, Serializable id);
026    
027            public <T> List<T> getInstances(Class<T> type);
028    
029            public <T> List<T> getInstances(Class<T> type, int startIndex, int maxResults);
030    
031            /**
032             * @return a List containing all the classes this persistence
033             *         service knows about
034             */
035    //      public List getAllTypes();
036    
037            public <T> T save(T instance);
038    
039            public void remove(Object instance);
040            public void removeAll(Collection collection);
041    
042            /**
043             * A convenience method for getting a singleton instance of specific type
044             *
045             * @param <T>  Specific type of the entity
046             * @param type Type of singleton entity you want return
047             * @return Returns the singleton entity of requested type
048             */
049            public <T> T getInstance(final Class<T> type);
050    
051            boolean isTransient(Object data, TynamoClassDescriptor classDescriptor);
052    
053            <T> T saveCollectionElement(String addExpression, T member, Object parent);
054    
055            void removeCollectionElement(String removeExpression, Object member, Object parent);
056    
057    }