1
1
/**************************************************************************************
2
- * (c) 2015, Master Technology
2
+ * (c) 2015, 2016, Master Technology
3
3
* Licensed under the MIT license or contact me for a support, changes, enhancements,
4
4
* and/or if you require a commercial licensing
5
5
*
6
6
* Any questions please feel free to email me or put a issue up on github
7
- * Version 0.1.0 - Android Nathan@master-technology.com
7
+ * Version 0.1.2 - Android Nathan@master-technology.com
8
8
*************************************************************************************/
9
9
10
10
"use strict" ;
@@ -241,7 +241,7 @@ function Database(dbname, options, callback) {
241
241
if ( dbname !== "" && dbname !== ":memory:" ) {
242
242
//var pkgName = appModule.android.context.getPackageName();
243
243
//noinspection JSUnresolvedFunction
244
- dbname = this . _getContext ( ) . getDatabasePath ( dbname ) . getAbsolutePath ( ) ;
244
+ dbname = _getContext ( ) . getDatabasePath ( dbname ) . getAbsolutePath ( ) ;
245
245
var path = dbname . substr ( 0 , dbname . lastIndexOf ( '/' ) + 1 ) ;
246
246
247
247
// Create "databases" folder if it is missing. This causes issues on Emulators if it is missing
@@ -292,22 +292,6 @@ function Database(dbname, options, callback) {
292
292
*/
293
293
Database . prototype . _isSqlite = true ;
294
294
295
- /**
296
- * gets the current application context
297
- * @returns {* }
298
- * @private
299
- */
300
- Database . prototype . _getContext = function ( ) {
301
- if ( appModule . android . context ) {
302
- return ( appModule . android . context ) ;
303
- }
304
- var ctx = java . lang . Class . forName ( "android.app.AppGlobals" ) . getMethod ( "getInitialApplication" , null ) . invoke ( null , null ) ;
305
- if ( ctx ) return ctx ;
306
-
307
- ctx = java . lang . Class . forName ( "android.app.ActivityThread" ) . getMethod ( "currentApplication" , null ) . invoke ( null , null ) ;
308
- return ctx ;
309
- } ;
310
-
311
295
/***
312
296
* This gets or sets the database version
313
297
* @param valueOrCallback to set or callback(err, version)
@@ -767,7 +751,7 @@ Database.isSqlite = function(obj) {
767
751
*/
768
752
Database . exists = function ( name ) {
769
753
//noinspection JSUnresolvedFunction
770
- var dbName = this . _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
754
+ var dbName = _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
771
755
var dbFile = new java . io . File ( dbName ) ;
772
756
return dbFile . exists ( ) ;
773
757
} ;
@@ -778,7 +762,7 @@ Database.exists = function(name) {
778
762
*/
779
763
Database . deleteDatabase = function ( name ) {
780
764
//noinspection JSUnresolvedFunction
781
- var dbName = this . _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
765
+ var dbName = _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
782
766
var dbFile = new java . io . File ( dbName ) ;
783
767
if ( dbFile . exists ( ) ) {
784
768
dbFile . delete ( ) ;
@@ -797,10 +781,10 @@ Database.copyDatabase = function(name) {
797
781
798
782
//Open your local db as the input stream
799
783
//noinspection JSUnresolvedFunction
800
- var myInput = this . _getContext ( ) . getAssets ( ) . open ( "app/" + name ) ;
784
+ var myInput = _getContext ( ) . getAssets ( ) . open ( "app/" + name ) ;
801
785
802
786
//noinspection JSUnresolvedFunction
803
- var dbname = this . _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
787
+ var dbname = _getContext ( ) . getDatabasePath ( name ) . getAbsolutePath ( ) ;
804
788
var path = dbname . substr ( 0 , dbname . lastIndexOf ( '/' ) + 1 ) ;
805
789
806
790
// Create "databases" folder if it is missing. This causes issues on Emulators if it is missing
@@ -856,3 +840,18 @@ Database.VALUESARESTRINGS = 8;
856
840
857
841
module . exports = Database ;
858
842
843
+ /**
844
+ * gets the current application context
845
+ * @returns {* }
846
+ * @private
847
+ */
848
+ function _getContext ( ) {
849
+ if ( appModule . android . context ) {
850
+ return ( appModule . android . context ) ;
851
+ }
852
+ var ctx = java . lang . Class . forName ( "android.app.AppGlobals" ) . getMethod ( "getInitialApplication" , null ) . invoke ( null , null ) ;
853
+ if ( ctx ) return ctx ;
854
+
855
+ ctx = java . lang . Class . forName ( "android.app.ActivityThread" ) . getMethod ( "currentApplication" , null ) . invoke ( null , null ) ;
856
+ return ctx ;
857
+ }
0 commit comments