1 19 20 package org.apache.cayenne.dba; 21 22 import org.apache.cayenne.access.jdbc.BatchAction; 23 import org.apache.cayenne.access.jdbc.EJBQLAction; 24 import org.apache.cayenne.access.jdbc.ProcedureAction; 25 import org.apache.cayenne.access.jdbc.SQLTemplateAction; 26 import org.apache.cayenne.access.jdbc.SelectAction; 27 import org.apache.cayenne.access.jdbc.UpdateAction; 28 import org.apache.cayenne.map.EntityResolver; 29 import org.apache.cayenne.query.BatchQuery; 30 import org.apache.cayenne.query.EJBQLQuery; 31 import org.apache.cayenne.query.ProcedureQuery; 32 import org.apache.cayenne.query.Query; 33 import org.apache.cayenne.query.SQLAction; 34 import org.apache.cayenne.query.SQLActionVisitor; 35 import org.apache.cayenne.query.SQLTemplate; 36 import org.apache.cayenne.query.SelectQuery; 37 38 45 public class JdbcActionBuilder implements SQLActionVisitor { 46 47 protected DbAdapter adapter; 48 protected EntityResolver entityResolver; 49 50 public JdbcActionBuilder(DbAdapter adapter, EntityResolver resolver) { 51 this.adapter = adapter; 52 this.entityResolver = resolver; 53 } 54 55 public SQLAction batchAction(BatchQuery query) { 56 58 boolean useOptimisticLock = query.isUsingOptimisticLocking(); 60 61 boolean runningAsBatch = !useOptimisticLock && adapter.supportsBatchUpdates(); 62 BatchAction action = new BatchAction(query, adapter, entityResolver); 63 action.setBatch(runningAsBatch); 64 return action; 65 } 66 67 public SQLAction procedureAction(ProcedureQuery query) { 68 return new ProcedureAction(query, adapter, entityResolver); 69 } 70 71 public SQLAction objectSelectAction(SelectQuery query) { 72 return new SelectAction(query, adapter, entityResolver); 73 } 74 75 public SQLAction sqlAction(SQLTemplate query) { 76 return new SQLTemplateAction(query, adapter); 77 } 78 79 public SQLAction updateAction(Query query) { 80 if (query instanceof SQLTemplate) { 81 return new SQLTemplateAction((SQLTemplate) query, adapter); 82 } 83 84 return new UpdateAction(query, adapter, entityResolver); 85 } 86 87 90 public SQLAction ejbqlAction(EJBQLQuery query) { 91 return new EJBQLAction(query, this, adapter, entityResolver); 92 } 93 94 97 public DbAdapter getAdapter() { 98 return adapter; 99 } 100 101 104 public EntityResolver getEntityResolver() { 105 return entityResolver; 106 } 107 } 108 | Popular Tags |