Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@jmysql/updateObjMetadataV1.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 = updateObjMetadataV1(conn, obj, objid) | |
2 % an utility to update 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 insertObjMetadataV1() | |
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 return 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 % get data type and id | |
32 stmt = conn.prepareStatement(... | |
33 'SELECT data_id, data_type FROM ao WHERE obj_id = ?'); | |
34 stmt.setObject(1, objid); | |
35 rs = stmt.executeQuery(); | |
36 rs.next(); | |
37 dataid = rs.getInt(1); | |
38 datatype = rs.getString(2); | |
39 rs.close(); | |
40 stmt.close(); | |
41 | |
42 % check if the data type is consistent | |
43 if ~strcmp(datatype, class(obj.data)) | |
44 error('### cannot update an object with one having a different data type'); | |
45 end | |
46 | |
47 % call recursively to insert the data object info | |
48 id = utils.jmysql.updateObjMetadataV1(conn, obj.data, dataid); | |
49 | |
50 % update ao description | |
51 stmt = conn.prepareStatement(... | |
52 'UPDATE ao SET description=? WHERE obj_id = ?'); | |
53 desc = obj.description; | |
54 if length(desc)>65535 | |
55 warning('Object description length exceeded. Truncating to 65535 characters'); | |
56 desc = desc(1:65535); | |
57 end | |
58 stmt.setObject(1, desc); | |
59 stmt.setObject(2, objid); | |
60 stmt.execute(); | |
61 stmt.close(); | |
62 | |
63 case 'cdata' | |
64 | |
65 stmt = conn.prepareStatement(... | |
66 'UPDATE cdata SET yunits=? WHERE id = ?'); | |
67 stmt.setObject(1, char(obj.yunits)); | |
68 stmt.setObject(2, objid); | |
69 stmt.execute(); | |
70 stmt.close(); | |
71 | |
72 case 'fsdata' | |
73 | |
74 % possible bad entries | |
75 fs = obj.fs; | |
76 if ~isfinite(fs) | |
77 fs = []; | |
78 end | |
79 | |
80 stmt = conn.prepareStatement(... | |
81 'UPDATE fsdata SET xunits=?, yunits=?, fs=? WHERE id = ?'); | |
82 stmt.setObject(1, char(obj.xunits)); | |
83 stmt.setObject(2, char(obj.yunits)); | |
84 stmt.setObject(3, fs); | |
85 stmt.setObject(4, objid); | |
86 stmt.execute(); | |
87 stmt.close(); | |
88 | |
89 case 'tsdata' | |
90 | |
91 stmt = conn.prepareStatement(... | |
92 'UPDATE tsdata SET xunits=?, yunits=?, fs=?, t0=?, nsecs=? WHERE id = ?'); | |
93 stmt.setObject(1, char(obj.xunits)); | |
94 stmt.setObject(2, char(obj.yunits)); | |
95 stmt.setObject(3, obj.fs); | |
96 stmt.setObject(4, format(obj.t0, 'yyyy-mm-dd HH:MM:SS', 'UTC')); | |
97 stmt.setObject(5, obj.nsecs); | |
98 stmt.setObject(6, objid); | |
99 stmt.execute(); | |
100 stmt.close(); | |
101 | |
102 case 'xydata' | |
103 | |
104 stmt = conn.prepareStatement(... | |
105 'UPDATE xydata SET xunits=?, yunits=? WHERE id = ?'); | |
106 stmt.setObject(1, char(obj.xunits)); | |
107 stmt.setObject(2, char(obj.yunits)); | |
108 stmt.setObject(3, objid); | |
109 stmt.execute(); | |
110 stmt.close(); | |
111 | |
112 case 'mfir' | |
113 | |
114 stmt = conn.prepareStatement(... | |
115 'UPDATE mfir SET in_file=?, fs=? WHERE obj_id = ?'); | |
116 stmt.setObject(1, obj.infile); | |
117 stmt.setObject(2, obj.fs); | |
118 stmt.setObject(3, objid); | |
119 stmt.execute(); | |
120 stmt.close(); | |
121 | |
122 case 'miir' | |
123 | |
124 stmt = conn.prepareStatement(... | |
125 'UPDATE miir SET in_file=?, fs=? WHERE obj_id = ?'); | |
126 stmt.setObject(1, obj.infile); | |
127 stmt.setObject(2, obj.fs); | |
128 stmt.setObject(3, objid); | |
129 stmt.execute(); | |
130 stmt.close(); | |
131 | |
132 otherwise | |
133 utils.helper.msg(msg.PROC2, 'no meta data table for %s object', cl); | |
134 | |
135 end | |
136 | |
137 end |