Source Code Cross Referenced for DeltaListIterator.java in  » ERP-CRM-Financial » jmoney » net » sf » jmoney » isolation » 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 » ERP CRM Financial » jmoney » net.sf.jmoney.isolation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *  JMoney - A Personal Finance Manager
004:         *  Copyright (c) 2005 Nigel Westbury <westbury@users.sourceforge.net>
005:         *
006:         *
007:         *  This program is free software; you can redistribute it and/or modify
008:         *  it under the terms of the GNU General Public License as published by
009:         *  the Free Software Foundation; either version 2 of the License, or
010:         *  (at your option) any later version.
011:         *
012:         *  This program is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         *  GNU General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         *
021:         */
022:
023:        package net.sf.jmoney.isolation;
024:
025:        import java.util.Collection;
026:        import java.util.Iterator;
027:
028:        import net.sf.jmoney.model2.ExtendableObject;
029:        import net.sf.jmoney.model2.IObjectKey;
030:
031:        /**
032:         * Class imlementing an iterator that wraps a iterator of committed
033:         * objects in the datastore,
034:         * but adjusting the elements by applying changes made in
035:         * the transaction.  New elements are added and deleted elements
036:         * are removed from the iteration.  Furthermore, the elements
037:         * returned by the given iterator are adjusted to get the
038:         * uncommitted versions.
039:         * 
040:         * @author Nigel Westbury
041:         */
042:        class DeltaListIterator<E extends ExtendableObject> implements 
043:                Iterator<E> {
044:            TransactionManager transactionManager;
045:            boolean processingCommittedObjects = true;
046:
047:            /**
048:             * This collection contains the uncommitted version
049:             * of objects that have been added
050:             */
051:            Collection<E> addedObjects;
052:
053:            /**
054:             * The object keys in this collection are the keys for
055:             * the committed version of the objects.
056:             */
057:            Collection<IObjectKey> deletedObjects;
058:
059:            Iterator<E> subIterator;
060:
061:            /**
062:             * Always non-null if processingCommittedObjects = true
063:             * Not applicable if processingCommittedObjects = false
064:             */
065:            E nextObject;
066:
067:            /**
068:             * Construct an iterator that iterates the given iterator,
069:             * but adjusting the elements by adding and removing elements
070:             * in the given lists.
071:             * 
072:             * @param committedListIterator
073:             * @param addedObjects list of objects that have been added
074:             * 			in the transaction.  These objects may be either
075:             * 			objects newly created in the transation or may be
076:             * 			uncommitted versions of objects that exist in the
077:             * 			committed datastore (the latter being possible only
078:             * 			if this iterator is being used for an indexed value
079:             * 			list).
080:             * @param deletedObjects list of objects in the committed datastore
081:             * 			that have been deleted in the transaction.  All objects
082:             * 			in this list should be also in the set returned by
083:             * 			committedListIterator.  This list contains the committed
084:             * 			object keys.
085:             */
086:            DeltaListIterator(TransactionManager transactionManager,
087:                    Iterator<E> committedListIterator,
088:                    Collection<E> addedObjects,
089:                    Collection<IObjectKey> deletedObjects) {
090:                this .transactionManager = transactionManager;
091:                subIterator = committedListIterator;
092:                this .addedObjects = addedObjects;
093:                this .deletedObjects = deletedObjects;
094:                setNextObject();
095:            }
096:
097:            public boolean hasNext() {
098:                if (processingCommittedObjects) {
099:                    return true;
100:                } else {
101:                    return subIterator.hasNext();
102:                }
103:            }
104:
105:            /*
106:             * When processing the list of committed objects (the first sub-iteration),
107:             * we always leave the sub-iterator positioned at the next object to be
108:             * returned. That is, we pass any objects in the set that are marked for
109:             * deletion. Doing this enables the hasNext() method to easily return the
110:             * correct result. This does mean we must save the next object to be
111:             * returned because it will have already been fetched from the sub-iterator.
112:             */
113:            public E next() {
114:                if (processingCommittedObjects) {
115:                    E objectToReturn = nextObject;
116:                    setNextObject();
117:                    return objectToReturn;
118:                } else {
119:                    return subIterator.next();
120:                }
121:            }
122:
123:            public void remove() {
124:                throw new RuntimeException("not implemented");
125:            }
126:
127:            /**
128:             * Set nextObject to the first/next object from the committed list that has
129:             * not been marked for deletion, or, if there is no more such objects, set
130:             * up for returning the newly added objects by setting the flag and setting
131:             * the sub-iterator to be an iterator that iterates the newly added objects.
132:             */
133:            private void setNextObject() {
134:                E committedObject;
135:                do {
136:                    if (!subIterator.hasNext()) {
137:                        processingCommittedObjects = false;
138:                        subIterator = addedObjects.iterator();
139:                        return;
140:                    }
141:                    committedObject = subIterator.next();
142:                } while (deletedObjects
143:                        .contains(committedObject.getObjectKey()));
144:
145:                nextObject = transactionManager
146:                        .getCopyInTransaction(committedObject);
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.