1 25 26 27 package org.objectweb.jonas_ejb.deployment.api; 28 29 import java.io.CharArrayReader ; 30 import java.lang.reflect.Method ; 31 32 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL; 33 import org.objectweb.jonas_ejb.deployment.ejbql.EJBQL; 34 import org.objectweb.jonas_ejb.deployment.ejbql.ParseException; 35 import org.objectweb.jonas_ejb.lib.EjbqlQueryTreeHolder; 36 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 37 import org.objectweb.jorm.api.PMapper; 38 39 40 45 public class MethodCmp2Desc extends MethodDesc { 46 47 protected String query = null; 48 protected ASTEJBQL queryNode = null; 49 protected EjbqlQueryTreeHolder queryTreeHolder = null; 50 protected boolean resultTypeMappingRemote = false; 51 protected EntityDesc entityDesc; 52 53 54 57 MethodCmp2Desc(BeanDesc beanDesc, Method meth, Class classDef, int index) { 58 super(beanDesc, meth, classDef, index); 59 entityDesc = (EntityDesc) beanDesc; 60 } 61 62 66 public String getQuery() { 67 return query; 68 } 69 70 74 public void setQuery(String query) throws ParseException { 75 this.query = query.replace('\r',' ').replace('\n',' ').replace('\t',' '); 77 EJBQL parser = new EJBQL(new CharArrayReader (query.toCharArray())); 78 queryNode = (ASTEJBQL)parser.EJBQL(); 79 queryTreeHolder=null; 80 } 81 82 83 86 public EjbqlQueryTreeHolder getQueryTreeHolder(PMapper mapper) throws DeploymentDescException { 87 if (queryTreeHolder==null) { 88 try { 89 queryTreeHolder = new EjbqlQueryTreeHolder(this, queryNode, mapper); 90 } catch (Exception e) { 91 throw new DeploymentDescException("ejbql query "+query+" does not map to the persistent schema",e); 92 } 93 } 94 return queryTreeHolder; 95 } 96 97 101 public boolean isResultTypeMappingRemote() { 102 return resultTypeMappingRemote; 103 } 104 105 108 public void setResultTypeMapping(String resultTypeMapping) 109 throws DeploymentDescException { 110 if (resultTypeMapping.equals("Remote")) { 111 resultTypeMappingRemote=true; 112 } else if (resultTypeMapping.equals("Local")) { 113 resultTypeMappingRemote=false; 114 } else { 115 throw new DeploymentDescException(resultTypeMapping+" is not a valid result-type-mapping value"); 116 } 117 } 118 119 123 public boolean getPrefetch() { 124 if (this.isFinder()) { 125 return entityDesc.isPrefetch(); 126 } else { 127 return false; 128 } 129 } 130 131 132 137 public static String queryMethodElementToString(org.objectweb.jonas_ejb.deployment.xml.QueryMethod m) { 138 return methodElementToString(null, m.getMethodName(),m.getMethodParams()); 139 } 140 141 145 public String toString() { 146 StringBuffer ret = new StringBuffer (); 147 ret.append(super.toString()); 148 ret.append("\nquery = " + query); 149 ret.append("\nqueryNode = " + queryNode); 150 ret.append("\nqueryTreeHolder = " + queryTreeHolder); 151 ret.append("\nresultTypeMappingRemote = " + resultTypeMappingRemote); 152 return ret.toString(); 153 } 154 155 } 156 | Popular Tags |