001    package railo.runtime.orm;
002    
003    
004    import railo.runtime.Component;
005    import railo.runtime.PageContext;
006    import railo.runtime.db.DatasourceConnection;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.type.Array;
009    import railo.runtime.type.Query;
010    import railo.runtime.type.Struct;
011    
012    public interface ORMSession {
013    
014            /**
015             * flush all elements in session
016             * @param pc
017             * @throws PageException
018             */
019            public void flush(PageContext pc) throws PageException;
020            
021            /**
022             * delete elememt from datasource
023             * @param name
024             * @throws PageException 
025             */
026            public void delete(PageContext pc, Object obj) throws PageException;
027            
028            /**
029             * insert entity into datasource, even the entry already exist
030             * @param entity
031             * @throws PageException 
032             */
033            public void save(PageContext pc, Object obj, boolean forceInsert) throws PageException;
034            
035    
036            /**
037             * Reloads data for an entity that is already loaded. This method refetches data from the database and repopulates the entity with the refreshed data.
038             * @param obj 
039             * @throws ORMException
040             */
041            public void reload(PageContext pc, Object obj) throws PageException;
042    
043            /**
044             * creates a entity matching the given name
045             * @param entityName
046             * @return
047             * @throws ORMException
048             */
049            public Component create(PageContext pc, String entityName) throws PageException;
050            
051            /**
052             * Attaches the specified entity to the current ORM session. It copies the state of the given object onto the persistent object with the same identifier and returns the persistent object.
053             * If there is no persistent instance currently associated with the session, it is loaded. The given instance is not associated with the session. User have to use the returned object from this session.
054             * @param entity
055             * @return
056             * @throws PageException 
057             */
058            public Component merge(PageContext pc, Object obj) throws PageException;
059            
060            /**
061             * clear the session
062             * @param pc
063             * @throws PageException
064             */
065            public void clear(PageContext pc) throws PageException;
066            
067            /**
068             * load and return a Object that match given filter, if there is more than one Object matching the filter, only the first Object is returned
069             * @param name
070             * @param filter
071             * @return
072             */
073            public Component load(PageContext pc, String name, Struct filter) throws PageException;
074            
075            public Query toQuery(PageContext pc, Object obj, String name) throws PageException;
076    
077    
078            
079            /**
080             * load and return a Object that match given id, if there is more than one Object matching the id, only the first Object is returned
081             * @param name
082             * @param id
083             */
084            public Component load(PageContext pc, String name, String id) throws PageException;
085            
086            /**
087             * load and return a array of Objects matching given filter
088             * @param name
089             * @param filter
090             * @return
091             */
092            public Array loadAsArray(PageContext pc, String name, Struct filter) throws PageException;
093            
094            
095            /**
096             * load and return a array of Objects matching given filter
097             * @param name
098             * @param filter
099             * @param options
100             * @return
101             */
102            public Array loadAsArray(PageContext pc, String name, Struct filter, Struct options)throws PageException;
103            
104            /**
105             * @param pc
106             * @param name
107             * @param filter
108             * @param options
109             * @param order
110             * @return
111             * @throws PageException
112             */
113            public Array loadAsArray(PageContext pc, String name, Struct filter, Struct options, String order)throws PageException;
114    
115            /**
116             * load and return a array of Objects matching given id
117             * @param name
118             * @param id
119             */
120            public Array loadAsArray(PageContext pc, String name, String id) throws PageException;
121            
122            /**
123             * @param pc
124             * @param name
125             * @param id
126             * @param order
127             * @return
128             * @throws PageException
129             */
130            public Array loadAsArray(PageContext pc, String name, String id, String order) throws PageException;
131    
132            /**
133             * load and return a array of Objects matching given sampleEntity
134             * @param name
135             * @param id
136             */
137            public Array loadByExampleAsArray(PageContext pc, Object obj) throws PageException;
138            
139            /**
140             * load and return a Object that match given sampleEntity, if there is more than one Object matching the id, only the first Object is returned
141             * @param name
142             * @param id
143             */
144            public Component loadByExample(PageContext pc, Object obj) throws PageException;
145            
146            public void evictCollection(PageContext pc,String entity, String collection) throws PageException;
147            
148            public void evictCollection(PageContext pc,String entity, String collection, String id) throws PageException;
149    
150            public void evictEntity(PageContext pc,String entity) throws PageException;
151            
152            public void evictEntity(PageContext pc,String entity, String id) throws PageException;
153    
154            public void evictQueries(PageContext pc) throws PageException;
155            
156            public void evictQueries(PageContext pc,String cacheName) throws PageException;
157    
158            public Object executeQuery(PageContext pc,String hql, Array params, boolean unique,Struct queryOptions) throws PageException;
159    
160            public Object executeQuery(PageContext pc,String hql, Struct params, boolean unique,Struct queryOptions) throws PageException;
161    
162            /**
163             * close the session
164             * @param pc
165             * @throws PageException
166             */
167            public void close(PageContext pc) throws PageException;
168            
169            /**
170             * is session valid or not
171             * @return is session valid
172             */
173            public boolean isValid();
174            
175            /**
176             * engine from session
177             * @return engine
178             */
179            public ORMEngine getEngine();
180            
181            public Object getRawSession();
182    
183            public ORMTransaction getTransaction(boolean autoManage);
184    
185            public DatasourceConnection getDatasourceConnection();
186            
187    }