1 56 package org.objectstyle.cayenne.dba; 57 58 import org.objectstyle.cayenne.access.jdbc.BatchAction; 59 import org.objectstyle.cayenne.access.jdbc.ProcedureAction; 60 import org.objectstyle.cayenne.access.jdbc.SQLTemplateAction; 61 import org.objectstyle.cayenne.access.jdbc.SQLTemplateSelectAction; 62 import org.objectstyle.cayenne.access.jdbc.SelectAction; 63 import org.objectstyle.cayenne.access.jdbc.UpdateAction; 64 import org.objectstyle.cayenne.map.EntityResolver; 65 import org.objectstyle.cayenne.query.BatchQuery; 66 import org.objectstyle.cayenne.query.ProcedureQuery; 67 import org.objectstyle.cayenne.query.Query; 68 import org.objectstyle.cayenne.query.SQLAction; 69 import org.objectstyle.cayenne.query.SQLActionVisitor; 70 import org.objectstyle.cayenne.query.SQLTemplate; 71 import org.objectstyle.cayenne.query.SelectQuery; 72 73 80 public class JdbcActionBuilder implements SQLActionVisitor { 81 82 protected DbAdapter adapter; 83 protected EntityResolver entityResolver; 84 85 public JdbcActionBuilder(DbAdapter adapter, EntityResolver resolver) { 86 this.adapter = adapter; 87 this.entityResolver = resolver; 88 } 89 90 public SQLAction batchAction(BatchQuery query) { 91 93 boolean useOptimisticLock = query.isUsingOptimisticLocking(); 95 96 boolean runningAsBatch = !useOptimisticLock && adapter.supportsBatchUpdates(); 97 BatchAction action = new BatchAction(query, adapter, entityResolver); 98 action.setBatch(runningAsBatch); 99 return action; 100 } 101 102 public SQLAction procedureAction(ProcedureQuery query) { 103 return new ProcedureAction(query, adapter, entityResolver); 104 } 105 106 public SQLAction objectSelectAction(SelectQuery query) { 107 return new SelectAction(query, adapter, entityResolver); 108 } 109 110 public SQLAction sqlAction(SQLTemplate query) { 111 return query.isSelecting() 112 ? new SQLTemplateSelectAction(query, adapter) 113 : new SQLTemplateAction(query, adapter); 114 } 115 116 public SQLAction updateAction(Query query) { 117 if (query instanceof SQLTemplate) { 118 return new SQLTemplateAction((SQLTemplate) query, adapter); 119 } 120 121 return new UpdateAction(query, adapter, entityResolver); 122 } 123 124 127 public DbAdapter getAdapter() { 128 return adapter; 129 } 130 131 134 public EntityResolver getEntityResolver() { 135 return entityResolver; 136 } 137 } 138 | Popular Tags |