KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc2 > PersistentContext


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 JavaDoc;
31 import java.sql.SQLException JavaDoc;
32
33 /**
34  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
35  * @version <tt>$Revision: 37459 $</tt>
36  */

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 JavaDoc getFieldValue(int rowIndex)
58    {
59       return row.getFieldValue(rowIndex);
60    }
61
62    public void setFieldValue(int rowIndex, Object JavaDoc value)
63    {
64       row.setFieldValue(rowIndex, value);
65    }
66
67    public void setPk(Object JavaDoc pk) throws DuplicateKeyException JavaDoc
68    {
69       if(pk == null)
70       {
71          throw new IllegalArgumentException JavaDoc("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 JavaDoc, DuplicateKeyException JavaDoc
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