Skip to content

Instantly share code, notes, and snippets.

@mcnemesis
Last active September 8, 2022 12:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcnemesis/912d307a16588a34cb30281bf7e40fd8 to your computer and use it in GitHub Desktop.
Save mcnemesis/912d307a16588a34cb30281bf7e40fd8 to your computer and use it in GitHub Desktop.
package com.nuchwezi.nulabs;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.nuchwezi.xlitedatabase.DBAdapter; // <-- get the DAL
public class TestXLiteDatabaseActivity extends AppCompatActivity {
// we shall use the XLiteDatabase layer for managing an in-app data cache
DBAdapter dbAdapter;
// Have some keys that will be used to store or read stuff from the XLDB dictionary-like interface
public class CACHE_KEYS {
public static final String VARIABLE_A = "A";
public static final String VARIABLE_B = "B";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize the XLDAL
dbAdapter = new DBAdapter(this);
dbAdapter.open();
// EXAMPLE 1: Store a strings into the XLDB
String someValue = "TESTING";
dbAdapter.cacheSET(CACHE_KEYS.VARIABLE_A, "testing"); // store literal string
dbAdapter.cacheSET(CACHE_KEYS.VARIABLE_B, someValue); // store referenced string
// EXAMPLE 2: Fetch a string from the XLDB
assert ("testing".equals(dbAdapter.cacheGET(CACHE_KEYS.VARIABLE_A)));
assert (someValue.equals(dbAdapter.cacheGET(CACHE_KEYS.VARIABLE_B)));
// EXAMPLE 3: Delete string from XLDB
if(dbAdapter.cacheDELETE(CACHE_KEYS.VARIABLE_B)){
assert (null == dbAdapter.cacheGET(CACHE_KEYS.VARIABLE_B));
}
// if tests passed (no errors), xlitedatabase is working fine.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment