d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * The contents of this file are subject to the terms of the Common Development and
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * Distribution License (the License). You may not use this file except in compliance with the
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * specific language governing permission and limitations under the License.
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * When distributing Covered Software, include this CDDL Header Notice in each file and include
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * Header, with the fields enclosed by brackets [] replaced by your own identifying
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * information: "Portions copyright [year] [name of copyright owner]".
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * Copyright 2016 ForgeRock AS.
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * Class for helping provide access to the database. Used internally by IdentityDatabase, and should
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * not be used elsewhere. Handles creation and upgrade of the SQLite database as required. Also
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * enables foreign key validation to maintain database consistency.
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumseyclass DatabaseOpenHelper extends SQLiteOpenHelper {
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey private static final String DATABASE_NAME = "FR_AUTH";
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * Creates the help for access to the database.
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey * @param context The context the database is to be opened from.
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey super(context, DATABASE_NAME, null, DATABASE_VERSION);
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey db.execSQL("CREATE TABLE " + IdentityDatabase.IDENTITY_TABLE_NAME + " (" +
d00779d35b3db7493fcdd3f8645e094c5540f4c4Tom Rumsey "PRIMARY KEY(" + IdentityDatabase.ISSUER + ", " + IdentityDatabase.ACCOUNT_NAME + "));");
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey db.execSQL("CREATE TABLE " + IdentityDatabase.MECHANISM_TABLE_NAME + " (" +
efafbd2aa55b834f714882683fa864a0ac9e64aaTom Rumsey IdentityDatabase.MECHANISM_UID + " TEXT UNIQUE, " +
b6d3b7f02818840dd9b10de909554c80a5e21326Tom Rumsey "PRIMARY KEY(" + IdentityDatabase.ID_ISSUER + ", " + IdentityDatabase.ID_ACCOUNT_NAME + ", " + IdentityDatabase.TYPE + "), " +
d00779d35b3db7493fcdd3f8645e094c5540f4c4Tom Rumsey "FOREIGN KEY(" + IdentityDatabase.ID_ISSUER + ", " + IdentityDatabase.ID_ACCOUNT_NAME + ") " +
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey "REFERENCES " + IdentityDatabase.IDENTITY_TABLE_NAME
d00779d35b3db7493fcdd3f8645e094c5540f4c4Tom Rumsey + "(" + IdentityDatabase.ISSUER + ", " + IdentityDatabase.ACCOUNT_NAME + "));");
efafbd2aa55b834f714882683fa864a0ac9e64aaTom Rumsey db.execSQL("CREATE TABLE " + IdentityDatabase.NOTIFICATION_TABLE_NAME + " (" +
b6d3b7f02818840dd9b10de909554c80a5e21326Tom Rumsey "PRIMARY KEY(" + IdentityDatabase.MECHANISM_UID + ", " + IdentityDatabase.TIME_RECEIVED + "), " +
efafbd2aa55b834f714882683fa864a0ac9e64aaTom Rumsey "FOREIGN KEY(" + IdentityDatabase.MECHANISM_UID + ") " +
efafbd2aa55b834f714882683fa864a0ac9e64aaTom Rumsey "REFERENCES " + IdentityDatabase.MECHANISM_TABLE_NAME
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey // SHOULD never be necessary
d4ba104b978e28c3f9254b390959e08bb8c2122fTom Rumsey // Enable foreign key constraints