001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.core.storage;
034:
035: import com.flexive.shared.content.FxContent;
036: import com.flexive.shared.content.FxContentSecurityInfo;
037: import com.flexive.shared.content.FxContentVersionInfo;
038: import com.flexive.shared.content.FxPK;
039: import com.flexive.shared.exceptions.*;
040: import com.flexive.shared.structure.FxEnvironment;
041: import com.flexive.shared.structure.FxProperty;
042: import com.flexive.shared.structure.FxType;
043: import com.flexive.shared.structure.UniqueMode;
044:
045: import java.io.InputStream;
046: import java.sql.Connection;
047: import java.util.List;
048:
049: /**
050: * SQL storage interface for contents
051: *
052: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: */
054: public interface ContentStorage {
055:
056: /**
057: * Get the Database table name for this data type
058: *
059: * @param prop FxPropery to request the table name for
060: * @return table name
061: */
062: String getTableName(FxProperty prop);
063:
064: /**
065: * Get the (optional) uppercase column used for this data type.
066: * If no uppercase column is used, <code>null</code> is returned.
067: *
068: * @param prop requested FxPropery
069: * @return uppercase column name or <code>null</code>
070: */
071: String getUppercaseColumn(FxProperty prop);
072:
073: /**
074: * Get the database columns used for this data type
075: *
076: * @param prop requested FxProperty
077: * @return the database columns used
078: */
079: String[] getColumns(FxProperty prop);
080:
081: /**
082: * Get all security relevant information about a content instance identified by its primary key
083: *
084: * @param con an open and valid connection
085: * @param pk primary key to query security information for
086: * @return FxContentSecurityInfo
087: * @throws FxLoadException on errors
088: * @throws FxNotFoundException on errors
089: */
090: FxContentSecurityInfo getContentSecurityInfo(Connection con, FxPK pk)
091: throws FxLoadException, FxNotFoundException;
092:
093: /**
094: * Get information about the versions used for a content id
095: *
096: * @param con an open and valid Connection
097: * @param id the id to query version information for
098: * @return FxContentVersionInfo
099: * @throws FxNotFoundException if the requested id does not exist
100: */
101: FxContentVersionInfo getContentVersionInfo(Connection con, long id)
102: throws FxNotFoundException;
103:
104: /**
105: * Create a new content instance
106: *
107: * @param con an open and valid Connection
108: * @param env Environment
109: * @param sql optional StringBuilder to save performance
110: * @param newId the new Id to assign
111: * @param content the content to persist
112: * @return primary key of the created content
113: * @throws FxCreateException on create errors
114: * @throws FxInvalidParameterException on invalid values/missing required values in content
115: */
116: FxPK contentCreate(Connection con, FxEnvironment env,
117: StringBuilder sql, long newId, FxContent content)
118: throws FxCreateException, FxInvalidParameterException;
119:
120: /**
121: * Create a new version for an existing content instance
122: *
123: * @param con an open and valid Connection
124: * @param env Environment
125: * @param sql optional StringBuilder to save performance
126: * @param content the content to persist
127: * @return primary key of the new version
128: * @throws FxCreateException on create errors
129: * @throws FxInvalidParameterException on invalid values/missing required values in content
130: */
131: FxPK contentCreateVersion(Connection con, FxEnvironment env,
132: StringBuilder sql, FxContent content)
133: throws FxCreateException, FxInvalidParameterException;
134:
135: /**
136: * Load a content with the given primary key
137: *
138: * @param con an open and valid connection
139: * @param pk primary key
140: * @param env Environment
141: * @param sql optional StringBuilder to save performance
142: * @return loaded content
143: * @throws FxLoadException on errors
144: * @throws FxInvalidParameterException on invalid parameters (pk)
145: * @throws FxNotFoundException if no instance for this primary key was found
146: */
147: FxContent contentLoad(Connection con, FxPK pk, FxEnvironment env,
148: StringBuilder sql) throws FxLoadException,
149: FxInvalidParameterException, FxNotFoundException;
150:
151: /**
152: * Save a content instance, creating new versions as needed
153: *
154: * @param con an open and valid connection
155: * @param env Environment
156: * @param sql optional StringBuilder to save performance
157: * @param content the content to persist
158: * @param fqnPropertyId id of the FQN property, needed to sync changes back to the tree
159: * @return primary key of the saved content
160: * @throws FxUpdateException on errors
161: * @throws FxInvalidParameterException on errors
162: */
163: FxPK contentSave(Connection con, FxEnvironment env,
164: StringBuilder sql, FxContent content, long fqnPropertyId)
165: throws FxUpdateException, FxInvalidParameterException;
166:
167: /**
168: * Remove a content instance and all its versions, will throw an
169: * Exception if it is referenced from other contents.
170: *
171: * @param con an open and valid connection
172: * @param pk primary key
173: * @throws com.flexive.shared.exceptions.FxRemoveException
174: * on errors
175: */
176: void contentRemove(Connection con, FxPK pk)
177: throws FxRemoveException;
178:
179: /**
180: * Remove a content's version, will throw an
181: * Exception if it is referenced from other contents.
182: * If the content consists only of this specific version the whole content is removed
183: *
184: * @param con an open and valid connection
185: * @param pk primary key for a distinct version
186: * @throws com.flexive.shared.exceptions.FxRemoveException
187: * on errors
188: * @throws FxNotFoundException on errors
189: */
190: void contentRemoveVersion(Connection con, FxPK pk)
191: throws FxRemoveException, FxNotFoundException;
192:
193: /**
194: * Remove all instances of the given type.
195: * Beans using this method should apply very strict security restrictions!
196: *
197: * @param con an open and valid connection
198: * @param type affected FxType
199: * @return number of instances removed
200: * @throws com.flexive.shared.exceptions.FxRemoveException
201: * on errors
202: */
203: int contentRemoveForType(Connection con, FxType type)
204: throws FxRemoveException;
205:
206: /**
207: * Get a list of all primary keys for the given FxType (can be a very long list!!!)
208: *
209: * @param con an open and valid connection
210: * @param type the type to request the primary keys for
211: * @param onePkPerInstance return one primary key per instance (with max version) or one per actual version?
212: * @return list containing the primary keys
213: * @throws FxDbException on errors
214: */
215: List<FxPK> getPKsForType(Connection con, FxType type,
216: boolean onePkPerInstance) throws FxDbException;
217:
218: /**
219: * Perform maintenance and cleanup tasks.
220: * To be called periodically.
221: *
222: * @param con an open and valid connection
223: */
224: void maintenance(Connection con);
225:
226: /**
227: * Prepare a content for a save or create operation (resolves binaries for script processing, etc.)
228: *
229: * @param con an open and valid Connection
230: * @param content the content to prepare
231: * @throws FxInvalidParameterException on errors
232: * @throws FxDbException on errors
233: */
234: void prepareSave(Connection con, FxContent content)
235: throws FxInvalidParameterException, FxDbException;
236:
237: //specialized repository methods
238:
239: /**
240: * Create a new or update an existing binary
241: *
242: * @param con an open and valid Connection
243: * @param id id of the binary
244: * @param version version of the binary
245: * @param quality quality of the binary
246: * @param name file name
247: * @param length length of the binary
248: * @param binary the binary
249: * @throws FxApplicationException on errors
250: */
251: void storeBinary(Connection con, long id, int version, int quality,
252: String name, long length, InputStream binary)
253: throws FxApplicationException;
254:
255: /**
256: * Create a new or update an existing binary
257: *
258: * @param con an open and valid Connection
259: * @param id id of the binary
260: * @param version version of the binary
261: * @param quality quality of the binary
262: * @param preview the number of the preview to update (1..3)
263: * @param width width of the preview
264: * @param height height of the preview
265: * @param length length of the binary
266: * @param binary the binary
267: */
268: void updateBinaryPreview(Connection con, long id, int version,
269: int quality, int preview, int width, int height,
270: long length, InputStream binary);
271:
272: /**
273: * Get the number of references that exist for the requested content id
274: *
275: * @param con an open and valid Connection
276: * @param id id of the requested content
277: * @return number of references that exist for the requested content
278: * @throws FxDbException on errors
279: */
280: int getReferencedContentCount(Connection con, long id)
281: throws FxDbException;
282:
283: /**
284: * Update XPath entires of content data
285: *
286: * @param con an open and valid connection
287: * @param assignmentId assignment id
288: * @param originalXPath original xpath
289: * @param newXPath new xpath
290: * @throws FxInvalidParameterException if an XPath is not valid
291: * @throws FxUpdateException on errors
292: */
293: void updateXPath(Connection con, long assignmentId,
294: String originalXPath, String newXPath)
295: throws FxUpdateException, FxInvalidParameterException;
296:
297: /**
298: * Check if a unique condition is valid for a propery
299: *
300: * @param con an open and valid Connection
301: * @param mode UniqueMode
302: * @param prop property
303: * @param typeId type
304: * @param pk primary key (optional)
305: * @return if mode would be valid
306: */
307: boolean uniqueConditionValid(Connection con, UniqueMode mode,
308: FxProperty prop, long typeId, FxPK pk);
309: }
|