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