KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > DaffodilDBRef


1 package in.co.daffodil.db.jdbc;
2
3 import java.sql.*;
4 import com.daffodilwoods.database.resource.*;
5 import java.util.*;
6 import java.lang.*;
7
8 public class DaffodilDBRef implements Ref
9 {
10    String JavaDoc baseTypeName;
11    byte[] values;
12    SQLInput sqlInput;
13    Map sqlJavaTypeMap;
14
15    public DaffodilDBRef(byte[] values,String JavaDoc baseTypeName)
16    {
17      this.values = values;
18      this.baseTypeName = baseTypeName;
19    }
20
21     /**
22      * Retrieves the fully-qualified SQL name of the SQL structured type that
23      * this <code>Ref</code> object references.
24      */

25    public String JavaDoc getBaseTypeName() throws SQLException
26    {
27      return baseTypeName;
28    }
29
30     /**
31      * Retrieves the referenced object and maps it to a Java type
32      * using the given type map.
33      *
34      * @param map a <code>java.util.Map</code> object that contains
35      * the mapping to use (the fully-qualified name of the SQL
36      * structured type being referenced and the class object for
37      * <code>SQLData</code> implementation to which the SQL
38      * structured type will be mapped)
39      * @return a Java <code>Object</code> that is the custom mapping for
40      * the SQL structured type to which this <code>DRef</code>
41      * object refers
42      */

43    public Object JavaDoc getObject(java.util.Map JavaDoc map) throws SQLException
44    {
45      Object JavaDoc javaType = map.get(baseTypeName);
46      Object JavaDoc element = null;
47      if(javaType == null){
48        element = null;//new DStruct(values);
49
}
50      else{
51       try{
52        element = ((Class JavaDoc)(javaType)).newInstance();
53       } catch (Exception JavaDoc ex){
54
55       }
56      }
57      SQLData sqlData = (SQLData)(element);
58      sqlData.readSQL(sqlInput,baseTypeName);
59      return element;
60
61    }
62
63
64     /**
65      * Retrieves the SQL structured type instance referenced by
66      * this <code>DRef</code> object. If the connection's type map has an entry
67      * for the structured type, the instance will be custom mapped to
68      * the Java class indicated in the type map. Otherwise, the
69      * structured type instance will be mapped to a <code>Struct</code> object.
70      *
71      * @return a Java <code>Object</code> that is the mapping for
72      * the SQL structured type to which this <code>DRef</code>
73      * object refers
74      */

75     public Object JavaDoc getObject() throws SQLException
76     {
77        return getObject(sqlJavaTypeMap);
78     }
79
80     /**
81      * Sets the structured type value that this <code>DRef</code>
82      * object references to the given instance of <code>Object</code>.
83      * The driver converts this to an SQL structured type when it
84      * sends it to the database.
85      *
86      * @param value an <code>Object</code> representing the SQL
87      * structured type instance that this
88      * <code>DRef</code> object will reference
89      */

90      public void setObject(Object JavaDoc value) throws SQLException
91      {
92         SQLData sqlData = (SQLData)value;
93         SQLOutput sqlOutPut = null;
94         sqlData.writeSQL(sqlOutPut);
95      }
96
97  }
98
Popular Tags