Source Code Cross Referenced for JDBCReadAheadMetaData.java in  » EJB-Server-JBoss-4.2.1 » server » org » jboss » ejb » plugins » cmp » jdbc » metadata » 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 » EJB Server JBoss 4.2.1 » server » org.jboss.ejb.plugins.cmp.jdbc.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software 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 GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.ejb.plugins.cmp.jdbc.metadata;
023:
024:        import java.util.Arrays;
025:        import java.util.List;
026:        import java.util.Collections;
027:        import java.util.Iterator;
028:
029:        import org.jboss.deployment.DeploymentException;
030:        import org.jboss.metadata.MetaData;
031:
032:        import org.w3c.dom.Element;
033:
034:        /**
035:         * Imutable class which holds all the information about read-ahead settings.
036:         * It loads its data from standardjbosscmp-jdbc.xml and jbosscmp-jdbc.xml
037:         *
038:         * @author <a href="mailto:on@ibis.odessa.ua">Oleg Nitz</a>
039:         * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
040:         * @version $Revision: 57209 $
041:         */
042:        public class JDBCReadAheadMetaData {
043:            public static final JDBCReadAheadMetaData DEFAULT = new JDBCReadAheadMetaData();
044:
045:            /** Don't read ahead. */
046:            private static final byte NONE = 0;
047:
048:            /** Read ahead when some entity is being loaded (lazily, good for all queries). */
049:            private static final byte ON_LOAD = 1;
050:
051:            /** Read ahead during "find" (not lazily, the best for queries with small result set). */
052:            private static final byte ON_FIND = 2;
053:
054:            private static final List STRATEGIES = Arrays.asList(new String[] {
055:                    "none", "on-load", "on-find" });
056:
057:            /** The strategy of reading ahead, one of {@link #NONE}, {@link #ON_LOAD}, {@link #ON_FIND}. */
058:            private final byte strategy;
059:
060:            /** The page size of the read ahead buffer */
061:            private final int pageSize;
062:
063:            /** The name of the load group to eager load. */
064:            private final String eagerLoadGroup;
065:
066:            /** a list of left-join */
067:            private final List leftJoinList;
068:
069:            /**
070:             * Constructs default read ahead meta data: no read ahead.
071:             */
072:            private JDBCReadAheadMetaData() {
073:                strategy = ON_LOAD;
074:                pageSize = 255;
075:                eagerLoadGroup = "*";
076:                leftJoinList = Collections.EMPTY_LIST;
077:            }
078:
079:            /**
080:             * Constructs read ahead meta data with specified strategy, pageSize and
081:             * eagerLoadGroup.
082:             * NOTE: used only in tests.
083:             */
084:            public JDBCReadAheadMetaData(String strategy, int pageSize,
085:                    String eagerLoadGroup) {
086:                this (strategy, pageSize, eagerLoadGroup, Collections.EMPTY_LIST);
087:            }
088:
089:            public JDBCReadAheadMetaData(String strategy, int pageSize,
090:                    String eagerLoadGroup, List leftJoins) {
091:                this .strategy = (byte) STRATEGIES.indexOf(strategy);
092:                if (this .strategy < 0) {
093:                    throw new IllegalArgumentException(
094:                            "Unknown read ahead strategy '" + strategy + "'.");
095:                }
096:                this .pageSize = pageSize;
097:                this .eagerLoadGroup = eagerLoadGroup;
098:                leftJoinList = leftJoins;
099:            }
100:
101:            /**
102:             * Constructs read ahead meta data with the data contained in the read-ahead
103:             * xml element from a jbosscmp-jdbc xml file. Optional values of the xml
104:             * element that are not present are instead loaded from the defalutValues
105:             * parameter.
106:             *
107:             * @param element the xml Element which contains the read-ahead metadata
108:             * @throws DeploymentException if the xml element is invalid
109:             */
110:            public JDBCReadAheadMetaData(Element element,
111:                    JDBCReadAheadMetaData defaultValue)
112:                    throws DeploymentException {
113:                // Strategy
114:                String strategyStr = MetaData.getUniqueChildContent(element,
115:                        "strategy");
116:                strategy = (byte) STRATEGIES.indexOf(strategyStr);
117:                if (strategy < 0) {
118:                    throw new DeploymentException(
119:                            "Unknown read ahead strategy '" + strategyStr
120:                                    + "'.");
121:                }
122:
123:                // page-size
124:                String pageSizeStr = MetaData.getOptionalChildContent(element,
125:                        "page-size");
126:                if (pageSizeStr != null) {
127:                    try {
128:                        pageSize = Integer.parseInt(pageSizeStr);
129:                    } catch (NumberFormatException ex) {
130:                        throw new DeploymentException(
131:                                "Invalid number format in read-ahead page-size '"
132:                                        + pageSizeStr + "': " + ex);
133:                    }
134:                    if (pageSize < 0) {
135:                        throw new DeploymentException(
136:                                "Negative value for read ahead page-size '"
137:                                        + pageSizeStr + "'.");
138:                    }
139:                } else {
140:                    pageSize = defaultValue.getPageSize();
141:                }
142:
143:                // eager-load-group
144:                Element eagerLoadGroupElement = MetaData.getOptionalChild(
145:                        element, "eager-load-group");
146:                if (eagerLoadGroupElement != null) {
147:                    eagerLoadGroup = MetaData
148:                            .getElementContent(eagerLoadGroupElement);
149:                } else {
150:                    eagerLoadGroup = defaultValue.getEagerLoadGroup();
151:                }
152:
153:                // left-join
154:                Iterator iter = MetaData.getChildrenByTagName(element,
155:                        "left-join");
156:                leftJoinList = JDBCLeftJoinMetaData.readLeftJoinList(iter);
157:            }
158:
159:            /**
160:             * Is read ahead strategy is none.
161:             */
162:            public boolean isNone() {
163:                return (strategy == NONE);
164:            }
165:
166:            /**
167:             * Is the read ahead stratey on-load
168:             */
169:            public boolean isOnLoad() {
170:                return (strategy == ON_LOAD);
171:            }
172:
173:            /**
174:             * Is the read ahead stratey on-find
175:             */
176:            public boolean isOnFind() {
177:                return (strategy == ON_FIND);
178:            }
179:
180:            /**
181:             * Gets the read ahead page size.
182:             */
183:            public int getPageSize() {
184:                return pageSize;
185:            }
186:
187:            /**
188:             * Gets the eager load group.
189:             */
190:            public String getEagerLoadGroup() {
191:                return eagerLoadGroup;
192:            }
193:
194:            public Iterator getLeftJoins() {
195:                return leftJoinList.iterator();
196:            }
197:
198:            /**
199:             * Returns a string describing this JDBCReadAheadMetaData.
200:             * @return a string representation of the object
201:             */
202:            public String toString() {
203:                return "[JDBCReadAheadMetaData :" + " strategy="
204:                        + STRATEGIES.get(strategy) + ", pageSize=" + pageSize
205:                        + ", eagerLoadGroup=" + eagerLoadGroup + ", left-join"
206:                        + leftJoinList + "]";
207:            }
208:        }
w_w___w__._ja__va___2___s_.__c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.