Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@jmysql/insertObjMetadataV1.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function id = insertObjMetadataV1(conn, obj, objid) | |
2 % an utility to insert entries for various object metadata in the | |
3 % corresponding tables. uses the old v2.1 database schema. | |
4 % | |
5 % MUST BE KEPT IN SYNC WITH updateObjMetadataV1() | |
6 % | |
7 % conn - Java database connection object | |
8 % obj - object | |
9 % objid - unique ID of the object in the database | |
10 % | |
11 | |
12 import utils.const.* | |
13 | |
14 if nargin < 3 | |
15 error('### incorrect usage'); | |
16 end | |
17 if ~isjava(conn) | |
18 error('### incorrect usage'); | |
19 end | |
20 | |
21 % default output value | |
22 id = []; | |
23 | |
24 % class of object | |
25 cl = class(obj); | |
26 utils.helper.msg(msg.PROC2, 'making meta data entry for %s object', cl); | |
27 | |
28 switch cl | |
29 case 'ao' | |
30 | |
31 % call recursively to insert the data object info | |
32 dataid = utils.jmysql.insertObjMetadataV1(conn, obj.data, objid); | |
33 | |
34 % insert the AO info | |
35 stmt = conn.prepareStatement(... | |
36 'INSERT INTO ao (obj_id, data_type, data_id, description) VALUES (?, ?, ?, ?)'); | |
37 stmt.setObject(1, objid); | |
38 stmt.setObject(2, java.lang.String(class(obj.data))); | |
39 stmt.setObject(3, dataid); | |
40 desc = obj.description; | |
41 if length(desc)>65535 | |
42 warning('Object description length exceeded. Truncating to 65535 characters'); | |
43 desc = desc(1:65535); | |
44 end | |
45 stmt.setObject(4, java.lang.String(desc)); | |
46 stmt.execute(); | |
47 stmt.close(); | |
48 | |
49 case 'cdata' | |
50 | |
51 stmt = conn.prepareStatement(... | |
52 'INSERT INTO cdata (yunits) VALUES (?)'); | |
53 stmt.setObject(1, java.lang.String(char(obj.yunits))); | |
54 stmt.executeUpdate(); | |
55 | |
56 % obtain generated data id | |
57 rs = stmt.getGeneratedKeys(); | |
58 rs.next(); | |
59 id = rs.getInt(1); | |
60 rs.close(); | |
61 stmt.close(); | |
62 | |
63 case 'fsdata' | |
64 | |
65 % possible bad entries | |
66 fs = obj.fs; | |
67 if ~isfinite(fs) | |
68 fs = []; | |
69 end | |
70 | |
71 stmt = conn.prepareStatement(... | |
72 'INSERT INTO fsdata (xunits, yunits, fs) VALUES (?, ?, ?)'); | |
73 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
74 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
75 stmt.setObject(3, fs); | |
76 stmt.executeUpdate(); | |
77 | |
78 % obtain generated data id | |
79 rs = stmt.getGeneratedKeys(); | |
80 rs.next(); | |
81 id = rs.getInt(1); | |
82 rs.close(); | |
83 stmt.close(); | |
84 | |
85 case 'tsdata' | |
86 | |
87 stmt = conn.prepareStatement(... | |
88 'INSERT INTO tsdata (xunits, yunits, fs, t0, nsecs) VALUES (?, ?, ?, ?, ?)'); | |
89 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
90 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
91 stmt.setObject(3, obj.fs); | |
92 stmt.setObject(4, java.lang.String(format(obj.t0, 'yyyy-mm-dd HH:MM:SS', 'UTC'))); | |
93 stmt.setObject(5, obj.nsecs); | |
94 stmt.executeUpdate(); | |
95 | |
96 % obtain generated data id | |
97 rs = stmt.getGeneratedKeys(); | |
98 rs.next(); | |
99 id = rs.getInt(1); | |
100 rs.close(); | |
101 stmt.close(); | |
102 | |
103 case 'xydata' | |
104 | |
105 stmt = conn.prepareStatement(... | |
106 'INSERT INTO xydata (xunits, yunits) VALUES (?, ?)'); | |
107 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
108 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
109 stmt.executeUpdate(); | |
110 | |
111 % obtain generated data id | |
112 rs = stmt.getGeneratedKeys(); | |
113 rs.next(); | |
114 id = rs.getInt(1); | |
115 rs.close(); | |
116 stmt.close(); | |
117 | |
118 case 'mfir' | |
119 | |
120 stmt = conn.prepareStatement(... | |
121 'INSERT INTO mfir (obj_id, in_file, fs) VALUES (?, ?, ?)'); | |
122 stmt.setObject(1, objid); | |
123 stmt.setObject(2, java.lang.String(obj.infile)); | |
124 stmt.setObject(3, obj.fs); | |
125 stmt.execute(); | |
126 stmt.close(); | |
127 | |
128 case 'miir' | |
129 | |
130 stmt = conn.prepareStatement(... | |
131 'INSERT INTO miir (obj_id, in_file, fs) VALUES (?, ?, ?)'); | |
132 stmt.setObject(1, objid); | |
133 stmt.setObject(2, java.lang.String(obj.infile)); | |
134 stmt.setObject(3, obj.fs); | |
135 stmt.execute(); | |
136 stmt.close(); | |
137 | |
138 otherwise | |
139 utils.helper.msg(msg.PROC2, 'no meta data table for %s object', cl); | |
140 | |
141 end | |
142 end |