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 org.tynamo.descriptor.CollectionDescriptor;
015    import org.tynamo.descriptor.TynamoClassDescriptor;
016    
017    import java.io.Serializable;
018    import java.util.Collection;
019    import java.util.List;
020    
021    public interface PersistenceService
022    {
023    
024            /**
025             * Returns the persistent instance of the given entity class with the given identifier,
026             * or null if there is no such persistent instance.
027             */
028            <T> T getInstance(Class<T> type, Serializable id);
029    
030            <T> List<T> getInstances(Class<T> type);
031    
032            <T> List<T> getInstances(Class<T> type, int startIndex, int maxResults);
033    
034            int count(Class type);
035    
036            <T> T save(T instance);
037    
038            void remove(Object instance);
039    
040            /**
041             * Removes all the elements in the specified collection
042             */
043            void removeAll(Collection collection);
044    
045            /**
046             * Adds and element to the collectionOwner's collection described by the descriptor
047             */
048            <T> T addToCollection(CollectionDescriptor descriptor, T element, Object collectionOwner);
049    
050            /**
051             * Removes the element from the collectionOwner's collection described by the descriptor
052             */
053            void removeFromCollection(CollectionDescriptor descriptor, Object element, Object collectionOwner);
054    
055            List getOrphanInstances(CollectionDescriptor descriptor, Object owner);
056    
057            /**
058             * Returns the identifier value of the given entity
059             */
060            Serializable getIdentifier(Object data, TynamoClassDescriptor classDescriptor);
061    
062            /**
063             * Returns the identifier value of the given entity
064             */
065            Serializable getIdentifier(Object data);
066    }