~ubuntu-branches/ubuntu/quantal/shotwell/quantal

« back to all changes in this revision

Viewing changes to plugins/shotwell-data-imports/FSpotPhotoVersionsTable.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-02-21 13:52:58 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: package-import@ubuntu.com-20120221135258-ao9jiib5qicomq7q
Tags: upstream-0.11.92
ImportĀ upstreamĀ versionĀ 0.11.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2011 Yorba Foundation
 
2
 *
 
3
 * This software is licensed under the GNU Lesser General Public License
 
4
 * (version 2.1 or later).  See the COPYING file in this distribution. 
 
5
 */
 
6
 
 
7
namespace DataImports.FSpot.Db {
 
8
 
 
9
/**
 
10
 * The value object for the "photo_versions" table, representing a single database row.
 
11
 */
 
12
public class FSpotPhotoVersionRow : Object {
 
13
    public int64 photo_id;
 
14
    public int64 version_id;
 
15
    public string name;
 
16
    public File? base_path;
 
17
    public string? filename;
 
18
    public string md5_sum;
 
19
    public bool is_protected;
 
20
}
 
21
 
 
22
/**
 
23
 * This class represents the F-Spot photo_versions table.
 
24
 */
 
25
public class FSpotPhotoVersionsTable : FSpotDatabaseTable<FSpotPhotoVersionRow> {
 
26
    public static const string TABLE_NAME = "Photo_versions";
 
27
 
 
28
    public FSpotPhotoVersionsTable(Sqlite.Database db, FSpotDatabaseBehavior db_behavior) {
 
29
        base(db);
 
30
        set_behavior(db_behavior.get_photo_versions_behavior());
 
31
    }
 
32
    
 
33
    public Gee.ArrayList<FSpotPhotoVersionRow> get_by_photo_id(int64 photo_id) throws DatabaseError {
 
34
        Gee.ArrayList<FSpotPhotoVersionRow> rows = new Gee.ArrayList<FSpotPhotoVersionRow?>();
 
35
        
 
36
        Sqlite.Statement stmt;
 
37
        
 
38
        string column_list = get_joined_column_list();
 
39
        string sql = "SELECT %s FROM %s WHERE photo_id=?".printf(
 
40
            column_list, table_name
 
41
        );
 
42
 
 
43
        int res = fspot_db.prepare_v2(sql, -1, out stmt);
 
44
        if (res != Sqlite.OK)
 
45
            throw_error("Statement failed: %s".printf(sql), res);
 
46
        
 
47
        res = stmt.bind_int64(1, photo_id);
 
48
        if (res != Sqlite.OK)
 
49
            throw_error("Bind failed for photo_id", res);
 
50
        
 
51
        res = stmt.step();
 
52
        while (res == Sqlite.ROW) {
 
53
            FSpotPhotoVersionRow row;
 
54
            behavior.build_row(stmt, out row);
 
55
            rows.add(row);
 
56
            res = stmt.step();
 
57
        }
 
58
        
 
59
        return rows;
 
60
    }
 
61
}
 
62
 
 
63
// Photo_versions table behavior for v0-8
 
64
// Note: there is a change in the URI format in version 8 but the File.new_for_uri
 
65
// constructor should be able to deal with the variation, so the v8 behavior should
 
66
// be handled in a way identical to v0-7
 
67
public class FSpotPhotoVersionsV0Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
 
68
    private static FSpotPhotoVersionsV0Behavior instance;
 
69
    
 
70
    private FSpotPhotoVersionsV0Behavior() {
 
71
    }
 
72
    
 
73
    public static FSpotPhotoVersionsV0Behavior get_instance() {
 
74
        if (instance == null)
 
75
            instance = new FSpotPhotoVersionsV0Behavior();
 
76
        return instance;
 
77
    }
 
78
    
 
79
    public string get_table_name() {
 
80
        return FSpotPhotoVersionsTable.TABLE_NAME;
 
81
    }    
 
82
    
 
83
    public string[] list_columns() {
 
84
        return { "photo_id", "version_id", "name", "uri" };
 
85
    }
 
86
    
 
87
    public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
 
88
        row = new FSpotPhotoVersionRow();
 
89
        row.photo_id = stmt.column_int64(offset + 0);
 
90
        row.version_id = stmt.column_int64(offset + 1);
 
91
        row.name = stmt.column_text(offset + 2);
 
92
 
 
93
        string? full_path = stmt.column_text(offset + 3);
 
94
        if (full_path != null) {
 
95
            File uri = File.new_for_uri(full_path);
 
96
            row.base_path = uri.get_parent();
 
97
            row.filename = uri.get_basename();
 
98
        }
 
99
 
 
100
        row.md5_sum = "";
 
101
        row.is_protected = false;
 
102
    }
 
