comparison m-toolbox/classes/+utils/@jmysql/insertObjMetadata.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 insertObjMetadata(conn, obj, objid)
2 % an utility to insert 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 updateObjMetadata()
7 %
8 % conn - Java database connection object
9 % obj - object
10 % objid - unique ID of the object in the database
11 %
12 % VERSION: $Id: insertObjMetadata.m,v 1.9 2011/11/09 18:45:14 mauro Exp $
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 import utils.const.*
17
18 if nargin < 3
19 error('### incorrect usage');
20 end
21 if ~isjava(conn)
22 error('### incorrect usage');
23 end
24
25 % class of object
26 cl = class(obj);
27 utils.helper.msg(msg.PROC2, 'making meta data entry for %s object', cl);
28
29 switch cl
30 case 'ao'
31
32 % call recursively to insert the data object info
33 utils.jmysql.insertObjMetadata(conn, obj.data, objid);
34
35 % insert the AO info
36 stmt = conn.prepareStatement(...
37 'INSERT INTO ao (obj_id, data_type, description) VALUES (?, ?, ?)');
38 stmt.setObject(1, objid);
39 stmt.setObject(2, java.lang.String(class(obj.data)));
40
41 desc = obj.description;
42 if length(desc)>65535
43 warning('Object description length exceeded. Truncating to 65535 characters');
44 desc = desc(1:65535);
45 end
46 stmt.setObject(3, java.lang.String(desc));
47 stmt.execute();
48 stmt.close();
49
50 case 'cdata'
51
52 stmt = conn.prepareStatement(...
53 'INSERT INTO cdata (obj_id, yunits) VALUES (?, ?)');
54 stmt.setObject(1, objid);
55 stmt.setObject(2, java.lang.String(char(obj.yunits)));
56 stmt.execute();
57 stmt.close();
58
59 case 'fsdata'
60
61 % possible bad entries
62 fs = obj.fs;
63 if ~isfinite(fs)
64 fs = [];
65 end
66
67 stmt = conn.prepareStatement(...
68 'INSERT INTO fsdata (obj_id, xunits, yunits, fs) VALUES (?, ?, ?, ?)');
69 stmt.setObject(1, objid);
70 stmt.setObject(2, java.lang.String(char(obj.xunits)));
71 stmt.setObject(3, java.lang.String(char(obj.yunits)));
72 stmt.setObject(4, fs);
73 stmt.execute();
74 stmt.close();
75
76 case 'tsdata'
77
78 stmt = conn.prepareStatement(...
79 'INSERT INTO tsdata (obj_id, xunits, yunits, fs, t0, nsecs, toffset) VALUES (?, ?, ?, ?, ?, ?, ?)');
80 stmt.setObject(1, objid);
81 stmt.setObject(2, java.lang.String(char(obj.xunits)));
82 stmt.setObject(3, java.lang.String(char(obj.yunits)));
83 stmt.setObject(4, obj.fs);
84 stmt.setObject(5, java.lang.String(format(obj.t0 + obj.toffset/1000, 'yyyy-mm-dd HH:MM:SS', 'UTC')));
85 stmt.setObject(6, obj.nsecs);
86 stmt.setObject(7, obj.toffset);
87 stmt.execute();
88 stmt.close();
89
90 case 'xydata'
91
92 stmt = conn.prepareStatement(...
93 'INSERT INTO xydata (obj_id, xunits, yunits) VALUES (?, ?, ?)');
94 stmt.setObject(1, objid);
95 stmt.setObject(2, java.lang.String(char(obj.xunits)));
96 stmt.setObject(3, java.lang.String(char(obj.yunits)));
97 stmt.execute();
98 stmt.close();
99
100 case 'mfir'
101
102 stmt = conn.prepareStatement(...
103 'INSERT INTO mfir (obj_id, in_file, fs) VALUES (?, ?, ?)');
104 stmt.setObject(1, objid);
105 stmt.setObject(2, java.lang.String(obj.infile));
106 stmt.setObject(3, obj.fs);
107 stmt.execute();
108 stmt.close();
109
110 case 'miir'
111
112 stmt = conn.prepareStatement(...
113 'INSERT INTO miir (obj_id, in_file, fs) VALUES (?, ?, ?)');
114 stmt.setObject(1, objid);
115 stmt.setObject(2, java.lang.String(obj.infile));
116 stmt.setObject(3, obj.fs);
117 stmt.execute();
118 stmt.close();
119
120 otherwise
121 utils.helper.msg(msg.PROC2, 'no meta data table for %s object', cl);
122
123 end
124
125 end