1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.dbunit.ext.oracle;
23
24 import java.sql.SQLException;
25 import java.sql.Connection;
26 import oracle.jdbc.OracleTypes;
27 import oracle.sql.ORAData;
28 import oracle.sql.ORADataFactory;
29 import oracle.sql.Datum;
30 import oracle.sql.STRUCT;
31 import oracle.jpub.runtime.MutableStruct;
32
33
34
35
36
37
38
39
40
41
42 public class OracleSdoGeometry implements ORAData, ORADataFactory
43 {
44 public static final String _SQL_NAME = "MDSYS.SDO_GEOMETRY";
45 public static final int _SQL_TYPECODE = OracleTypes.STRUCT;
46
47 protected MutableStruct _struct;
48
49 protected static int[] _sqlType = { 2,2,2002,2003,2003 };
50 protected static ORADataFactory[] _factory = new ORADataFactory[5];
51 static
52 {
53 _factory[2] = OracleSdoPointType.getORADataFactory();
54 _factory[3] = OracleSdoElemInfoArray.getORADataFactory();
55 _factory[4] = OracleSdoOrdinateArray.getORADataFactory();
56 }
57 protected static final OracleSdoGeometry _OracleSdoGeometryFactory = new OracleSdoGeometry();
58
59 public static ORADataFactory getORADataFactory()
60 { return _OracleSdoGeometryFactory; }
61
62 protected void _init_struct(boolean init)
63 { if (init) _struct = new MutableStruct(new Object[5], _sqlType, _factory); }
64 public OracleSdoGeometry()
65 { _init_struct(true); }
66 public OracleSdoGeometry(java.math.BigDecimal sdoGtype, java.math.BigDecimal sdoSrid, OracleSdoPointType sdoPoint, OracleSdoElemInfoArray sdoElemInfo, OracleSdoOrdinateArray sdoOrdinates) throws SQLException
67 { _init_struct(true);
68 setSdoGtype(sdoGtype);
69 setSdoSrid(sdoSrid);
70 setSdoPoint(sdoPoint);
71 setSdoElemInfo(sdoElemInfo);
72 setSdoOrdinates(sdoOrdinates);
73 }
74
75
76 public Datum toDatum(Connection c) throws SQLException
77 {
78 return _struct.toDatum(c, _SQL_NAME);
79 }
80
81
82
83 public ORAData create(Datum d, int sqlType) throws SQLException
84 { return create(null, d, sqlType); }
85 protected ORAData create(OracleSdoGeometry o, Datum d, int sqlType) throws SQLException
86 {
87 if (d == null) return null;
88 if (o == null) o = new OracleSdoGeometry();
89 o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
90 return o;
91 }
92
93 public java.math.BigDecimal getSdoGtype() throws SQLException
94 { return (java.math.BigDecimal) _struct.getAttribute(0); }
95
96 public void setSdoGtype(java.math.BigDecimal sdoGtype) throws SQLException
97 { _struct.setAttribute(0, sdoGtype); }
98
99
100 public java.math.BigDecimal getSdoSrid() throws SQLException
101 { return (java.math.BigDecimal) _struct.getAttribute(1); }
102
103 public void setSdoSrid(java.math.BigDecimal sdoSrid) throws SQLException
104 { _struct.setAttribute(1, sdoSrid); }
105
106
107 public OracleSdoPointType getSdoPoint() throws SQLException
108 { return (OracleSdoPointType) _struct.getAttribute(2); }
109
110 public void setSdoPoint(OracleSdoPointType sdoPoint) throws SQLException
111 { _struct.setAttribute(2, sdoPoint); }
112
113
114 public OracleSdoElemInfoArray getSdoElemInfo() throws SQLException
115 { return (OracleSdoElemInfoArray) _struct.getAttribute(3); }
116
117 public void setSdoElemInfo(OracleSdoElemInfoArray sdoElemInfo) throws SQLException
118 { _struct.setAttribute(3, sdoElemInfo); }
119
120
121 public OracleSdoOrdinateArray getSdoOrdinates() throws SQLException
122 { return (OracleSdoOrdinateArray) _struct.getAttribute(4); }
123
124 public void setSdoOrdinates(OracleSdoOrdinateArray sdoOrdinates) throws SQLException
125 { _struct.setAttribute(4, sdoOrdinates); }
126
127 public String toString()
128 { try {
129 return "MDSYS.SDO_GEOMETRY" + "(" +
130 getSdoGtype() + "," +
131 getSdoSrid() + "," +
132 getSdoPoint() + "," +
133 getSdoElemInfo() + "," +
134 getSdoOrdinates() +
135 ")";
136 } catch (Exception e) { return e.toString(); }
137 }
138
139 public boolean equals(Object obj)
140 {
141 if (this == obj)
142 {
143 return true;
144 }
145
146 if (obj == null || ! obj.getClass().equals(this.getClass()))
147 {
148 return false;
149 }
150
151 OracleSdoGeometry otherSdoGeom = (OracleSdoGeometry) obj;
152
153 try
154 {
155 return
156 OracleSdoHelper.objectsEqual(getSdoGtype(), otherSdoGeom.getSdoGtype()) &&
157 OracleSdoHelper.objectsEqual(getSdoSrid(), otherSdoGeom.getSdoSrid()) &&
158 OracleSdoHelper.objectsEqual(getSdoPoint(), otherSdoGeom.getSdoPoint()) &&
159 OracleSdoHelper.objectsEqual(getSdoElemInfo(), otherSdoGeom.getSdoElemInfo()) &&
160 OracleSdoHelper.objectsEqual(getSdoOrdinates(), otherSdoGeom.getSdoOrdinates());
161 }
162 catch (SQLException ex)
163 {
164 return false;
165 }
166 }
167
168 public int hashCode()
169 {
170 try
171 {
172 int hash = 7;
173 Object o;
174 o = getSdoGtype();
175 hash = 31 * hash + (null == o ? 0 : o.hashCode());
176 o = getSdoSrid();
177 hash = 31 * hash + (null == o ? 0 : o.hashCode());
178 o = getSdoPoint();
179 hash = 31 * hash + (null == o ? 0 : o.hashCode());
180 o = getSdoElemInfo();
181 hash = 31 * hash + (null == o ? 0 : o.hashCode());
182 o = getSdoOrdinates();
183 hash = 31 * hash + (null == o ? 0 : o.hashCode());
184 return hash;
185 }
186 catch (SQLException ex)
187 {
188 return 0;
189 }
190 }
191 }