1 29 30 package com.caucho.amber.field; 31 32 import com.caucho.amber.expr.AmberExpr; 33 import com.caucho.amber.expr.PathExpr; 34 import com.caucho.amber.query.QueryParser; 35 import com.caucho.amber.table.Column; 36 import com.caucho.amber.table.ForeignColumn; 37 import com.caucho.amber.table.LinkColumns; 38 import com.caucho.amber.type.RelatedType; 39 import com.caucho.amber.type.Type; 40 import com.caucho.config.ConfigException; 41 import com.caucho.java.JavaWriter; 42 import com.caucho.log.Log; 43 import com.caucho.util.L10N; 44 45 import javax.persistence.CascadeType; 46 import java.io.IOException ; 47 import java.util.logging.Logger ; 48 49 52 public class CollectionField extends CascadableField { 53 private static final L10N L = new L10N(CollectionField.class); 54 protected static final Logger log = Log.open(CollectionField.class); 55 56 private Type _targetType; 57 58 private LinkColumns _linkColumns; 59 60 private String _table; 61 62 public CollectionField(RelatedType relatedType, 63 String name, 64 CascadeType[] cascadeTypes) 65 throws ConfigException 66 { 67 super(relatedType, name, cascadeTypes); 68 } 69 70 public CollectionField(RelatedType relatedType) 71 { 72 super(relatedType); 73 } 74 75 78 public void setTable(String table) 79 { 80 _table = table; 81 } 82 83 86 public String getTableName() 87 { 88 return _table; 89 } 90 91 94 public void setType(Type targetType) 95 { 96 _targetType = targetType; 97 } 98 99 102 public Type getTargetType() 103 { 104 return _targetType; 105 } 106 107 110 public void setLinkColumns(LinkColumns linkColumns) 111 { 112 _linkColumns = linkColumns; 113 } 114 115 118 public LinkColumns getLinkColumns() 119 { 120 return _linkColumns; 121 } 122 123 129 public void generatePreCascade(JavaWriter out, 130 String aConn, 131 CascadeType cascadeType) 132 throws IOException 133 { 134 if (isCascade(cascadeType)) { 135 136 String getter = "_caucho_field_" + getGetterName(); 138 out.println("if (" + getter + " != null) {"); 139 out.pushDepth(); 140 141 out.println("for (Object o : " + getter + ")"); 142 out.pushDepth(); 143 144 out.print(aConn + "."); 145 146 switch (cascadeType) { 147 case PERSIST: 148 out.print("persistNoChecks"); 149 break; 150 151 case MERGE: 152 out.print("merge"); 153 break; 154 155 case REMOVE: 156 out.print("remove"); 157 break; 158 159 case REFRESH: 160 out.print("refresh"); 161 break; 162 } 163 164 out.println("(o);"); 165 166 out.popDepth(); 167 168 out.popDepth(); 169 out.println("}"); 170 } 171 } 172 173 179 public void generatePostCascade(JavaWriter out, 180 String aConn, 181 CascadeType cascadeType) 182 throws IOException 183 { 184 } 185 186 189 public void generateSet(JavaWriter out, String pstmt, 190 String obj, String index) 191 throws IOException 192 { 193 } 194 195 198 public void generateUpdate(JavaWriter out, String mask, String pstmt, 199 String index) 200 throws IOException 201 { 202 String maskVar = mask + "_" + (getIndex() / 64); 203 long maskValue = (1L << (getIndex() % 64)); 204 205 out.println(); 206 out.println("if ((" + maskVar + " & " + maskValue + "L) != 0) {"); 207 out.pushDepth(); 208 209 generateSet(out, pstmt, index); 210 211 out.popDepth(); 212 out.println("}"); 213 } 214 215 218 public void generateCopyUpdateObject(JavaWriter out, 219 String dst, String src, 220 int updateIndex) 221 throws IOException 222 { 223 } 224 225 228 public String generateLoadSelect(String id) 229 { 230 return null; 231 } 232 233 236 public String generateTargetSelect(String id) 237 { 238 throw new UnsupportedOperationException (getClass().getName()); 239 } 240 241 244 public AmberExpr createExpr(QueryParser parser, PathExpr parent) 245 { 246 throw new UnsupportedOperationException (getClass().getName()); 247 } 248 249 252 public String generateJoin(String sourceTable, String targetTable) 253 { 254 return _linkColumns.generateJoin(sourceTable, targetTable); 255 } 256 257 260 public ForeignColumn getSourceColumn(Column key) 261 { 262 return _linkColumns.getSourceColumn(key); 263 } 264 } 265 | Popular Tags |