1 24 25 package org.objectweb.cjdbc.controller.loadbalancer.policies.createtable; 26 27 import java.util.ArrayList ; 28 29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 30 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 31 32 40 public abstract class CreateTableRule 41 { 42 43 protected ArrayList backendList; 44 45 46 protected int nbOfNodes = 0; 47 48 52 protected String tableName = null; 53 54 protected int policy; 55 56 61 public CreateTableRule(int policy) 62 { 63 this.policy = policy; 64 backendList = new ArrayList (); 65 } 66 67 73 public CreateTableRule(int policy, ArrayList backendList) 74 { 75 if (backendList == null) 76 throw new IllegalArgumentException ( 77 "Null backendList in CreateTableRule constructor"); 78 79 this.policy = policy; 80 this.backendList = backendList; 81 } 82 83 88 public void addBackendName(String name) 89 { 90 backendList.add(name); 91 } 92 93 98 public ArrayList getBackendList() 99 { 100 return backendList; 101 } 102 103 108 public int getNumberOfNodes() 109 { 110 return nbOfNodes; 111 } 112 113 118 public void setNumberOfNodes(int numberOfNodes) 119 { 120 this.nbOfNodes = numberOfNodes; 121 } 122 123 128 public String getTableName() 129 { 130 return tableName; 131 } 132 133 138 public void setTableName(String tableName) 139 { 140 this.tableName = tableName; 141 } 142 143 148 public int getPolicy() 149 { 150 return policy; 151 } 152 153 158 public void setPolicy(int policy) 159 { 160 this.policy = policy; 161 } 162 163 168 public boolean isDefaultRule() 169 { 170 return this.tableName == null; 171 } 172 173 182 public ArrayList getBackends(ArrayList backends) throws CreateTableException 183 { 184 ArrayList clonedList; 185 186 int size = backends.size(); 187 188 if (backendList.size() > 0) 189 { clonedList = new ArrayList (size); 191 for (int i = 0; i < size; i++) 192 { 193 DatabaseBackend db = (DatabaseBackend) backends.get(i); 194 if (db.isWriteEnabled() && backendList.contains(db.getName())) 195 clonedList.add(db); 196 } 197 } 198 else 199 { clonedList = new ArrayList (size); 201 for (int i = 0; i < size; i++) 202 { 203 DatabaseBackend db = (DatabaseBackend) backends.get(i); 204 if (db.isWriteEnabled()) 205 clonedList.add(db); 206 } 207 } 208 209 return clonedList; 210 } 211 212 217 public abstract String getInformation(); 218 219 224 public String getXml() 225 226 { 227 StringBuffer info = new StringBuffer (); 228 info.append("<" + DatabasesXmlTags.ELT_CreateTable + " " 229 + DatabasesXmlTags.ATT_tableName + "=\"" + tableName + "\" " 230 + DatabasesXmlTags.ATT_policy + "=\"" 231 + CreateTablePolicy.getXmlValue(policy) + "\" " 232 + DatabasesXmlTags.ATT_numberOfNodes + "=\"" + nbOfNodes + "\">"); 233 ArrayList list = this.getBackendList(); 234 int count = list.size(); 235 for (int i = 0; i < count; i++) 236 { 237 info 238 .append("<" + DatabasesXmlTags.ELT_BackendName + " " 239 + DatabasesXmlTags.ATT_name + "=\"" + ((String ) list.get(i)) 240 + "\"/>"); 241 } 242 info.append("</" + DatabasesXmlTags.ELT_CreateTable + ">"); 243 return info.toString(); 244 } 245 246 } 247 | Popular Tags |