Source Code Cross Referenced for HeapDriver.java in  » Database-ORM » XORM » org » xorm » datastore » heap » 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 » Database ORM » XORM » org.xorm.datastore.heap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/heap/HeapDriver.java,v 1.2 2003/09/03 05:03:33 wbiggs Exp $
003:
004:            This file is part of XORM.
005:
006:            XORM is free software; you can redistribute it and/or modify
007:            it under the terms of the GNU General Public License as published by
008:            the Free Software Foundation; either version 2 of the License, or
009:            (at your option) any later version.
010:
011:            XORM 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
014:            GNU General Public License for more details.
015:
016:            You should have received a copy of the GNU General Public License
017:            along with XORM; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:        package org.xorm.datastore.heap;
021:
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Hashtable;
025:        import java.util.Iterator;
026:        import java.util.Set;
027:
028:        import org.xorm.InterfaceManagerFactory;
029:        import org.xorm.cache.DataCache;
030:        import org.xorm.datastore.Column;
031:        import org.xorm.datastore.DatastoreDriver;
032:        import org.xorm.datastore.Row;
033:        import org.xorm.datastore.Table;
034:        import org.xorm.query.Selector;
035:        import org.xorm.query.SimpleCondition;
036:
037:        /**
038:         * An exceedingly useless implementation of the DatastoreDriver
039:         * interface: a non-persisted, in-memory representation of a
040:         * database.  Not a full implementation -- in particular, query
041:         * methods and transactions are not implemented.  But it can be used
042:         * to see when certain operations would occur, or extended for an
043:         * application that wanted to use "fake JDO" and provide its own
044:         * keys for looking up bootstrap objects.
045:         *
046:         * When using this driver, XORM's second-level cache is the actual
047:         * datastore (see HeapDatastore).
048:         *
049:         * @author Wes Biggs
050:         */
051:        public class HeapDriver implements  DatastoreDriver {
052:            private static Hashtable sequences = new Hashtable();
053:
054:            private static synchronized Integer nextSequenceValue(
055:                    String sequence) {
056:                Integer i = (Integer) sequences.get(sequence);
057:                if (i == null) {
058:                    i = new Integer(1);
059:                } else {
060:                    i = new Integer(i.intValue() + 1);
061:                }
062:                sequences.put(sequence, i);
063:                return i;
064:            }
065:
066:            private InterfaceManagerFactory factory;
067:
068:            public HeapDriver(InterfaceManagerFactory factory) {
069:                this .factory = factory;
070:            }
071:
072:            // Transaction methods
073:            public void begin(boolean readOnly) {
074:                System.out.println("HeapDriver: begin");
075:            }
076:
077:            public void commit() {
078:                System.out.println("HeapDriver: commit");
079:            }
080:
081:            public void rollback() {
082:                System.out.println("HeapDriver: rollback");
083:            }
084:
085:            // CRUD methods
086:            public void create(Row row) {
087:                System.out.println("HeapDriver: create "
088:                        + row.getTable().getName());
089:                Column c = row.getTable().getPrimaryKey();
090:                String s = c.getSequence();
091:                if (c.isAutoIncremented() || (s != null)) {
092:                    row.setValue(c, nextSequenceValue(s));
093:                }
094:                factory.getCache().add(row);
095:            }
096:
097:            public void update(Row row) {
098:                System.out.println("HeapDriver: update "
099:                        + row.getTable().getName() + " "
100:                        + row.getPrimaryKeyValue());
101:
102:                factory.getCache().add(row);
103:            }
104:
105:            public void delete(Row row) {
106:                System.out.println("HeapDriver: delete "
107:                        + row.getTable().getName() + " "
108:                        + row.getPrimaryKeyValue());
109:
110:                factory.getCache().remove(row);
111:            }
112:
113:            public Collection select(Selector selector, Set extraRows) {
114:                System.out.println("HeapDriver: select " + selector);
115:                // Assumes we're dealing with a PK selector, not fully implemented.
116:                ArrayList list = new ArrayList();
117:                if (selector.getCondition() instanceof  SimpleCondition) {
118:                    SimpleCondition condition = (SimpleCondition) selector
119:                            .getCondition();
120:                    Table table = selector.getTable();
121:                    Object primaryKey = condition.getValue();
122:                    Row found = factory.getCache().get(table, primaryKey);
123:                    if (found != null) {
124:                        list.add((Row) found.clone());
125:                    }
126:                }
127:                return list;
128:            }
129:
130:            public int count(Selector selector) {
131:                return select(selector, null).size();
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.