Source Code Cross Referenced for UndoLogRecord.java in  » Database-DBMS » h2database » org » h2 » log » 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 DBMS » h2database » org.h2.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.log;
007:
008:        import java.sql.SQLException;
009:
010:        import org.h2.constant.ErrorCode;
011:        import org.h2.constant.SysProperties;
012:        import org.h2.engine.Constants;
013:        import org.h2.engine.Session;
014:        import org.h2.index.Cursor;
015:        import org.h2.index.Index;
016:        import org.h2.message.Message;
017:        import org.h2.result.Row;
018:        import org.h2.store.DataPage;
019:        import org.h2.store.FileStore;
020:        import org.h2.table.Table;
021:        import org.h2.util.ObjectArray;
022:        import org.h2.value.Value;
023:
024:        /**
025:         * An entry in a undo log.
026:         */
027:        public class UndoLogRecord {
028:            public static final short INSERT = 0, DELETE = 1;
029:            private static final int IN_MEMORY = 0, STORED = 1,
030:                    IN_MEMORY_READ_POS = 2;
031:            private Table table;
032:            private Row row;
033:            private short operation;
034:            private short state;
035:            private int filePos;
036:
037:            public boolean isStored() {
038:                return state == STORED;
039:            }
040:
041:            public boolean canStore() {
042:                return table.getUniqueIndex() != null;
043:            }
044:
045:            public UndoLogRecord(Table table, short op, Row row) {
046:                this .table = table;
047:                this .row = row;
048:                this .operation = op;
049:                this .state = IN_MEMORY;
050:            }
051:
052:            public void undo(Session session) throws SQLException {
053:                switch (operation) {
054:                case INSERT:
055:                    if (state == IN_MEMORY_READ_POS) {
056:                        Index index = table.getUniqueIndex();
057:                        Cursor cursor = index.find(session, row, row);
058:                        cursor.next();
059:                        int pos = cursor.getPos();
060:                        row.setPos(pos);
061:                        state = IN_MEMORY;
062:                    }
063:                    if (session.getDatabase().getLockMode() == Constants.LOCK_MODE_OFF) {
064:                        if (row.getDeleted()) {
065:                            // it might have been deleted by another thread
066:                            return;
067:                        }
068:                    }
069:                    try {
070:                        table.removeRow(session, row);
071:                    } catch (SQLException e) {
072:                        if (session.getDatabase().getLockMode() == Constants.LOCK_MODE_OFF
073:                                && e.getErrorCode() == ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1) {
074:                            // it might have been deleted by another thread
075:                            // ignore
076:                        } else {
077:                            throw e;
078:                        }
079:                    }
080:                    break;
081:                case DELETE:
082:                    try {
083:                        row.setPos(0);
084:                        table.addRow(session, row);
085:                    } catch (SQLException e) {
086:                        if (session.getDatabase().getLockMode() == Constants.LOCK_MODE_OFF
087:                                && e.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
088:                            // it might have been added by another thread
089:                            // ignore
090:                        } else {
091:                            throw e;
092:                        }
093:                    }
094:                    break;
095:                default:
096:                    throw Message.getInternalError("op=" + operation);
097:                }
098:            }
099:
100:            public void save(DataPage buff, FileStore file) throws SQLException {
101:                buff.reset();
102:                buff.writeInt(0);
103:                buff.writeInt(operation);
104:                buff.writeInt(row.getColumnCount());
105:                for (int i = 0; i < row.getColumnCount(); i++) {
106:                    buff.writeValue(row.getValue(i));
107:                }
108:                buff.fillAligned();
109:                buff.setInt(0, buff.length() / Constants.FILE_BLOCK_SIZE);
110:                buff.updateChecksum();
111:                filePos = (int) (file.getFilePointer() / Constants.FILE_BLOCK_SIZE);
112:                file.write(buff.getBytes(), 0, buff.length());
113:                row = null;
114:                state = STORED;
115:            }
116:
117:            public void seek(FileStore file) throws SQLException {
118:                file.seek(filePos * Constants.FILE_BLOCK_SIZE);
119:            }
120:
121:            public void load(DataPage buff, FileStore file, Session session)
122:                    throws SQLException {
123:                int min = Constants.FILE_BLOCK_SIZE;
124:                seek(file);
125:                buff.reset();
126:                file.readFully(buff.getBytes(), 0, min);
127:                int len = buff.readInt() * Constants.FILE_BLOCK_SIZE;
128:                buff.checkCapacity(len);
129:                if (len - min > 0) {
130:                    file.readFully(buff.getBytes(), min, len - min);
131:                }
132:                buff.check(len);
133:                int op = buff.readInt();
134:                if (SysProperties.CHECK) {
135:                    if (operation != op) {
136:                        throw Message.getInternalError("operation=" + operation
137:                                + " op=" + op);
138:                    }
139:                }
140:                int columnCount = buff.readInt();
141:                Value[] values = new Value[columnCount];
142:                for (int i = 0; i < columnCount; i++) {
143:                    values[i] = buff.readValue();
144:                }
145:                row = new Row(values, 0);
146:                state = IN_MEMORY_READ_POS;
147:            }
148:
149:            public Table getTable() {
150:                return table;
151:            }
152:
153:            public void commit() throws SQLException {
154:                ObjectArray list = table.getIndexes();
155:                for (int i = 0; i < list.size(); i++) {
156:                    Index index = (Index) list.get(i);
157:                    index.commit(operation, row);
158:                }
159:            }
160:
161:            public Row getRow() {
162:                return row;
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.