Source Code Cross Referenced for MemStatementIterator.java in  » RSS-RDF » sesame » org » openrdf » sail » memory » model » 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 » RSS RDF » sesame » org.openrdf.sail.memory.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.sail.memory.model;
007:
008:        import java.util.NoSuchElementException;
009:
010:        import info.aduna.iteration.CloseableIterationBase;
011:        import info.aduna.lang.ObjectUtil;
012:
013:        /**
014:         * A StatementIterator that can iterate over a list of Statement objects. This
015:         * iterator compares Resource and Literal objects using the '==' operator, which
016:         * is possible thanks to the extensive sharing of these objects in the
017:         * MemoryStore.
018:         */
019:        public class MemStatementIterator<X extends Exception> extends
020:                CloseableIterationBase<MemStatement, X> {
021:
022:            /*-----------*
023:             * Variables *
024:             *-----------*/
025:
026:            /**
027:             * The lists of statements over which to iterate.
028:             */
029:            private MemStatementList statementList;
030:
031:            /**
032:             * The subject of statements to return, or null if any subject is OK.
033:             */
034:            private MemResource subject;
035:
036:            /**
037:             * The predicate of statements to return, or null if any predicate is OK.
038:             */
039:            private MemURI predicate;
040:
041:            /**
042:             * The object of statements to return, or null if any object is OK.
043:             */
044:            private MemValue object;
045:
046:            /**
047:             * The context of statements to return, or null if any context is OK.
048:             */
049:            private MemResource[] contexts;
050:
051:            /**
052:             * Flag indicating whether this iterator should only return explicitly added
053:             * statements.
054:             */
055:            private boolean explicitOnly;
056:
057:            /**
058:             * Indicates which snapshot should be iterated over.
059:             */
060:            private int snapshot;
061:
062:            /**
063:             * Flag indicating whether or not the iterator should read any non-committed
064:             * changes to the data.
065:             */
066:            private ReadMode readMode;
067:
068:            /**
069:             * The statement to return next.
070:             */
071:            private MemStatement nextStatement;
072:
073:            /**
074:             * The index of the next statement to return.
075:             */
076:            private int nextStatementIdx;
077:
078:            /*--------------*
079:             * Constructors *
080:             *--------------*/
081:
082:            /**
083:             * Creates a new MemStatementIterator that will iterate over the statements
084:             * contained in the supplied MemStatementList searching for statements that
085:             * match the specified pattern of subject, predicate, object and context.
086:             * 
087:             * @param statementList
088:             *        the statements over which to iterate.
089:             * @param subject
090:             *        subject of pattern.
091:             * @param predicate
092:             *        predicate of pattern.
093:             * @param object
094:             *        object of pattern.
095:             * @param context
096:             *        context of pattern.
097:             */
098:            public MemStatementIterator(MemStatementList statementList,
099:                    MemResource subject, MemURI predicate, MemValue object,
100:                    boolean explicitOnly, int snapshot, ReadMode readMode,
101:                    MemResource... contexts) {
102:                this .statementList = statementList;
103:                this .subject = subject;
104:                this .predicate = predicate;
105:                this .object = object;
106:                this .contexts = contexts;
107:                this .explicitOnly = explicitOnly;
108:                this .snapshot = snapshot;
109:                this .readMode = readMode;
110:
111:                this .nextStatementIdx = -1;
112:            }
113:
114:            /*---------*
115:             * Methods *
116:             *---------*/
117:
118:            /**
119:             * Searches through statementList, starting from index
120:             * <tt>_nextStatementIdx + 1</tt>, for statements that match the
121:             * constraints that have been set for this iterator. If a matching statement
122:             * has been found it will be stored in <tt>_nextStatement</tt> and
123:             * <tt>_nextStatementIdx</tt> points to the index of this statement in
124:             * <tt>_statementList</tt>. Otherwise, <tt>_nextStatement</tt> will set
125:             * to <tt>null</tt>.
126:             */
127:            private void findNextStatement() {
128:                nextStatementIdx++;
129:
130:                for (; nextStatementIdx < statementList.size(); nextStatementIdx++) {
131:                    nextStatement = statementList.get(nextStatementIdx);
132:
133:                    if (nextStatement.isInSnapshot(snapshot)
134:                            && (subject == null || subject == nextStatement
135:                                    .getSubject())
136:                            && (predicate == null || predicate == nextStatement
137:                                    .getPredicate())
138:                            && (object == null || object == nextStatement
139:                                    .getObject())) {
140:                        // A matching statement has been found, check if it should be
141:                        // skipped due to explicitOnly, contexts and readMode requirements
142:
143:                        if (contexts != null && contexts.length > 0) {
144:                            boolean matchingContext = false;
145:                            for (int i = 0; i < contexts.length
146:                                    && !matchingContext; i++) {
147:                                matchingContext = ObjectUtil
148:                                        .nullEquals(nextStatement.getContext(),
149:                                                contexts[i]);
150:                            }
151:                            if (!matchingContext) {
152:                                // statement does not appear in one of the specified contexts,
153:                                // skip it.
154:                                continue;
155:                            }
156:                        }
157:
158:                        if (ReadMode.COMMITTED.equals(readMode)) {
159:                            // Only read committed statements
160:
161:                            if (nextStatement.getTxnStatus() == TxnStatus.NEW) {
162:                                // Uncommitted statements, skip it
163:                                continue;
164:                            }
165:                            if (explicitOnly && !nextStatement.isExplicit()) {
166:                                // Explicit statements only; skip inferred ones
167:                                continue;
168:                            }
169:                        } else if (ReadMode.TRANSACTION.equals(readMode)) {
170:                            // Pretend that the transaction has already been committed
171:
172:                            TxnStatus txnStatus = nextStatement.getTxnStatus();
173:
174:                            if (TxnStatus.DEPRECATED.equals(txnStatus)
175:                                    || TxnStatus.ZOMBIE.equals(txnStatus)) {
176:                                // Statement scheduled for removal, skip it
177:                                continue;
178:                            }
179:
180:                            if (explicitOnly) {
181:                                if (!nextStatement.isExplicit()
182:                                        && !TxnStatus.EXPLICIT
183:                                                .equals(txnStatus)
184:                                        || TxnStatus.INFERRED.equals(txnStatus)) {
185:                                    // Explicit statements only; skip inferred ones
186:                                    continue;
187:                                }
188:                            }
189:                        } else if (ReadMode.RAW.equals(readMode)) {
190:                            // Ignore the statement's transaction status, only check the
191:                            // explicitOnly requirement
192:
193:                            if (explicitOnly && !nextStatement.isExplicit()) {
194:                                // Explicit statements only; skip inferred ones
195:                                continue;
196:                            }
197:                        }
198:
199:                        return;
200:                    }
201:                }
202:
203:                // No more matching statements.
204:                nextStatement = null;
205:            }
206:
207:            public boolean hasNext() {
208:                if (nextStatement == null && statementList != null
209:                        && nextStatementIdx < statementList.size()) {
210:                    findNextStatement();
211:                }
212:
213:                return nextStatement != null;
214:            }
215:
216:            public MemStatement next() {
217:                if (statementList == null) {
218:                    throw new NoSuchElementException("Iterator has been closed");
219:                }
220:                if (nextStatement == null
221:                        && nextStatementIdx < statementList.size()) {
222:                    findNextStatement();
223:                }
224:                if (nextStatement == null) {
225:                    throw new NoSuchElementException("No more statements");
226:                }
227:
228:                MemStatement result = nextStatement;
229:                nextStatement = null;
230:                return result;
231:            }
232:
233:            /**
234:             * Throws an UnsupportedOperationException.
235:             */
236:            public void remove() {
237:                throw new UnsupportedOperationException();
238:            }
239:
240:            @Override
241:            protected void handleClose() throws X {
242:                nextStatement = null;
243:                statementList = null;
244:
245:                subject = null;
246:                predicate = null;
247:                object = null;
248:                contexts = null;
249:
250:                super.handleClose();
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.