1 22 package org.jboss.ejb.plugins.cmp.jdbc.bridge; 23 24 25 import org.jboss.deployment.DeploymentException; 26 import org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager; 27 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCCMPFieldMetaData; 28 import org.jboss.ejb.EntityEnterpriseContext; 29 30 import java.sql.PreparedStatement ; 31 32 38 public abstract class JDBCCMP2xAutoUpdatedFieldBridge extends JDBCCMP2xFieldBridge 39 { 40 42 public JDBCCMP2xAutoUpdatedFieldBridge(JDBCStoreManager manager, 43 JDBCCMPFieldMetaData metadata) 44 throws DeploymentException 45 { 46 super(manager, metadata); 47 defaultFlags |= JDBCEntityBridge.ADD_TO_SET_ON_UPDATE; 48 } 49 50 public JDBCCMP2xAutoUpdatedFieldBridge(JDBCCMP2xFieldBridge cmpField) 51 throws DeploymentException 52 { 53 super( 54 (JDBCStoreManager) cmpField.getManager(), 55 cmpField.getFieldName(), 56 cmpField.getFieldType(), 57 cmpField.getJDBCType(), 58 cmpField.isReadOnly(), cmpField.getReadTimeOut(), 60 cmpField.getPrimaryKeyClass(), 61 cmpField.getPrimaryKeyField(), 62 cmpField, 63 null, cmpField.getColumnName() 65 ); 66 defaultFlags |= JDBCEntityBridge.ADD_TO_SET_ON_UPDATE; cmpField.addDefaultFlag(JDBCEntityBridge.ADD_TO_SET_ON_UPDATE); 68 } 69 70 public void initInstance(EntityEnterpriseContext ctx) 71 { 72 setFirstVersion(ctx); 73 } 74 75 public int setInstanceParameters(PreparedStatement ps, 76 int parameterIndex, 77 EntityEnterpriseContext ctx) 78 { 79 Object value; 80 if(ctx.isValid()) 81 { 82 value = isDirty(ctx) ? getInstanceValue(ctx) : updateVersion(ctx); 85 } 86 else 87 { 88 value = getInstanceValue(ctx); 90 } 91 return setArgumentParameters(ps, parameterIndex, value); 92 } 93 94 public abstract void setFirstVersion(EntityEnterpriseContext ctx); 95 public abstract Object updateVersion(EntityEnterpriseContext ctx); 96 } 97 | Popular Tags |