Source Code Cross Referenced for AbstractFeatureLocking.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » 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 » GIS » GeoTools 2.4.1 » org.geotools.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.data;
017:
018:        import java.io.IOException;
019:        import java.util.NoSuchElementException;
020:        import java.util.Set;
021:
022:        import org.geotools.feature.Feature;
023:        import org.geotools.feature.FeatureIterator;
024:        import org.opengis.filter.Filter;
025:
026:        /**
027:         * A Starting point for your own FeatureLocking implementations.
028:         * 
029:         * <p>
030:         * This class extends AbstractFeatureSource and depends on getDataStore().
031:         * </p>
032:         * The implementation of the following functions depends on
033:         * getDataStore().getLockingManger() not being <code>null</code>:
034:         * 
035:         * <ul>
036:         * <li>
037:         * lockFeatures( Query )
038:         * </li>
039:         * <li>
040:         * unLockFeatures( Query )
041:         * </li>
042:         * <li>
043:         * releaseLock( AuthorizationID )
044:         * </li>
045:         * <li>
046:         * refreshLock( AuthorizationID )
047:         * </li>
048:         * </ul>
049:         * 
050:         * <p>
051:         * FeatureStores that have provided their own locking to will need to override
052:         * the above methods, or provide a custom LockingManger.
053:         * </p>
054:         *
055:         * @author Jody Garnett, Refractions Research
056:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/data/AbstractFeatureLocking.java $
057:         */
058:        public abstract class AbstractFeatureLocking extends
059:                AbstractFeatureStore implements  FeatureLocking {
060:            FeatureLock featureLock = FeatureLock.TRANSACTION;
061:
062:            public AbstractFeatureLocking() {
063:                // just to keep the default constructor around
064:            }
065:
066:            /**
067:             * This constructors allows to set the supported hints 
068:             * @param hints
069:             */
070:            public AbstractFeatureLocking(Set hints) {
071:                super (hints);
072:            }
073:
074:            /**
075:             * Provide a FeatureLock for locking opperations to opperate against.
076:             * 
077:             * <p>
078:             * Initial Transactional duration locks can be restored with
079:             * setFeatureLock( FetaureLock.TRANSACTION )
080:             * </p>
081:             *
082:             * @param lock FeatureLock (or FeatureLock.TRANSACTION );
083:             *
084:             * @throws NullPointerException If lock was <code>null</code>
085:             *
086:             * @see org.geotools.data.FeatureLocking#setFeatureLock(org.geotools.data.FeatureLock)
087:             */
088:            public void setFeatureLock(FeatureLock lock) {
089:                if (lock == null) {
090:                    throw new NullPointerException(
091:                            "A FeatureLock is required - did you mean FeatureLock.TRANSACTION?");
092:                }
093:
094:                featureLock = lock;
095:            }
096:
097:            /**
098:             * Lock all Features
099:             *
100:             * @return Number of Locked features
101:             *
102:             * @throws IOException
103:             *
104:             * @see org.geotools.data.FeatureLocking#lockFeatures()
105:             */
106:            public int lockFeatures() throws IOException {
107:                return lockFeatures(Filter.INCLUDE);
108:            }
109:
110:            /**
111:             * Lock features matching <code>filter</code>.
112:             *
113:             * @param filter
114:             *
115:             * @return Number of locked Features
116:             *
117:             * @throws IOException
118:             */
119:            public int lockFeatures(Filter filter) throws IOException {
120:                return lockFeatures(new DefaultQuery(getSchema().getTypeName(),
121:                        filter));
122:            }
123:
124:            /**
125:             * Lock features matching Query.
126:             * 
127:             * <p>
128:             * FeatureStores that have provided their own locking to will need to
129:             * override this method.
130:             * </p>
131:             *
132:             * @param query
133:             *
134:             * @return Number of locked Features
135:             *
136:             * @throws IOException If we could not determine which feature to lock
137:             *         based on Query
138:             * @throws UnsupportedOperationException When DataStore does not provide a
139:             *         LockingManager
140:             * @throws DataSourceException If feature to be locked does not exist
141:             *
142:             * @see org.geotools.data.FeatureLocking#lockFeatures(org.geotools.data.Query)
143:             */
144:            public int lockFeatures(Query query) throws IOException {
145:                LockingManager lockingManager = getDataStore()
146:                        .getLockingManager();
147:
148:                if (lockingManager == null) {
149:                    throw new UnsupportedOperationException(
150:                            "DataStore not using lockingManager, must provide alternate implementation");
151:                }
152:
153:                // Could we reduce the Query to only return the FetureID here?
154:                //
155:                FeatureIterator reader = getFeatures(query).features();
156:                String typeName = query.getTypeName();
157:                Feature feature;
158:                int count = 0;
159:
160:                try {
161:                    while (reader.hasNext()) {
162:                        try {
163:                            feature = reader.next();
164:                            lockingManager.lockFeatureID(typeName, feature
165:                                    .getID(), getTransaction(), featureLock);
166:                            count++;
167:                        } catch (FeatureLockException locked) {
168:                            // could not aquire - don't increment count                
169:                        } catch (NoSuchElementException nosuch) {
170:                            throw new DataSourceException("Problem with "
171:                                    + query.getHandle() + " while locking",
172:                                    nosuch);
173:                        }
174:                    }
175:                } finally {
176:                    reader.close();
177:                }
178:
179:                return count;
180:            }
181:
182:            /**
183:             * Unlock all Features.
184:             *
185:             * @throws IOException
186:             *
187:             * @see org.geotools.data.FeatureLocking#unLockFeatures()
188:             */
189:            public void unLockFeatures() throws IOException {
190:                unLockFeatures(Filter.INCLUDE);
191:            }
192:
193:            /**
194:             * Unlock Features specified by <code>filter</code>.
195:             *
196:             * @param filter
197:             *
198:             * @throws IOException
199:             */
200:            public void unLockFeatures(Filter filter) throws IOException {
201:                unLockFeatures(new DefaultQuery(getSchema().getTypeName(),
202:                        filter));
203:            }
204:
205:            /**
206:             * Unlock features specified by the <code>query</code>.
207:             * 
208:             * <p>
209:             * FeatureStores that have provided their own locking to will need to
210:             * override this method.
211:             * </p>
212:             *
213:             * @param query
214:             *
215:             * @throws IOException
216:             * @throws UnsupportedOperationException If lockingManager is not provided
217:             *         by DataStore subclass
218:             * @throws DataSourceException Filter describes an unlocked Feature, or
219:             *         authorization not held
220:             *
221:             * @see org.geotools.data.FeatureLocking#unLockFeatures(org.geotools.data.Query)
222:             */
223:            public void unLockFeatures(Query query) throws IOException {
224:                LockingManager lockingManager = getDataStore()
225:                        .getLockingManager();
226:
227:                if (lockingManager == null) {
228:                    throw new UnsupportedOperationException(
229:                            "DataStore not using lockingManager, must provide alternate implementation");
230:                }
231:
232:                // Could we reduce the Query to only return the FetureID here?
233:                //
234:                FeatureIterator reader = getFeatures(query).features();
235:                String typeName = query.getTypeName();
236:                Feature feature;
237:
238:                try {
239:                    while (reader.hasNext()) {
240:                        try {
241:                            feature = reader.next();
242:                            lockingManager.unLockFeatureID(typeName, feature
243:                                    .getID(), getTransaction(), featureLock);
244:                        } catch (NoSuchElementException nosuch) {
245:                            throw new DataSourceException("Problem with "
246:                                    + query.getHandle() + " while locking",
247:                                    nosuch);
248:                        }
249:                    }
250:                } finally {
251:                    reader.close();
252:                }
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.