Skip to content

Instantly share code, notes, and snippets.

Last active September 8, 2022 12:13
What would you like to do?
package com.nuchwezi.nulabs;
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";
protected void onCreate(Bundle savedInstanceState) {
// initialize the XLDAL
dbAdapter = new DBAdapter(this);;
// 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
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