1 19 20 21 package org.apache.cayenne.jpa.bridge; 22 23 import java.util.Collections ; 24 25 import org.apache.cayenne.jpa.map.JpaQueryHint; 26 import org.apache.cayenne.CayenneRuntimeException; 27 import org.apache.cayenne.map.EntityResolver; 28 import org.apache.cayenne.query.Query; 29 import org.apache.cayenne.query.SQLTemplate; 30 31 37 public class JpaSQLTemplate extends JpaIndirectQuery { 38 39 42 @Override 43 protected Query createReplacementQuery(EntityResolver resolver) { 44 SQLTemplate query = new SQLTemplate(); 45 query.setDefaultTemplate(jpaQuery.getQuery()); 46 47 if (parentEntity != null) { 48 query.setRoot(parentEntity); 49 } 50 else if (parentMap != null) { 51 query.setRoot(parentMap); 52 } 53 else { 54 throw new CayenneRuntimeException("Unknown query root. Name: " + getName()); 55 } 56 57 JpaQueryHint dataRowsHint = jpaQuery.getHint(QueryHints.DATA_ROWS_HINT); 59 if (dataRowsHint != null) { 60 query.setFetchingDataRows("true".equalsIgnoreCase(dataRowsHint.getValue())); 61 } 62 63 return query.queryWithParameters(parameters != null 64 ? parameters 65 : Collections.EMPTY_MAP); 66 } 67 68 } 69 | Popular Tags |