Android Open Source - sugar Sugar Context






From Project

Back to project page sugar.

License

The source code is released under:

Copyright (C) 2012 by Satya Narayan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the S...

If you think the Android project sugar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.orm;
//from w  ww .j  a  v a2  s  . c  o m
import android.content.Context;

public class SugarContext {

    private static SugarContext instance = null;
    private SugarDb sugarDb;
    private Context context;

    private SugarContext(Context context) {
        this.context = context;
        this.sugarDb = new SugarDb(context);
    }
    
    public static SugarContext getSugarContext() {
        if (instance == null) {
            throw new NullPointerException("SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.");
        }
        return instance;
    }

    public static void init(Context context) {
        instance = new SugarContext(context);
    }

    public static void terminate() {
        if (instance == null) {
            return;
        }
        instance.doTerminate();
    }

    /*
     * Per issue #106 on Github, this method won't be called in
     * any real Android device. This method is used purely in
     * emulated process environments such as an emulator or
     * Robolectric Android mock.
     */
    private void doTerminate() {
        if (this.sugarDb != null) {
            this.sugarDb.getDB().close();
        }
    }

    protected SugarDb getSugarDb() {
        return sugarDb;
    }

}




Java Source Code List

com.example.AddNoteActivity.java
com.example.ClientApp.java
com.example.NewNote.java
com.example.NoteListActivity.java
com.example.NoteRelation.java
com.example.Note.java
com.example.SugarActivity.java
com.example.Tag.java
com.example.TextNote.java
com.orm.SchemaGenerator.java
com.orm.SugarApp.java
com.orm.SugarContext.java
com.orm.SugarDb.java
com.orm.SugarRecord.java
com.orm.SugarTransactionHelper.java
com.orm.dsl.Column.java
com.orm.dsl.Ignore.java
com.orm.dsl.NotNull.java
com.orm.dsl.Table.java
com.orm.dsl.Unique.java
com.orm.query.Condition.java
com.orm.query.Select.java
com.orm.util.Collection.java
com.orm.util.ManifestHelper.java
com.orm.util.NamingHelper.java
com.orm.util.NumberComparator.java
com.orm.util.QueryBuilder.java
com.orm.util.ReflectionUtil.java
com.orm.util.SugarConfig.java
com.orm.util.SugarCursorFactory.java