sbMigrate070RC1to070.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("----++++----++++\nsbLocalDatabaseMigrate070RC1to070 ---> " +
38  s +
39  "\n----++++----++++\n");
40 }
41 
43 {
44  SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(this);
45 
46  this.fromVersion = 6;
47  this.toVersion = 7;
48 }
49 
50 //-----------------------------------------------------------------------------
51 // sbLocalDatabaseMigration Implementation
52 //-----------------------------------------------------------------------------
53 
55  __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
56 
57  classDescription: 'Songbird Migration Handler for 0.7.0 RC1 to 0.7.0',
58  classID: Components.ID("{60e48ff7-13b4-498d-9c2e-a077a34a9ca6}"),
59  contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID + "0.7.0 RC1 to 0.7.0",
60 
61  _databaseLocation: null,
62  _databaseGUID: null,
63 
64  _mediaItems: null,
65 
66  migrate: function sbLDBM070RC1to070_migrate(aLibrary) {
67  this._databaseGUID = aLibrary.databaseGuid;
68  this._databaseLocation = aLibrary.databaseLocation;
69 
70  this._getMediaItems();
71 
72  var query = this._createQuery();
73  query.addQuery("begin");
74 
75  // add is_list to media_items table.
76  query.addQuery("alter table media_items add column is_list integer not null check(is_list in (0, 1)) default 0");
77  // add is_list to library_media_item table.
78  query.addQuery("alter table library_media_item add column is_list integer not null check(is_list in (0, 1)) default 0");
79  // add index on is_list media_items.
80  query.addQuery("create index idx_media_items_is_list on media_items (is_list)");
81 
82  for(let i = 0; i < this._mediaItems.length; ++i) {
83  let str = "update media_items set is_list = ? where media_item_id = ?";
84  query.addQuery(str);
85 
86  query.bindInt32Parameter(0, this._mediaItems[i].isList);
87  query.bindInt32Parameter(1, this._mediaItems[i].itemId);
88  }
89 
90  // Finally, we updated the schema version to the destination version.
91  query.addQuery("update library_metadata set value = '7' where name = 'version'");
92 
93  // Our queries are all generated. Time to execute the migration.
94  query.addQuery("commit");
95 
96  var retval;
97  query.setAsyncQuery(true);
98  query.execute(retval);
99 
100  var sip = Cc["@mozilla.org/supports-interface-pointer;1"]
101  .createInstance(Ci.nsISupportsInterfacePointer);
102  sip.data = this;
103 
104  this._titleText = "Library Migration Helper";
105  this._statusText = "Migrating 0.7.0 RC1 database to 0.7.0 database...";
106  this.migrationQuery = query;
107 
108  this.startNotificationTimer();
109  SBJobUtils.showProgressDialog(sip.data, null, 0);
110  this.stopNotificationTimer();
111  },
112 
113  _createQuery: function sbLDBM070RC1to070_createQuery() {
114  var query = Cc["@songbirdnest.com/Songbird/DatabaseQuery;1"]
115  .createInstance(Ci.sbIDatabaseQuery);
116  query.databaseLocation = this._databaseLocation;
117  query.setDatabaseGUID(this._databaseGUID);
118 
119  return query;
120  },
121 
122  _getMediaItems: function sbLDBM070RC1to070_getMediaItems() {
123  this._mediaItems = [];
124 
125  let sql = "select media_item_id, media_list_type_id from media_items where media_list_type_id is not null";
126 
127  var query = this._createQuery();
128  query.addQuery(sql);
129 
130  var retval;
131  query.execute(retval);
132 
133  var resultSet = query.getResultObject();
134 
135  var rowCount = resultSet.getRowCount();
136  for(let currentRow = 0; currentRow < rowCount; ++currentRow) {
137  let _mediaItemId = resultSet.getRowCell(currentRow, 0);
138  let _listType = resultSet.getRowCell(currentRow, 1);
139  let _isList = Number(parseInt(_listType) > 0);
140 
141  var entry = {itemId: _mediaItemId, isList: _isList};
142  this._mediaItems.push(entry);
143  }
144  }
145 }
146 
147 
148 //
149 // Module
150 //
151 
152 function NSGetModule(compMgr, fileSpec) {
153  return XPCOMUtils.generateModule([
155  ]);
156 }
classDescription entry
Definition: FeedWriter.js:1427
const Ci
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
const Cr
function LOG(s)
return null
Definition: FeedWriter.js:1143
function sbLocalDatabaseMigrate070RC1to070()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
_getSelectedPageStyle s i
const Cc