sbMigrate11pre1bTo11pre1c.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
28 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
29 Components.utils.import("resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
30 Components.utils.import("resource://app/jsmodules/SBJobUtils.jsm");
31 
32 const Cc = Components.classes;
33 const Ci = Components.interfaces;
34 const Cr = Components.results;
35 
36 function LOG(s) {
37  dump("----++++----++++sbLibraryMigration " +
38  sbLibraryMigration.versionString + ": " +
39  s +
40  "\n----++++----++++\n");
41 }
42 
44 {
45  SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(this);
46 
47  this.fromVersion = 14;
48  this.toVersion = 15;
49  this.versionString = this.fromVersion + " to " +
50  this.toVersion;
51 }
52 
53 //-----------------------------------------------------------------------------
54 // sbLocalDatabaseMigration Implementation
55 //-----------------------------------------------------------------------------
56 
57 sbLibraryMigration.prototype = {
58  __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
59  classDescription: 'Songbird Migration Handler, version 14 to 15',
60  classID: Components.ID("{3e473356-a84a-4243-a597-6919cb1a26ff}"),
61  contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID + ' 14 to 15',
62 
63  _databaseLocation: null,
64  _databaseGUID: null,
65 
66  migrate: function sbLibraryMigration_migrate(aLibrary) {
67  try{
68 
69  this._databaseGUID = aLibrary.databaseGuid;
70  this._databaseLocation = aLibrary.databaseLocation;
71 
72  var query = this._createQuery();
73 
74  // because sqlite does not support ALTER COLUMN, we have to create
75  // a new table and replace the old one.
76 
77  // create the new resource_properties table with correct collation sequences
78  query.addQuery("create table resource_properties_2 (" +
79  "media_item_id integer not null," +
80  "property_id integer not null," +
81  "obj text not null," +
82  "obj_searchable text," +
83  "obj_sortable text collate library_collate," +
84  "obj_secondary_sortable text collate library_collate," +
85  "primary key (media_item_id, property_id)" +
86  ");");
87 
88  // copy the data from the old table to the new. note that we drop the obj_*
89  // data because we are going to recompute it anyway. this boosts the
90  // creation of the index, since all the comparisons will be on empty
91  // strings.
92  query.addQuery("insert into resource_properties_2 (media_item_id, property_id, obj) select media_item_id, property_id, obj from resource_properties;");
93 
94  // drop the old table
95  query.addQuery("drop table resource_properties;");
96 
97  // rename the new table into the old one
98  query.addQuery("alter table resource_properties_2 rename to resource_properties;");
99 
100  // recreate the index
101  query.addQuery("create index idx_resource_properties_property_id_obj_sortable_obj_secondary_sortable_media_item_id on resource_properties " +
102  "(property_id, obj_sortable, obj_secondary_sortable, media_item_id);");
103 
104  // Update the schema version to the destination version.
105  query.addQuery("update library_metadata set value = '"
106  + this.toVersion + "' where name = 'version'");
107  query.addQuery("commit");
108 
109  // Try to reduce db size
110  query.addQuery("VACUUM");
111 
112  var retval;
113  query.setAsyncQuery(true);
114  query.execute(retval);
115 
116  this._titleText = "Library Migration Helper";
117  this._statusText = "Improving sorting data...";
118  this.migrationQuery = query;
119 
120  var sip = Cc["@mozilla.org/supports-interface-pointer;1"]
121  .createInstance(Ci.nsISupportsInterfacePointer);
122  sip.data = this;
123 
124  this.startNotificationTimer();
125  SBJobUtils.showProgressDialog(sip.data, null, 0);
126  this.stopNotificationTimer();
127 
128  // Raise a flag indicating that this library will need all
129  // sort info to be recomputed.
130  // Normally we'd call propertyCache.invalidateSortData(), but
131  // at this point in startup the property cache does not exist yet.
132  var prefs = Cc["@mozilla.org/preferences-service;1"]
133  .getService(Ci.nsIPrefBranch);
134  prefs.setBoolPref("songbird.propertycache." +
135  this._databaseGUID + ".invalidSortData", true);
136  prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
137  }
138  catch (e) {
139  dump("Exception occured: " + e);
140  throw e;
141  }
142  },
143 
144  _createQuery: function sbLibraryMigration_createQuery() {
145  var query = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
146  .createInstance(Ci.sbIDatabaseQuery);
147  query.databaseLocation = this._databaseLocation;
148  query.setDatabaseGUID(this._databaseGUID);
149 
150  return query;
151  }
152 
153 };
154 
155 //-----------------------------------------------------------------------------
156 // Module
157 //-----------------------------------------------------------------------------
158 function NSGetModule(compMgr, fileSpec) {
159  return XPCOMUtils.generateModule([
161  ]);
162 }
163 
function sbLibraryMigration()
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function NSGetModule(compMgr, fileSpec)
return null
Definition: FeedWriter.js:1143
var prefs
Definition: FeedWriter.js:1169
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function LOG(s)