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