001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.persistence;
019:
020: import java.io.IOException;
021: import java.io.OutputStream;
022: import java.util.Collection;
023: import java.util.List;
024: import java.util.Set;
025:
026: import de.finix.contelligent.ComponentNotFoundException;
027: import de.finix.contelligent.ComponentPath;
028: import de.finix.contelligent.core.ComponentContextImpl;
029: import de.finix.contelligent.exception.ComponentPersistenceException;
030: import de.finix.contelligent.resource.Resource;
031:
032: public interface ComponentPersistenceAdapter extends DatabaseAdapter {
033: final static int REGULAR = 0;
034:
035: final static int RECREATED = 1;
036:
037: final static int DELETED = 9;
038:
039: final static int RESOURCETYPE_UNKNOWN = -1;
040:
041: final static int RESOURCETYPE_NUMERIC = 0;
042:
043: final static int RESOURCETYPE_STRING = 1;
044:
045: final static int RESOURCETYPE_TEXT = 2;
046:
047: final static int RESOURCETYPE_BINARY = 3;
048:
049: final static long ROOT_ID = -1L;
050:
051: /**
052: * Anser the id of the corresponding component manager. This is of use only
053: * for edit managers.
054: */
055: long getCMId();
056:
057: ComponentPersistenceAdapter getParent();
058:
059: /**
060: * Describe <code>getSubcomponentCount</code> method here.
061: *
062: * @param path
063: * a <code>ComponentPath</code> value
064: * @return an <code>int</code> value
065: */
066: int getSubcomponentCount(ComponentPath path);
067:
068: /**
069: * Returns a list of <code>ComponentDBPathHolder</code> instances
070: * representing all components available in this adapter and belong to the
071: * tree given by <tt>path</tt>. A <code>ComponentDBPathHolder</code>
072: * holds the path and the state of a component.
073: *
074: * @param path
075: * a <code>ComponentPath</code> value
076: * @return a <code>List</code> value of <code>ComponentDBPathHolder</code>
077: * instances
078: */
079: List getLocalComponentNames(ComponentPath path)
080: throws ComponentPersistenceException;
081:
082: /**
083: * Describe <code>getSubComponentNames</code> method here.
084: *
085: * @param path
086: * a <code>ComponentPath</code> value
087: * @return a <code>SortedIterator</code> value
088: * @exception ComponentPersistenceException
089: * if an error occurs
090: */
091: Set getSubComponentNames(ComponentPath path, long[] ids)
092: throws ComponentPersistenceException;
093:
094: /**
095: * Answer all subcomponent names of a complete tree.
096: *
097: * @param path
098: * @param ids
099: * @return
100: * @throws ComponentPersistenceException
101: */
102: Set getAllSubComponentPaths(ComponentPath path)
103: throws ComponentPersistenceException;
104:
105: Set getRemovedSubComponentNames(ComponentPath path)
106: throws ComponentPersistenceException;
107:
108: /**
109: * Returns the modification time of the specified component or -1 if the
110: * component does not exist.
111: *
112: * @param ctx
113: * a <code>ComponentContextImpl</code> value
114: * @return a <code>long</code> value
115: * @exception ComponentPersistenceException
116: * if an error occurs
117: */
118: long getLastModified(ComponentContextImpl ctx)
119: throws ComponentPersistenceException;
120:
121: /**
122: * Returns a list of <code>String</code> instances each representing the
123: * <B>full</B> path of a subcomponent of the given <tt>path</tt>. The
124: * order of the paths is determined by the given
125: * <tt>orderByResourceName</tt> which must equal 'stringValue' or
126: * 'numericValue' at the moment.
127: *
128: * @param basePath
129: * @param subPath
130: * @param orderByResourceName
131: * @param numberConstrain
132: * @param ascending
133: * @return
134: * @throws ComponentPersistenceException
135: */
136: List querySubcomponentPaths(ComponentPath basePath,
137: ComponentPath subPath, String orderByResourceName,
138: NumberConstraint numberConstrain, boolean ascending)
139: throws ComponentPersistenceException;
140:
141: List querySubcomponentPathsQuick(ComponentPath basePath,
142: ComponentPath subPath, String orderByResourceName,
143: NumberConstraint numberConstrain, boolean ascending)
144: throws ComponentPersistenceException;
145:
146: /**
147: * Deletes every content within the adapeter.
148: */
149: public void destroy() throws ComponentPersistenceException;
150:
151: /**
152: * Removes the given component and all it's subcomponents.
153: *
154: * @param path
155: * a <code>ComponentPath</code> value
156: * @exception ComponentPersistenceException
157: * if an error occurs
158: */
159: void delete(ComponentPath path, boolean completeTree,
160: boolean keepRoot) throws ComponentPersistenceException;
161:
162: /**
163: * Returns true if the component specifed by name and dir exists within this
164: * adpater. If an error occurs while accessing the underlying persistent
165: * store, such as an IO-error from the filesystem or an SQL-error from a
166: * database an <code>ComponentPersistenceException</code> is thrown.
167: *
168: * @param dir
169: * a <code>String</code> value
170: * @param name
171: * a <code>String</code> value
172: * @return a <code>boolean</code> value
173: * @exception ComponentPersistenceException
174: * if an error occurs
175: */
176: boolean exists(String dir, String name)
177: throws ComponentPersistenceException;
178:
179: /**
180: * Returns true if the component specifed by name and dir was deleted within
181: * this adpater. If an error occurs while accessing the underlying
182: * persistent store, such as an IO-error from the filesystem or an SQL-error
183: * from a database an <code>ComponentPersistenceException</code> is
184: * thrown.
185: *
186: * @param path
187: * a <code>String</code> value
188: * @return a <code>boolean</code> value
189: * @exception ComponentPersistenceException
190: * if an error occurs
191: */
192: boolean deleted(ComponentPath path)
193: throws ComponentPersistenceException;
194:
195: boolean recreated(ComponentPath path)
196: throws ComponentPersistenceException;
197:
198: boolean deletedHierarchical(ComponentPath path)
199: throws ComponentPersistenceException;
200:
201: boolean recreatedHierarchical(ComponentPath path)
202: throws ComponentPersistenceException;
203:
204: /**
205: * Merges all contents of the given adapter into this adapter. If the merge
206: * is successful the given adapter is empty afterwards!
207: *
208: * @param adapter
209: * the adapter whose content will be merged into this one
210: */
211: void mergeAdapter(ComponentPersistenceAdapter adapter)
212: throws ComponentPersistenceException;
213:
214: /**
215: * Merges all contents beneath the given <tt>path</tt> from the given
216: * adapter into this adapter. If the merge is successful the path in the
217: * given adapter will be empty afterwards!
218: *
219: * @param path
220: * the path to merge
221: * @param adapter
222: * the adapter whose content will be merged into this one
223: */
224: void mergeSubtreeOfAdapter(ComponentPath path,
225: ComponentPersistenceAdapter adapter)
226: throws ComponentPersistenceException;
227:
228: void removeChanges(ComponentPath root)
229: throws ComponentPersistenceException;
230:
231: Resource loadResource(long resourceId)
232: throws ComponentPersistenceException;
233:
234: void streamResource(long resourceId, OutputStream stream)
235: throws ComponentPersistenceException, IOException;
236:
237: // CRUD operations
238: public void create(ComponentContextImpl context)
239: throws ComponentPersistenceException;
240:
241: public void retrieve(ComponentContextImpl context)
242: throws ComponentPersistenceException,
243: ComponentNotFoundException;
244:
245: public void update(ComponentContextImpl context)
246: throws ComponentPersistenceException;
247:
248: public void delete(ComponentContextImpl context,
249: boolean completeTree) throws ComponentPersistenceException;
250:
251: /**
252: * Returns the paths of all components in the given <tt>treeRoot</tt>
253: * which are an instance of any type specified by </tt>typeNames</tt>.
254: * Like {@link #getSubComponentNames} components from any manager who's id
255: * is given in <tt>ids</tt> is considered. Note that <tt>treeRoot</tt>
256: * is excluded from the query.
257: *
258: * @param treeRoot
259: * a <code>ComponentPath</code> value, use null or
260: * ComponentPath.ROOT_PATH to search the whole component-tree.
261: * @param typeNames
262: * a set of strings, the names of the types to search instances
263: * of.
264: * @param ids
265: * an array of valid manager ids.
266: * @return a <code>Set</code> of <code>ComponentPath</code> instances,
267: * empty if no component matches.
268: * @exception ComponentPersistenceException
269: * if an error occurs
270: */
271: Set getComponentPathsForTypeInstances(ComponentPath treeRoot,
272: Set typeNames, long[] ids)
273: throws ComponentPersistenceException;
274:
275: String getTypeOfComponent(ComponentPath path)
276: throws ComponentPersistenceException;
277:
278: /**
279: *
280: * @return collection of ComponentPath
281: * @throws ComponentPersistenceException
282: */
283: Collection getDeletedComponents()
284: throws ComponentPersistenceException;
285:
286: /**
287: *
288: * @return collection of ComponentPath
289: * @throws ComponentPersistenceException
290: */
291: Collection getModifiedComponents()
292: throws ComponentPersistenceException;
293:
294: /**
295: *
296: * @return collection of ComponentPath
297: * @throws ComponentPersistenceException
298: */
299: Collection getNewOrModifiedBlueprintInstances()
300: throws ComponentPersistenceException;
301:
302: /**
303: * extracts a list of all TypeNames in a tree defined by the root path:
304: * <code>topMostPath</code> parameter
305: *
306: * @param topMostPath -
307: * the root path of the tree to traverse
308: * @return a collection of all typeNames within the subtree
309: */
310: Collection getTypeNamesInSubTree(ComponentPath topMostPath)
311: throws ComponentPersistenceException;
312: }
|