1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.util.Arrays ; 25 import java.util.List ; 26 import java.util.Collections ; 27 import java.util.Iterator ; 28 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.metadata.MetaData; 31 32 import org.w3c.dom.Element ; 33 34 42 public class JDBCReadAheadMetaData 43 { 44 public static final JDBCReadAheadMetaData DEFAULT = new JDBCReadAheadMetaData(); 45 46 47 private static final byte NONE = 0; 48 49 50 private static final byte ON_LOAD = 1; 51 52 53 private static final byte ON_FIND = 2; 54 55 private static final List STRATEGIES = Arrays.asList(new String []{"none", "on-load", "on-find"}); 56 57 58 private final byte strategy; 59 60 61 private final int pageSize; 62 63 64 private final String eagerLoadGroup; 65 66 67 private final List leftJoinList; 68 69 72 private JDBCReadAheadMetaData() 73 { 74 strategy = ON_LOAD; 75 pageSize = 255; 76 eagerLoadGroup = "*"; 77 leftJoinList = Collections.EMPTY_LIST; 78 } 79 80 85 public JDBCReadAheadMetaData(String strategy, int pageSize, String eagerLoadGroup) 86 { 87 this(strategy, pageSize, eagerLoadGroup, Collections.EMPTY_LIST); 88 } 89 90 public JDBCReadAheadMetaData(String strategy, int pageSize, String eagerLoadGroup, List leftJoins) 91 { 92 this.strategy = (byte)STRATEGIES.indexOf(strategy); 93 if(this.strategy < 0) 94 { 95 throw new IllegalArgumentException ("Unknown read ahead strategy '" + strategy + "'."); 96 } 97 this.pageSize = pageSize; 98 this.eagerLoadGroup = eagerLoadGroup; 99 leftJoinList = leftJoins; 100 } 101 102 111 public JDBCReadAheadMetaData(Element element, JDBCReadAheadMetaData defaultValue) 112 throws DeploymentException 113 { 114 String strategyStr = MetaData.getUniqueChildContent(element, "strategy"); 116 strategy = (byte)STRATEGIES.indexOf(strategyStr); 117 if(strategy < 0) 118 { 119 throw new DeploymentException("Unknown read ahead strategy '" + strategyStr + "'."); 120 } 121 122 String pageSizeStr = MetaData.getOptionalChildContent(element, "page-size"); 124 if(pageSizeStr != null) 125 { 126 try 127 { 128 pageSize = Integer.parseInt(pageSizeStr); 129 } 130 catch(NumberFormatException ex) 131 { 132 throw new DeploymentException("Invalid number format in read-ahead page-size '" + pageSizeStr + "': " + ex); 133 } 134 if(pageSize < 0) 135 { 136 throw new DeploymentException("Negative value for read ahead page-size '" + pageSizeStr + "'."); 137 } 138 } 139 else 140 { 141 pageSize = defaultValue.getPageSize(); 142 } 143 144 Element eagerLoadGroupElement = MetaData.getOptionalChild(element, "eager-load-group"); 146 if(eagerLoadGroupElement != null) 147 { 148 eagerLoadGroup = MetaData.getElementContent(eagerLoadGroupElement); 149 } 150 else 151 { 152 eagerLoadGroup = defaultValue.getEagerLoadGroup(); 153 } 154 155 Iterator iter = MetaData.getChildrenByTagName(element, "left-join"); 157 leftJoinList = JDBCLeftJoinMetaData.readLeftJoinList(iter); 158 } 159 160 163 public boolean isNone() 164 { 165 return (strategy == NONE); 166 } 167 168 171 public boolean isOnLoad() 172 { 173 return (strategy == ON_LOAD); 174 } 175 176 179 public boolean isOnFind() 180 { 181 return (strategy == ON_FIND); 182 } 183 184 187 public int getPageSize() 188 { 189 return pageSize; 190 } 191 192 195 public String getEagerLoadGroup() 196 { 197 return eagerLoadGroup; 198 } 199 200 public Iterator getLeftJoins() 201 { 202 return leftJoinList.iterator(); 203 } 204 205 209 public String toString() 210 { 211 return "[JDBCReadAheadMetaData :" + 212 " strategy=" + STRATEGIES.get(strategy) + 213 ", pageSize=" + pageSize + 214 ", eagerLoadGroup=" + eagerLoadGroup + 215 ", left-join" + leftJoinList + "]"; 216 } 217 } 218 | Popular Tags |