KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > PersistenceCapableMapping


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: PersistenceCapableMapping.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.PersistenceManager;
14 import java.sql.PreparedStatement JavaDoc;
15 import java.sql.ResultSet JavaDoc;
16 import javax.jdo.JDOUserException;
17 import javax.jdo.spi.PersistenceCapable;
18
19
20 public class PersistenceCapableMapping extends OIDMapping
21 {
22     private Class JavaDoc surroundingClass = null;
23
24
25     public PersistenceCapableMapping(DatabaseAdapter dba, Class JavaDoc type)
26     {
27         super(dba, type);
28     }
29
30     public PersistenceCapableMapping(Column col)
31     {
32         super(col);
33     }
34
35     public PersistenceCapableMapping(ClassBaseTable table, int relativeFieldNumber)
36     {
37         this(table.newColumn(relativeFieldNumber));
38
39         surroundingClass = table.getType();
40     }
41
42     public void setObject(PersistenceManager pm, PreparedStatement JavaDoc ps, int param, Object JavaDoc value)
43     {
44         pm.makePersistent(value);
45         super.setObject(pm, ps, param, pm.getObjectId(value));
46     }
47
48     public Object JavaDoc getObject(PersistenceManager pm, ResultSet JavaDoc rs, int param)
49     {
50         return pm.getObjectById(super.getObject(pm, rs, param), surroundingClass, false);
51     }
52
53     public SQLExpression newSQLLiteral(QueryStatement qs, Object JavaDoc value)
54     {
55         return new ObjectLiteral(qs, this, value);
56     }
57
58     public SQLExpression newSQLExpression(QueryStatement qs, QueryStatement.QueryColumn qsc, String JavaDoc fieldName)
59     {
60         return new ObjectFieldExpression(qs, qsc, fieldName, type);
61     }
62 }
63
Popular Tags