103
}
 
104
 
 
105
// Photo_versions table behavior for v9-15
 
106
// add protected field
 
107
public class FSpotPhotoVersionsV9Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
 
108
    private static FSpotPhotoVersionsV9Behavior instance;
 
109
    
 
110
    private FSpotPhotoVersionsV9Behavior() {
 
111
    }
 
112
    
 
113
    public static FSpotPhotoVersionsV9Behavior get_instance() {
 
114
        if (instance == null)
 
115
            instance = new FSpotPhotoVersionsV9Behavior();
 
116
        return instance;
 
117
    }
 
118
    
 
119
    public string get_table_name() {
 
120
        return FSpotPhotoVersionsTable.TABLE_NAME;
 
121
    }    
 
122
    
 
123
    public string[] list_columns() {
 
124
        return { "photo_id", "version_id", "name", "uri",
 
125
            "protected" };
 
126
    }
 
127
    
 
128
    public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
 
129
        row = new FSpotPhotoVersionRow();
 
130
        row.photo_id = stmt.column_int64(offset + 0);
 
131
        row.version_id = stmt.column_int64(offset + 1);
 
132
        row.name = stmt.column_text(offset + 2);
 
133
 
 
134
        string? full_path = stmt.column_text(offset + 3);
 
135
        if (full_path != null) {
 
136
            File uri = File.new_for_uri(full_path);
 
137
            row.base_path = uri.get_parent();
 
138
            row.filename = uri.get_basename();
 
139
        }
 
140
 
 
141
        row.md5_sum = "";
 
142
        row.is_protected = (stmt.column_int(offset + 4) > 0);
 
143
    }
 
144
}
 
145
 
 
146
// Photo_versions table behavior for v16
 
147
// add md5_sum in photo_versions
 
148
public class FSpotPhotoVersionsV16Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
 
149
    private static FSpotPhotoVersionsV16Behavior instance;
 
150
    
 
151
    private FSpotPhotoVersionsV16Behavior() {
 
152
    }
 
153
    
 
154
    public static FSpotPhotoVersionsV16Behavior get_instance() {
 
155
        if (instance == null)
 
156
            instance = new FSpotPhotoVersionsV16Behavior();
 
157
        return instance;
 
158
    }
 
159
    
 
160
    public string get_table_name() {
 
161
        return FSpotPhotoVersionsTable.TABLE_NAME;
 
162
    }    
 
163
    
 
164
    public string[] list_columns() {
 
165
        return { "photo_id", "version_id", "name", "uri",
 
166
            "md5_sum", "protected" };
 
167
    }
 
168
    
 
169
    public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
 
170
        row = new FSpotPhotoVersionRow();
 
171
        row.photo_id = stmt.column_int64(offset + 0);
 
172
        row.version_id = stmt.column_int64(offset + 1);
 
173
        row.name = stmt.column_text(offset + 2);
 
174
 
 
175
        string? full_path = stmt.column_text(offset + 3);
 
