Source Code Cross Referenced for CreateTableRule.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » controller » loadbalancer » policies » createtable » 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 JDBC Connection Pool » sequoia 2.10.9 » org.continuent.sequoia.controller.loadbalancer.policies.createtable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Sequoia: Database clustering technology.
003:         * Copyright (C) 2002-2004 French National Institute For Research In Computer
004:         * Science And Control (INRIA).
005:         * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006:         * Contact: sequoia@continuent.org
007:         * 
008:         * Licensed under the Apache License, Version 2.0 (the "License");
009:         * you may not use this file except in compliance with the License.
010:         * You may obtain a copy of the License at
011:         * 
012:         * http://www.apache.org/licenses/LICENSE-2.0
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License. 
019:         *
020:         * Initial developer(s): Emmanuel Cecchet.
021:         * Contributor(s): Jean-Bernard van Zuylen
022:         */package org.continuent.sequoia.controller.loadbalancer.policies.createtable;
023:
024:        import java.util.ArrayList;
025:
026:        import org.continuent.sequoia.common.xml.DatabasesXmlTags;
027:        import org.continuent.sequoia.controller.backend.DatabaseBackend;
028:
029:        /**
030:         * Defines the policy to adopt when creating a new table.
031:         * 
032:         * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
033:         * @author <a href="mailto:jbvanzuylen@transwide.com">Jean-Bernard van Zuylen
034:         *         </a>
035:         * @version 1.0
036:         */
037:        public abstract class CreateTableRule {
038:            /** List of backend names to wait for. */
039:            protected ArrayList backendList;
040:
041:            /** Number of nodes that must create the table. */
042:            protected int nbOfNodes = 0;
043:
044:            /**
045:             * Table name pattern to which this rule apply (null means it is the default
046:             * rule).
047:             */
048:            protected String tableName = null;
049:
050:            protected int policy;
051:
052:            /**
053:             * Constructor for CreateTableRule.
054:             * 
055:             * @param policy the implemented policy
056:             */
057:            public CreateTableRule(int policy) {
058:                this .policy = policy;
059:                backendList = new ArrayList();
060:            }
061:
062:            /**
063:             * Creates a new <code>CreateTableRule</code> instance.
064:             * 
065:             * @param policy the implemented policy
066:             * @param backendList the backend list to use
067:             */
068:            public CreateTableRule(int policy, ArrayList backendList) {
069:                if (backendList == null)
070:                    throw new IllegalArgumentException(
071:                            "Null backendList in CreateTableRule constructor");
072:
073:                this .policy = policy;
074:                this .backendList = backendList;
075:            }
076:
077:            /**
078:             * Add a backend name to the list of backends to wait for.
079:             * 
080:             * @param name backend name
081:             */
082:            public void addBackendName(String name) {
083:                backendList.add(name);
084:            }
085:
086:            /**
087:             * Returns the backendList.
088:             * 
089:             * @return ArrayList
090:             */
091:            public ArrayList getBackendList() {
092:                return backendList;
093:            }
094:
095:            /**
096:             * Returns the number of nodes.
097:             * 
098:             * @return an <code>int</code> value
099:             */
100:            public int getNumberOfNodes() {
101:                return nbOfNodes;
102:            }
103:
104:            /**
105:             * Sets the number of nodes.
106:             * 
107:             * @param numberOfNodes the number of nodes to set
108:             */
109:            public void setNumberOfNodes(int numberOfNodes) {
110:                this .nbOfNodes = numberOfNodes;
111:            }
112:
113:            /**
114:             * Returns the table name.
115:             * 
116:             * @return a <code>String</code> value
117:             */
118:            public String getTableName() {
119:                return tableName;
120:            }
121:
122:            /**
123:             * Sets the table name.
124:             * 
125:             * @param tableName the table name to set
126:             */
127:            public void setTableName(String tableName) {
128:                this .tableName = tableName;
129:            }
130:
131:            /**
132:             * Returns the policy.
133:             * 
134:             * @return an <code>int</code> value
135:             */
136:            public int getPolicy() {
137:                return policy;
138:            }
139:
140:            /**
141:             * Sets the policy.
142:             * 
143:             * @param policy the policy to set
144:             */
145:            public void setPolicy(int policy) {
146:                this .policy = policy;
147:            }
148:
149:            /**
150:             * Returns <code>true</code> if this rule is the default rule.
151:             * 
152:             * @return <code>boolean</code>
153:             */
154:            public boolean isDefaultRule() {
155:                return this .tableName == null;
156:            }
157:
158:            /**
159:             * Pickups backends from the given backends arraylist according to the current
160:             * rule policy.
161:             * 
162:             * @param backends backends to choose from
163:             * @return <code>Arraylist</code> of choosen <code>DatabaseBackend</code>
164:             * @throws CreateTableException in some specific implementations (not this
165:             *           one)
166:             */
167:            public ArrayList getBackends(ArrayList backends)
168:                    throws CreateTableException {
169:                ArrayList clonedList;
170:
171:                int size = backends.size();
172:
173:                if (backendList.size() > 0) { // Keep only the backends that are affected by this rule
174:                    clonedList = new ArrayList(size);
175:                    for (int i = 0; i < size; i++) {
176:                        DatabaseBackend db = (DatabaseBackend) backends.get(i);
177:                        if (db.isWriteEnabled()
178:                                && backendList.contains(db.getName()))
179:                            clonedList.add(db);
180:                    }
181:                } else { // Take all enabled backends
182:                    clonedList = new ArrayList(size);
183:                    for (int i = 0; i < size; i++) {
184:                        DatabaseBackend db = (DatabaseBackend) backends.get(i);
185:                        if (db.isWriteEnabled())
186:                            clonedList.add(db);
187:                    }
188:                }
189:
190:                return clonedList;
191:            }
192:
193:            /**
194:             * Gives information about the current policy.
195:             * 
196:             * @return a <code>String</code> value
197:             */
198:            public abstract String getInformation();
199:
200:            /**
201:             * Gives information about the current policy in xml
202:             * 
203:             * @return a <code>String</code> value in xml
204:             */
205:            public String getXml()
206:
207:            {
208:                StringBuffer info = new StringBuffer();
209:                info.append("<" + DatabasesXmlTags.ELT_CreateTable + " "
210:                        + DatabasesXmlTags.ATT_tableName + "=\"" + tableName
211:                        + "\" " + DatabasesXmlTags.ATT_policy + "=\""
212:                        + CreateTablePolicy.getXmlValue(policy) + "\" "
213:                        + DatabasesXmlTags.ATT_numberOfNodes + "=\""
214:                        + nbOfNodes + "\">");
215:                ArrayList list = this .getBackendList();
216:                int count = list.size();
217:                for (int i = 0; i < count; i++) {
218:                    info.append("<" + DatabasesXmlTags.ELT_BackendName + " "
219:                            + DatabasesXmlTags.ATT_name + "=\""
220:                            + ((String) list.get(i)) + "\"/>");
221:                }
222:                info.append("</" + DatabasesXmlTags.ELT_CreateTable + ">");
223:                return info.toString();
224:            }
225:
226:        }
w__w__w___.j___a__v___a2___s.___c___o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.