1 22 package org.jboss.ejb.plugins.cmp.jdbc2; 23 24 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2; 25 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMRFieldBridge2; 26 import org.jboss.ejb.plugins.cmp.jdbc2.schema.EntityTable; 27 import org.jboss.ejb.plugins.cmp.jdbc2.schema.Cache; 28 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge; 29 30 import javax.ejb.DuplicateKeyException ; 31 import java.sql.SQLException ; 32 33 37 public class PersistentContext 38 { 39 private final EntityTable.Row row; 40 private final JDBCCMRFieldBridge2.FieldState[] cmrStates; 41 42 public PersistentContext(JDBCEntityBridge2 entity, EntityTable.Row row) 43 { 44 this.row = row; 45 46 JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields(); 47 if(cmrFields != null) 48 { 49 cmrStates = new JDBCCMRFieldBridge2.FieldState[cmrFields.length]; 50 } 51 else 52 { 53 cmrStates = null; 54 } 55 } 56 57 public Object getFieldValue(int rowIndex) 58 { 59 return row.getFieldValue(rowIndex); 60 } 61 62 public void setFieldValue(int rowIndex, Object value) 63 { 64 row.setFieldValue(rowIndex, value); 65 } 66 67 public void setPk(Object pk) throws DuplicateKeyException 68 { 69 if(pk == null) 70 { 71 throw new IllegalArgumentException ("Primary key is null!"); 72 } 73 74 row.insert(pk); 75 } 76 77 public boolean isDirty() 78 { 79 return row.isDirty(); 80 } 81 82 public void setDirty() 83 { 84 row.setDirty(); 85 } 86 87 public void setDirtyRelations() 88 { 89 row.setDirtyRelations(); 90 } 91 92 public void remove() 93 { 94 row.delete(); 95 } 96 97 public JDBCCMRFieldBridge2.FieldState getCMRState(int cmrIndex) 98 { 99 return cmrStates[cmrIndex]; 100 } 101 102 public void setCMRState(int cmrIndex, JDBCCMRFieldBridge2.FieldState state) 103 { 104 cmrStates[cmrIndex] = state; 105 } 106 107 public void loadCachedRelations(int cmrIndex, Cache.CacheLoader loader) 108 { 109 row.loadCachedRelations(cmrIndex, loader); 110 } 111 112 public void cacheRelations(int cmrIndex, Cache.CacheLoader loader) 113 { 114 row.cacheRelations(cmrIndex, loader); 115 } 116 117 public void flush() throws SQLException , DuplicateKeyException 118 { 119 row.flush(); 120 } 121 122 public void nullForeignKey(EntityTable.ForeignKeyConstraint constraint) 123 { 124 row.nullForeignKey(constraint); 125 } 126 127 public void nonNullForeignKey(EntityTable.ForeignKeyConstraint constraint) 128 { 129 row.nonNullForeignKey(constraint); 130 } 131 } 132 | Popular Tags |