Source Code Cross Referenced for JDBCFeatureLocking.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » jdbc » 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.jdbc 
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.jdbc;
017:
018:        import java.io.IOException;
019:        import java.util.NoSuchElementException;
020:
021:        import org.geotools.data.DataSourceException;
022:        import org.geotools.data.DefaultQuery;
023:        import org.geotools.data.FeatureLock;
024:        import org.geotools.data.FeatureLockException;
025:        import org.geotools.data.FeatureLocking;
026:        import org.geotools.data.LockingManager;
027:        import org.geotools.data.Query;
028:        import org.geotools.feature.Feature;
029:        import org.geotools.feature.FeatureIterator;
030:        import org.geotools.feature.FeatureType;
031:        import org.opengis.filter.Filter;
032:
033:        /**
034:         * A Starting point for your own FeatureLocking implementations.
035:         * 
036:         * <p>
037:         * This class extends JDBCFeatureSource and depends on getDataStore().
038:         * </p>
039:         * The implementation of the following functions depends on
040:         * getDataStore().getLockingManger() not being <code>null</code>:
041:         * 
042:         * <ul>
043:         * <li>
044:         * lockFeatures( Query )
045:         * </li>
046:         * <li>
047:         * unLockFeatures( Query )
048:         * </li>
049:         * <li>
050:         * releaseLock( AuthorizationID )
051:         * </li>
052:         * <li>
053:         * refreshLock( AuthorizationID )
054:         * </li>
055:         * </ul>
056:         * 
057:         * <p>
058:         * JDBCFeatureLocking that have provided their own locking to will need to
059:         * override the above methods, or provide a custom LockingManger.
060:         * </p>
061:         *
062:         * @author Jody Garnett, Refractions Research
063:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/jdbc/src/main/java/org/geotools/data/jdbc/JDBCFeatureLocking.java $
064:         */
065:        public class JDBCFeatureLocking extends JDBCFeatureStore implements 
066:                FeatureLocking {
067:            FeatureLock featureLock = FeatureLock.TRANSACTION;
068:
069:            public JDBCFeatureLocking(JDBC1DataStore jdbcDataStore,
070:                    FeatureType featureType) {
071:                super (jdbcDataStore, featureType);
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 DOCUMENT ME!
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:            //GEOT-1192
125:            //public int lockFeatures(org.geotools.filter.Filter filter) throws IOException {
126:            //    return lockFeatures(new DefaultQuery(getSchema().getTypeName(), filter));
127:            //}
128:            /**
129:             * Lock features matching Query.
130:             * 
131:             * <p>
132:             * FeatureStores that have provided their own locking to will need to
133:             * override this method.
134:             * </p>
135:             *
136:             * @param query
137:             *
138:             * @return Number of locked Features
139:             *
140:             * @throws IOException DOCUMENT ME!
141:             * @throws UnsupportedOperationException DOCUMENT ME!
142:             * @throws DataSourceException If we have any lock conflicts
143:             *
144:             * @see org.geotools.data.FeatureLocking#lockFeatures(org.geotools.data.Query)
145:             */
146:            public int lockFeatures(Query query) throws IOException {
147:                LockingManager lockingManager = getDataStore()
148:                        .getLockingManager();
149:
150:                if (lockingManager == null) {
151:                    throw new UnsupportedOperationException(
152:                            "DataStore not using lockingManager, must provide alternate implementation");
153:                }
154:
155:                // Could we reduce the Query to only return the FetureID here?
156:                //
157:                FeatureIterator reader = getFeatures(query).features();
158:                String typeName = query.getTypeName();
159:                Feature feature;
160:                int count = 0;
161:
162:                try {
163:                    while (reader.hasNext()) {
164:                        try {
165:                            feature = reader.next();
166:                            lockingManager.lockFeatureID(typeName, feature
167:                                    .getID(), getTransaction(), featureLock);
168:                            count++;
169:                        } catch (FeatureLockException locked) {
170:                            // could not aquire - don't increment count                
171:                        } catch (NoSuchElementException nosuch) {
172:                            throw new DataSourceException("Problem with "
173:                                    + query.getHandle() + " while locking",
174:                                    nosuch);
175:                        }
176:                    }
177:                } finally {
178:                    reader.close();
179:                }
180:
181:                return count;
182:            }
183:
184:            /**
185:             * Unlock all Features.
186:             *
187:             * @throws IOException
188:             *
189:             * @see org.geotools.data.FeatureLocking#unLockFeatures()
190:             */
191:            public void unLockFeatures() throws IOException {
192:                unLockFeatures(Filter.INCLUDE);
193:            }
194:
195:            /**
196:             * Unlock Features specified by <code>filter</code>.
197:             *
198:             * @param filter
199:             *
200:             * @throws IOException
201:             */
202:            public void unLockFeatures(Filter filter) throws IOException {
203:                unLockFeatures(new DefaultQuery(getSchema().getTypeName(),
204:                        filter));
205:            }
206:
207:            /**
208:             * Unlock features specified by the <code>query</code>.
209:             * 
210:             * <p>
211:             * FeatureStores that have provided their own locking to will need to
212:             * override this method.
213:             * </p>
214:             *
215:             * @param query
216:             *
217:             * @throws IOException
218:             * @throws UnsupportedOperationException DOCUMENT ME!
219:             * @throws DataSourceException DOCUMENT ME!
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.