176
        if (full_path != null) {
 
177
            File uri = File.new_for_uri(full_path);
 
178
            row.base_path = uri.get_parent();
 
179
            row.filename = uri.get_basename();
 
180
        }
 
181
 
 
182
        row.md5_sum = stmt.column_text(offset + 4);
 
183
        row.is_protected = (stmt.column_int(offset + 5) > 0);
 
184
    }
 
185
}
 
186
 
 
187
// Photo_versions table behavior for v17
 
188
// v17 split the URI into base_uri and filename (reverting back to the original
 
189
// design introduced in v0, albeit with a URI rather than a file system path)
 
190
public class FSpotPhotoVersionsV17Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
 
191
    private static FSpotPhotoVersionsV17Behavior instance;
 
192
    
 
193
    private FSpotPhotoVersionsV17Behavior() {
 
194
    }
 
195
    
 
196
    public static FSpotPhotoVersionsV17Behavior get_instance() {
 
197
        if (instance == null)
 
198
            instance = new FSpotPhotoVersionsV17Behavior();
 
199
        return instance;
 
200
    }
 
201
    
 
202
    public string get_table_name() {
 
203
        return FSpotPhotoVersionsTable.TABLE_NAME;
 
204
    }    
 
205
    
 
206
    public string[] list_columns() {
 
207
        return { "photo_id", "version_id", "name", "base_uri", "filename",
 
208
            "md5_sum", "protected" };
 
209
    }
 
210
    
 
211
    public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
 
212
        row = new FSpotPhotoVersionRow();
 
213
        row.photo_id = stmt.column_int64(offset + 0);
 
214
        row.version_id = stmt.column_int64(offset + 1);
 
215
        row.name = stmt.column_text(offset + 2);
 
216
        
 
217
        string? base_path = stmt.column_text(offset + 3);
 
218
        string? filename = stmt.column_text(offset + 4);
 
219
        if (base_path != null && filename != null) {
 
220
            row.base_path = File.new_for_uri(base_path);
 
221
            row.filename = filename;
 
222
        }
 
223
        
 
224
        row.md5_sum = stmt.column_text(offset + 5);
 
225
        row.is_protected = (stmt.column_int(offset + 6) > 0);
 
226
    }
 
227
}
 
228
 
 
229
// Photo_versions table behavior for v18
 
230
// md5_sum renamed import_md5
 
231
public class FSpotPhotoVersionsV18Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
 
232
    private static FSpotPhotoVersionsV18Behavior instance;
 
233
    
 
234
    private FSpotPhotoVersionsV18Behavior() {
 
235
    }
 
236
    
 
237
    public static FSpotPhotoVersionsV18Behavior get_instance() {
 
238
        if (instance == null)
 
239
            instance = new FSpotPhotoVersionsV18Behavior();
 
240
        return instance;
 
241
    }
 
242
    
 
243
    public string get_table_name() {
 
244
        return FSpotPhotoVersionsTable.TABLE_NAME;
 
245
    }    
 
246
    
 
247
    public string[] list_columns() {
 
248
        return { "photo_id", "version_id", "name", "base_uri", "filename",
 
249
            "import_md5", "protected" };
 
250
    }
 
251
    
 
252
    public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
 
253
        row = new FSpotPhotoVersionRow();
 
254
        row.photo_id = stmt.column_int64(offset + 0);
 
255
        row.version_id = stmt.column_int64(offset + 1);
 
256
        row.name = stmt.column_text(offset + 2);
 
257
        
 
258
        string? base_path = stmt.column_text(offset + 3);
 
259
        string? filename = stmt.column_text(offset + 4);
 
260
        if (base_path != null && filename != null) {
 
261
            row.base_path = File.new_for_uri(base_path);
 
262
            row.filename = filename;
 
263
        }
 
264
        
 
265
        row.md5_sum = stmt.column_text(offset + 5);
 
266
        row.is_protected = (stmt.column_int(offset + 6) > 0);
 
267
    }
 
268
}
 
269
 
 
270
}
 
271