Source Code Cross Referenced for ServiceButtonsStateStorer.java in  » Portal » mypersonalizer » es » udc » mypersonalizer » kernel » model » repository » sql » storers » 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 » Portal » mypersonalizer » es.udc.mypersonalizer.kernel.model.repository.sql.storers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/sql/storers/ServiceButtonsStateStorer.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003:         * $Revision: 1.1.1.1 $
004:         * $Date: 2004/03/25 12:08:36 $
005:         *
006:         * =============================================================================
007:         *
008:         * Copyright (c) 2003, The MyPersonalizer Development Group
009:         * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at 
010:         * University Of A Coruna
011:         * All rights reserved.
012:         *
013:         * Redistribution and use in source and binary forms, with or without
014:         * modification, are permitted provided that the following conditions are met:
015:         *
016:         *  - Redistributions of source code must retain the above copyright notice, 
017:         *    this list of conditions and the following disclaimer.
018:         *
019:         *  - Redistributions in binary form must reproduce the above copyright notice,
020:         *    this list of conditions and the following disclaimer in the documentation
021:         *    and/or other materials provided with the distribution.
022:         *
023:         *  - Neither the name of the University Of A Coruna nor the names of its 
024:         *    contributors may be used to endorse or promote products derived from 
025:         *    this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
028:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037:         * POSSIBILITY OF SUCH DAMAGE.
038:         *
039:         */
040:
041:        package es.udc.mypersonalizer.kernel.model.repository.sql.storers;
042:
043:        import java.util.Map;
044:        import java.util.HashMap;
045:        import java.sql.Connection;
046:
047:        import es.udc.mypersonalizer.kernel.model.annotators.sql.SQLPersistenceTypeAnnotationHelper;
048:        import es.udc.mypersonalizer.kernel.model.metainfo.MetaService;
049:        import es.udc.mypersonalizer.kernel.model.metainfo.MetaServiceRegistrySingleton;
050:        import es.udc.mypersonalizer.kernel.model.properties.Property;
051:        import es.udc.mypersonalizer.kernel.model.repository.sql.config.DatabaseConventionsConfigManager;
052:        import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
053:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceButtonsState;
054:        import es.udc.mypersonalizer.kernel.util.exceptions.DuplicateInstanceException;
055:        import es.udc.mypersonalizer.kernel.util.exceptions.InstanceNotFoundException;
056:        import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
057:
058:        /**
059:         * This "storer" class stores and removes <code>ServiceButtonsState</code>s
060:         * on a database. This class does not assume any policy on how to store and
061:         * retrieve the data. This knowledge is encapsulated in classes that implement
062:         * the interface <code>PropertyStorageStrategy</code>. This "storer" class
063:         * will delegate on the strategy class in order to store or retrieve a
064:         * service buttons state on the database. Example: a strategy class that
065:         * stores service buttons states by using serialization. This storate strategy
066:         * is obtained from a registry on initializing time.
067:         *
068:         * @author  Abel Muinho
069:         * @author  Fernando Bellas
070:         * @since   1.0
071:         */
072:        public class ServiceButtonsStateStorer {
073:
074:            /** Constant for the table name. */
075:            private static String TABLE_NAME = null;
076:
077:            /** Constant for the key field name. */
078:            private static String propertyIdentifierColumnName;
079:
080:            /** The class that knows how to store and retrieve properties. */
081:            private static PropertyStorageStrategy strategy = null;
082:
083:            /**
084:             * Creates an instance of this class.
085:             *
086:             * @throws InternalErrorException if an essential internal element is
087:             *      missing.
088:             */
089:            public ServiceButtonsStateStorer() throws InternalErrorException {
090:                MetaService metaService = MetaServiceRegistrySingleton
091:                        .getInstance()
092:                        .getMetaService(
093:                                ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
094:
095:                if (metaService == null) {
096:                    throw new InternalErrorException(
097:                            "FATAL ERROR: MetaService not found for service identifier: "
098:                                    + ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
099:                }
100:
101:                TABLE_NAME = SQLPersistenceTypeAnnotationHelper
102:                        .getTableNameAnnotation(metaService);
103:                propertyIdentifierColumnName = DatabaseConventionsConfigManager
104:                        .getConfig().getPropertyIdentifierColumn();
105:
106:                strategy = PropertyStorageStrategyRegistrySingleton
107:                        .getInstance()
108:                        .getPropertyStorageStrategy(
109:                                ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
110:
111:                if (strategy == null) {
112:                    throw new InternalErrorException(
113:                            "FATAL ERROR: PropertyStorageStrategy "
114:                                    + "not found for service identifier: "
115:                                    + ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
116:                }
117:            }
118:
119:            /**
120:             * Finds a service buttons state.
121:             * 
122:             * @param  connection the connection to the database
123:             * @param  propertyIdentifier the service buttons state property identifier
124:             * @return the service buttons state
125:             * @throws InternalErrorException if a failure is detected.
126:             * @throws InstanceNotFoundException if it was unable the find the service buttons
127:             *         state
128:             */
129:            public ServiceButtonsState findServiceButtonsState(
130:                    Connection connection, Long propertyIdentifier)
131:                    throws InternalErrorException, InstanceNotFoundException {
132:
133:                Property property = strategy.findProperty(connection,
134:                        getStrategyKey(propertyIdentifier));
135:
136:                return new ServiceButtonsState(propertyIdentifier, property);
137:            }
138:
139:            /**
140:             * Removes a service buttons state.
141:             *
142:             * @param  connection the connection to the database
143:             * @param  propertyIdentifier the service buttons state property identifier
144:             * @throws InternalErrorException if a failure is detected.
145:             * @throws InstanceNotFoundException if it was unable to find the service buttons
146:             *         state to be removed
147:             */
148:            public void removeServiceButtonsState(Connection connection,
149:                    Long propertyIdentifier) throws InternalErrorException,
150:                    InstanceNotFoundException {
151:
152:                strategy.removeProperty(connection,
153:                        getStrategyKey(propertyIdentifier));
154:            }
155:
156:            /**
157:             * Updates a service buttons state.
158:             * 
159:             * @param  connection the connection to the database
160:             * @param  serviceButtonsState the new service buttons state
161:             * @throws InternalErrorException if a failure is detected.
162:             * @throws InstanceNotFoundException if it was unable to find the service buttons
163:             *         state to be updated
164:             */
165:            public void updateServiceButtonsState(Connection connection,
166:                    ServiceButtonsState serviceButtonsState)
167:                    throws InternalErrorException, InstanceNotFoundException {
168:
169:                Map strategyKey = getStrategyKey(serviceButtonsState
170:                        .getPropertyIdentifier());
171:                strategy.updateProperty(connection, strategyKey,
172:                        serviceButtonsState.getProperty());
173:            }
174:
175:            /**
176:             * Adds a new service buttons state.
177:             * 
178:             * @param  connection the connection to the database
179:             * @param  property the property that represents the new service buttons
180:             *         state 
181:             * @return the property identifier for the service buttons state added
182:             * @throws InternalErrorException if a failure is detected.
183:             */
184:            public Long addServiceButtonsState(Connection connection,
185:                    Property property) throws InternalErrorException {
186:
187:                Long nextIdentifier = EntityIdentifierGeneratorSingleton
188:                        .getInstance().nextIdentifier(connection, TABLE_NAME);
189:                Map strategyKey = getStrategyKey(nextIdentifier);
190:
191:                try {
192:                    strategy.addProperty(connection, strategyKey, property);
193:
194:                } catch (DuplicateInstanceException exception) {
195:                    throw new InternalErrorException(
196:                            "FATAL ERROR: generated identifier is duplicated: "
197:                                    + nextIdentifier
198:                                    + " for service: "
199:                                    + ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
200:                }
201:
202:                return nextIdentifier;
203:            }
204:
205:            /** 
206:             * Constructs a <code>Map</code> with a single row that contains a pair
207:             * of (<code>String, Long</code>), used as the key for inserting or
208:             * updating a property delegating on the strategy class passed.
209:             *
210:             * @param  propertyIdentifier the property identifier
211:             * @return the <code>Map</code> containing the key field and the
212:             *         corresponding value 
213:             */
214:            private Map getStrategyKey(Long propertyIdentifier) {
215:                Map map = new HashMap();
216:                map.put(propertyIdentifierColumnName, propertyIdentifier);
217:                return map;
218:            }
219:
220:        }
w___w__w._jav___a__2___s_.c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.