Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@repository/updateObjMetadata.m @ 13:e05504b18072 database-connection-manager
Move more functions to utils.repository
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | m-toolbox/classes/+utils/@jmysql/updateObjMetadata.m@f0afece42f48 |
children |
comparison
equal
deleted
inserted
replaced
12:86aabb42dd84 | 13:e05504b18072 |
---|---|
1 function updateObjMetadata(conn, obj, objid) | |
2 % an utility to update entries for various object metadata in the | |
3 % corresponding tables. differs from insertObjMetadataV1() by | |
4 % the use of the new v3.0 database structure | |
5 % | |
6 % MUST BE KEPT IN SYNC WITH insertObjMetadata() | |
7 % | |
8 % conn - Java database connection object | |
9 % obj - object | |
10 % objid - unique ID of the object in the database | |
11 % | |
12 % VERSION: $Id: updateObjMetadata.m,v 1.7 2011/11/09 18:47:04 mauro Exp $ | |
13 % | |
14 | |
15 import utils.const.* | |
16 | |
17 if nargin < 3 | |
18 error('### incorrect usage'); | |
19 end | |
20 if ~isjava(conn) | |
21 error('### incorrect usage'); | |
22 end | |
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 utils.repository.updateObjMetadata(conn, obj.data, objid); | |
33 | |
34 % insert the AO info | |
35 stmt = conn.prepareStatement(... | |
36 'UPDATE ao SET data_type=?, description=? WHERE obj_id = ?'); | |
37 stmt.setObject(1, java.lang.String(class(obj.data))); | |
38 desc = obj.description; | |
39 if length(desc)>65535 | |
40 warning('Object description length exceeded. Truncating to 65535 characters'); | |
41 desc = desc(1:65535); | |
42 end | |
43 stmt.setObject(2, java.lang.String(desc)); | |
44 stmt.setObject(3, objid); | |
45 stmt.executeUpdate(); | |
46 stmt.close(); | |
47 | |
48 case 'cdata' | |
49 | |
50 stmt = conn.prepareStatement(... | |
51 'UPDATE cdata SET yunits=? WHERE obj_id = ?'); | |
52 stmt.setObject(1, java.lang.String(char(obj.yunits))); | |
53 stmt.setObject(2, objid); | |
54 stmt.executeUpdate(); | |
55 stmt.close(); | |
56 | |
57 case 'fsdata' | |
58 | |
59 % possible bad entries | |
60 fs = obj.fs; | |
61 if ~isfinite(fs) | |
62 fs = []; | |
63 end | |
64 | |
65 stmt = conn.prepareStatement(... | |
66 'UPDATE fsdata SET xunits=?, yunits=?, fs=? WHERE obj_id = ?'); | |
67 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
68 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
69 stmt.setObject(3, fs); | |
70 stmt.setObject(4, objid); | |
71 stmt.executeUpdate(); | |
72 stmt.close(); | |
73 | |
74 case 'tsdata' | |
75 | |
76 stmt = conn.prepareStatement(... | |
77 'UPDATE tsdata SET xunits=?, yunits=?, fs=?, t0=?, nsecs=?, toffset=? WHERE obj_id = ?'); | |
78 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
79 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
80 stmt.setObject(3, obj.fs); | |
81 stmt.setObject(4, java.lang.String(format(obj.t0 + obj.toffset/1000, 'yyyy-mm-dd HH:MM:SS', 'UTC'))); | |
82 stmt.setObject(5, obj.nsecs); | |
83 stmt.setObject(6, obj.toffset); | |
84 stmt.setObject(7, objid); | |
85 stmt.execute(); | |
86 stmt.close(); | |
87 | |
88 case 'xydata' | |
89 | |
90 stmt = conn.prepareStatement(... | |
91 'UPDATE xydata SET xunits=?, yunits=? WHERE obj_id = ?'); | |
92 stmt.setObject(1, java.lang.String(char(obj.xunits))); | |
93 stmt.setObject(2, java.lang.String(char(obj.yunits))); | |
94 stmt.setObject(3, objid); | |
95 stmt.execute(); | |
96 stmt.close(); | |
97 | |
98 case 'mfir' | |
99 | |
100 stmt = conn.prepareStatement(... | |
101 'UPDATE mfir SET in_file=?, fs=? WHERE obj_id = ?'); | |
102 stmt.setObject(1, java.lang.String(obj.infile)); | |
103 stmt.setObject(2, obj.fs); | |
104 stmt.setObject(3, objid); | |
105 stmt.execute(); | |
106 stmt.close(); | |
107 | |
108 case 'miir' | |
109 | |
110 stmt = conn.prepareStatement(... | |
111 'UPDATE miir SET in_file=?, fs=? WHERE obj_id = ?'); | |
112 stmt.setObject(1, java.lang.String(obj.infile)); | |
113 stmt.setObject(2, obj.fs); | |
114 stmt.setObject(3, objid); | |
115 stmt.execute(); | |
116 stmt.close(); | |
117 | |
118 otherwise | |
119 utils.helper.msg(msg.PROC2, 'no meta data table for %s object', cl); | |
120 | |
121 end | |
122 | |
123 end |