001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2012 GRANITE DATA SERVICES S.A.S.
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.client.tide.data.spi;
022    
023    import java.util.List;
024    import java.util.Map;
025    import java.util.Set;
026    
027    import javax.validation.ConstraintViolation;
028    import javax.validation.TraversableResolver;
029    
030    import org.granite.client.persistence.LazyableCollection;
031    import org.granite.client.tide.collections.ManagedPersistentCollection;
032    import org.granite.client.tide.collections.ManagedPersistentMap;
033    import org.granite.client.tide.data.Identifiable;
034    
035    /**
036     * @author William DRAI
037     */
038    public interface DataManager {
039        
040        public void setTrackingHandler(TrackingHandler trackingHandler);
041    
042        public boolean isDirty();
043        
044        public EntityDescriptor getEntityDescriptor(Object entity);
045        
046        public Object getProperty(Object object, String propertyName);
047    
048        public void setProperty(Object object, String propertyName, Object oldValue, Object newValue);
049    
050        public void setInternalProperty(Object object, String propertyName, Object value);
051        
052        public Map<String, Object> getPropertyValues(Object object, boolean includeReadOnly, boolean includeTransient);
053        
054        public Map<String, Object> getPropertyValues(Object object, List<String> excludedProperties, boolean includeReadOnly, boolean includeTransient);
055        
056        public ManagedPersistentCollection<Object> newPersistentCollection(Identifiable parent, String propertyName, LazyableCollection nextList);
057        
058        public ManagedPersistentMap<Object, Object> newPersistentMap(Identifiable parent, String propertyName, LazyableCollection nextMap);
059    
060        
061        public static enum TrackingType {        
062            COLLECTION,
063            MAP,
064            ENTITY_PROPERTY,
065            ENTITY_COLLECTION,
066            ENTITY_MAP
067        }
068        
069        public static enum ChangeKind {
070            ADD,
071            REMOVE,
072            REPLACE,
073            UPDATE
074        }
075    
076        
077        /**
078         *  Start tracking for specific object / parent
079         *
080         *  @param previous previously existing object in the entity manager cache (null if no existing object)
081         *  @param parent parent object for collections
082         */
083        public void startTracking(Object previous, Object parent);
084        
085        /**
086         *  Stop tracking for specific object / parent
087         *
088         *  @param previous previously existing object in the entity manager cache (null if no existing object)
089         *  @param parent parent object for collections
090         */
091        public void stopTracking(Object previous, Object parent);
092    
093    
094        public void notifyDirtyChange(boolean oldDirty, boolean dirty);
095    
096        public void notifyEntityDirtyChange(Object entity, boolean oldDirtyEntity, boolean newDirtyEntity);
097        
098        
099        public TraversableResolver getTraversableResolver();
100        
101        public void notifyConstraintViolations(Object entity, Set<ConstraintViolation<?>> violation);
102        
103        
104        /**
105         *  Reset all currently tracked objects
106         */
107        public void clear();          
108        
109        
110        public static interface TrackingHandler {
111            
112            public void collectionChangeHandler(ChangeKind kind, Object target, int location, Object[] items);
113            
114            public void mapChangeHandler(ChangeKind kind, Object target, int location, Object[] items);
115    
116            public void entityPropertyChangeHandler(Object target, String property, Object oldValue, Object newValue);
117    
118            public void entityCollectionChangeHandler(ChangeKind kind, Object target, int location, Object[] items);
119    
120            public void entityMapChangeHandler(ChangeKind kind, Object target, int location, Object[] items);
121        }
122    
123    
124    }