Android Open Source - morpho S Q L File Parser






From Project

Back to project page morpho.

License

The source code is released under:

Apache License

If you think the Android project morpho 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.morpho.android.ws.impl.sqlite;
/*  w w w .  ja  va  2 s  . com*/
import android.util.Log;

import com.morpho.android.util.Strings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

/**
 * Toma un archivo .sql y lo convierte a un arreglo de objetos String solo con
 * las sentencias vlidas.
 * 
 * @author Daniel Pedraza-Arcega
 * @since 1.0
 */
final class SQLFileParser {
    
    private static final int END_OF_STREAM = -1;
    private static final String TAG = SQLFileParser.class.getSimpleName();
    private static final String STATEMENT_DELIMITER = ";";
    private static final Pattern COMMENT_PATTERN = Pattern.compile("(?:/\\*[^;]*?\\*/)|(?:--[^;]*?$)", Pattern.DOTALL | Pattern.MULTILINE);

    /** NO INVOCAR. */
    private SQLFileParser() {
        throw new IllegalAccessError("This class cannot be instantiated nor extended");
    }

    /**
     * @param stream un archivo.
     * @return un arreglo de objetos String solo con las sentencias vlidas o
     *         {@code null} si hubo algn error.
     */
    static String[] getSqlStatements(InputStream stream) {
        
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new InputStreamReader(stream));
            int r;
            StringBuilder sb = new StringBuilder();
            while ((r = reader.read()) != END_OF_STREAM) {
                char character = (char) r;
                sb.append(character);
            }

            return COMMENT_PATTERN.matcher(sb)
                    .replaceAll(Strings.EMPTY)
                    .split(STATEMENT_DELIMITER);

        } catch (IOException ex) {
            Log.e(TAG, "Unable to parse SQL Statements", ex);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                    Log.e(TAG, "Unable to close stream", ex);
                }
            }
        }

        return null;
    }
}




Java Source Code List

com.morpho.android.activity.MainActivity.java
com.morpho.android.data.GeoArea.java
com.morpho.android.data.GeoPoint.java
com.morpho.android.data.JSONable.java
com.morpho.android.data.Route.java
com.morpho.android.data.Schedule.java
com.morpho.android.data.Station.java
com.morpho.android.intent.ReceiveTransitionsIntentService.java
com.morpho.android.receiver.VoiceReplyReceiver.java
com.morpho.android.util.Strings.java
com.morpho.android.ws.AsyncTaskAdapter.java
com.morpho.android.ws.Buses.java
com.morpho.android.ws.MorphoRequest.java
com.morpho.android.ws.Schedules.java
com.morpho.android.ws.Stations.java
com.morpho.android.ws.impl.MorphoClientFactory.java
com.morpho.android.ws.impl.sqlite.BusesSQLite.java
com.morpho.android.ws.impl.sqlite.MorphoSQLiteOpenHelper.java
com.morpho.android.ws.impl.sqlite.SQLFileParser.java
com.morpho.android.ws.impl.sqlite.SQLiteTemplate.java
com.morpho.android.ws.impl.sqlite.SQLiteUtils.java
com.morpho.android.ws.impl.sqlite.SchedulesSQLite.java
com.morpho.android.ws.impl.sqlite.StationsSQLite.java