package com.yahoo.squidb.data;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;

import com.yahoo.squidb.data.SqlValidatorFactory.SqlValidator;

/*package*/ class SqlValidatorFactory {

    interface SqlValidator {

        void compileStatement(SQLiteDatabase db, String sql);
    }

    private static final SqlValidator INSTANCE;

    static {
        int version = VERSION.SDK_INT;
        if (version >= VERSION_CODES.JELLY_BEAN) {
            INSTANCE = new DefaultSqlValidator();
        } else if (version >= VERSION_CODES.ICE_CREAM_SANDWICH) {
            INSTANCE = new ReflectiveSqlValidator();
        } else {
            // included for forks that reduce minSdk below 14
            INSTANCE = new DefaultSqlValidator();
        }
    }

    private SqlValidatorFactory() {
        //no instance
    }

    static SqlValidator getValidator() {
        return INSTANCE;
    }
}

/*package*/ class DefaultSqlValidator implements SqlValidator {

    @Override
    public void compileStatement(SQLiteDatabase db, String sql) {
        db.compileStatement(sql);
    }
}

/*package*/ class ReflectiveSqlValidator implements SqlValidator {

    @Override
    public void compileStatement(SQLiteDatabase db, String sql) {
        Cursor c = db.rawQuery(sql, null);
        if (c != null) {
            c.close();
        }
    }
}

package com.yahoo.squidb.data;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;

import com.yahoo.squidb.data.SqlValidatorFactory.SqlValidator;

/*package*/ class SqlValidatorFactory {

    interface SqlValidator {

        void compileStatement(SQLiteDatabase db, String sql);
    }

    private static final SqlValidator INSTANCE;

    static {
        int version = VERSION.SDK_INT;
        if (version >= VERSION_CODES.JELLY_BEAN) {
            INSTANCE = new DefaultSqlValidator();
        } else if (version >= VERSION_CODES.ICE_CREAM_SANDWICH) {
            INSTANCE = new IcsSqlValidator();
        } else {
            // included for forks that reduce minSdk below 14
            INSTANCE = new DefaultSqlValidator();
        }
    }

    private SqlValidatorFactory() {
        //no instance
    }

    static SqlValidator getValidator() {
        return INSTANCE;
    }
}

/*package*/ class DefaultSqlValidator implements SqlValidator {

    @Override
    public void compileStatement(SQLiteDatabase db, String sql) {
        db.compileStatement(sql);
    }
}

/*package*/ class IcsSqlValidator implements SqlValidator {

    @Override
    public void compileStatement(SQLiteDatabase db, String sql) {
        Cursor c = db.rawQuery(sql, null);
        if (c != null) {
            c.close();
        }
    }
}

Rename to IcsSqlValidator