Source Code Cross Referenced for DatabaseContentStore.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » cmf » dam » contentstores » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.cmf.dam.contentstores 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: DatabaseContentStore.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.cmf.dam.contentstores;
009:
010:        import com.uwyn.rife.database.*;
011:
012:        import com.uwyn.rife.cmf.MimeType;
013:        import com.uwyn.rife.cmf.dam.ContentStore;
014:        import com.uwyn.rife.cmf.dam.contentstores.exceptions.DeleteContentDataErrorException;
015:        import com.uwyn.rife.cmf.dam.contentstores.exceptions.HasContentDataErrorException;
016:        import com.uwyn.rife.cmf.dam.contentstores.exceptions.InstallContentStoreErrorException;
017:        import com.uwyn.rife.cmf.dam.contentstores.exceptions.RemoveContentStoreErrorException;
018:        import com.uwyn.rife.cmf.dam.contentstores.exceptions.RetrieveSizeErrorException;
019:        import com.uwyn.rife.cmf.dam.exceptions.ContentManagerException;
020:        import com.uwyn.rife.database.exceptions.DatabaseException;
021:        import com.uwyn.rife.database.queries.CreateTable;
022:        import com.uwyn.rife.database.queries.Delete;
023:        import com.uwyn.rife.database.queries.DropTable;
024:        import com.uwyn.rife.database.queries.Select;
025:        import com.uwyn.rife.engine.ElementSupport;
026:        import com.uwyn.rife.tools.ExceptionUtils;
027:        import com.uwyn.rife.tools.InnerClassException;
028:        import java.io.OutputStream;
029:        import java.sql.ResultSet;
030:        import java.sql.SQLException;
031:        import java.util.ArrayList;
032:        import java.util.Collection;
033:        import java.util.logging.Logger;
034:        import javax.servlet.http.HttpServletResponse;
035:
036:        public abstract class DatabaseContentStore extends DbQueryManager
037:                implements  ContentStore {
038:            private ArrayList<MimeType> mMimeTypes = new ArrayList<MimeType>();
039:
040:            public DatabaseContentStore(Datasource datasource) {
041:                super (datasource);
042:            }
043:
044:            protected void addMimeType(MimeType mimeType) {
045:                mMimeTypes.add(mimeType);
046:            }
047:
048:            public Collection<MimeType> getSupportedMimeTypes() {
049:                return mMimeTypes;
050:            }
051:
052:            protected boolean _install(CreateTable createTableContentStore)
053:                    throws ContentManagerException {
054:                assert createTableContentStore != null;
055:
056:                try {
057:                    executeUpdate(createTableContentStore);
058:                } catch (DatabaseException e) {
059:                    throw new InstallContentStoreErrorException(e);
060:                }
061:
062:                return true;
063:            }
064:
065:            protected boolean _remove(DropTable dropTableContentStore)
066:                    throws ContentManagerException {
067:                assert dropTableContentStore != null;
068:
069:                try {
070:                    executeUpdate(dropTableContentStore);
071:                } catch (DatabaseException e) {
072:                    throw new RemoveContentStoreErrorException(e);
073:                }
074:
075:                return true;
076:            }
077:
078:            protected boolean _deleteContentData(
079:                    final Delete deleteContentData, final int id)
080:                    throws ContentManagerException {
081:                if (id < 0)
082:                    throw new IllegalArgumentException("id must be positive");
083:
084:                assert deleteContentData != null;
085:
086:                Boolean result = null;
087:
088:                try {
089:                    result = inTransaction(new DbTransactionUser() {
090:                        public Boolean useTransaction()
091:                                throws InnerClassException {
092:                            return 0 != executeUpdate(deleteContentData,
093:                                    new DbPreparedStatementHandler() {
094:                                        public void setParameters(
095:                                                DbPreparedStatement statement) {
096:                                            statement.setInt("contentId", id);
097:                                        }
098:                                    });
099:
100:                        }
101:                    });
102:                } catch (DatabaseException e) {
103:                    throw new DeleteContentDataErrorException(id, e);
104:                }
105:
106:                return result != null && result.booleanValue();
107:            }
108:
109:            protected int _getSize(Select retrieveSize, final int id)
110:                    throws ContentManagerException {
111:                if (id < 0)
112:                    throw new IllegalArgumentException("id must be positive");
113:
114:                assert retrieveSize != null;
115:
116:                try {
117:                    return executeGetFirstInt(retrieveSize,
118:                            new DbPreparedStatementHandler() {
119:                                public void setParameters(
120:                                        DbPreparedStatement statement) {
121:                                    statement.setInt("contentId", id);
122:                                }
123:                            });
124:                } catch (DatabaseException e) {
125:                    throw new RetrieveSizeErrorException(id, e);
126:                }
127:            }
128:
129:            protected boolean _hasContentData(Select hasContentData,
130:                    final int id) throws ContentManagerException {
131:                if (id < 0)
132:                    throw new IllegalArgumentException("id must be positive");
133:
134:                assert hasContentData != null;
135:
136:                try {
137:                    return executeHasResultRows(hasContentData,
138:                            new DbPreparedStatementHandler() {
139:                                public void setParameters(
140:                                        DbPreparedStatement statement) {
141:                                    statement.setInt("contentId", id);
142:                                }
143:                            });
144:                } catch (DatabaseException e) {
145:                    throw new HasContentDataErrorException(id, e);
146:                }
147:            }
148:
149:            protected String getContentSizeColumnName() {
150:                return "size";
151:            }
152:
153:            protected void _serveContentData(Select retrieveContent,
154:                    final ElementSupport element, final int id)
155:                    throws ContentManagerException {
156:                if (null == element)
157:                    throw new IllegalArgumentException("element can't be null");
158:
159:                if (id < 0) {
160:                    element.defer();
161:                    return;
162:                }
163:
164:                assert retrieveContent != null;
165:
166:                try {
167:                    if (!executeFetchFirst(retrieveContent,
168:                            new DbRowProcessor() {
169:                                public boolean processRow(ResultSet resultSet)
170:                                        throws SQLException {
171:                                    // set the content length header
172:                                    element
173:                                            .setContentLength(resultSet
174:                                                    .getInt(getContentSizeColumnName()));
175:
176:                                    // output the content
177:                                    OutputStream os = element.getOutputStream();
178:                                    outputContentColumn(resultSet, os);
179:
180:                                    return true;
181:                                }
182:                            }, new DbPreparedStatementHandler() {
183:                                public void setParameters(
184:                                        DbPreparedStatement statement) {
185:                                    statement.setInt("contentId", id);
186:                                }
187:                            })) {
188:                        element.defer();
189:                        return;
190:                    }
191:                } catch (DatabaseException e) {
192:                    Logger.getLogger("com.uwyn.rife.cmf").severe(
193:                            ExceptionUtils.getExceptionStackTrace(e));
194:                    element
195:                            .setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
196:                }
197:            }
198:
199:            protected abstract void outputContentColumn(ResultSet resultSet,
200:                    OutputStream os) throws SQLException;
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.