Android Open Source - AquaBase Fish Table Helper






From Project

Back to project page AquaBase.

License

The source code is released under:

GNU General Public License

If you think the Android project AquaBase 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

/*
 *  This file is part of AquaBase.//from  w  ww.ja v a 2s  . c o m
 *
 *  AquaBase is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AquaBase is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AquaBase.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Copyright (c) 2014 Cdric Bosdonnat <cedric@bosdonnat.fr>
 */
package org.aquabase.data;

import java.text.MessageFormat;
import java.util.Vector;

import org.aquabase.R;

import android.content.Context;
import android.util.Pair;

public class FishTableHelper {

    public static final String TABLE_NAME = "fish";                   //$NON-NLS-1$
    public static final String COLUMN_DESCRIPTOR = "descriptor";       //$NON-NLS-1$
    public static final String COLUMN_FAMILY = "family";               //$NON-NLS-1$
    public static final String COLUMN_MIN_TEMP = "minTemp";            //$NON-NLS-1$
    public static final String COLUMN_MAX_TEMP = "maxTemp";            //$NON-NLS-1$
    public static final String COLUMN_REPRO_TEMP = "reproTemp";        //$NON-NLS-1$
    public static final String COLUMN_MIN_PH = "minPh";                //$NON-NLS-1$
    public static final String COLUMN_MAX_PH = "maxPh";                //$NON-NLS-1$
    public static final String COLUMN_REPRO_PH = "reproPh";            //$NON-NLS-1$
    public static final String COLUMN_MIN_GH = "minGh";                //$NON-NLS-1$
    public static final String COLUMN_MAX_GH = "maxGh";                //$NON-NLS-1$
    public static final String COLUMN_REPRO_GH = "reproGh";            //$NON-NLS-1$
    public static final String COLUMN_MALE_SIZE = "maleSize";          //$NON-NLS-1$
    public static final String COLUMN_FEMALE_SIZE = "femaleSize";      //$NON-NLS-1$
    public static final String COLUMN_LIFE_TIME = "lifeTime";          //$NON-NLS-1$
    public static final String COLUMN_LIFE_ZONE = "lifeZone";          //$NON-NLS-1$
    public static final String COLUMN_ORIGIN = "origin";               //$NON-NLS-1$
    public static final String COLUMN_DESCRIPTION = "description";     //$NON-NLS-1$
    public static final String COLUMN_DIMORPHISM = "dimorphism";       //$NON-NLS-1$
    public static final String COLUMN_BEHAVIOR = "behavior";           //$NON-NLS-1$
    public static final String COLUMN_REPRODUCTION = "reproduction";   //$NON-NLS-1$
    private static final String CSV_FILE_URL = "http://www.aquabase.org/fish/dump.php3?format=file"; //$NON-NLS-1$


    protected static CsvMapping CSV_MAPPING;
    static {
        CSV_MAPPING = new CsvMapping();

        CSV_MAPPING.put("NomScientifique", DatabaseHelper.COLUMN_SCI_NAME, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Descripteur", FishTableHelper.COLUMN_DESCRIPTOR, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Famille", FishTableHelper.COLUMN_FAMILY, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("TempMin", FishTableHelper.COLUMN_MIN_TEMP, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("TempMax", FishTableHelper.COLUMN_MAX_TEMP, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("TempRepro", FishTableHelper.COLUMN_REPRO_TEMP, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("PHMin", FishTableHelper.COLUMN_MIN_PH, double.class); //$NON-NLS-1$
        CSV_MAPPING.put("PHMax", FishTableHelper.COLUMN_MAX_PH, double.class); //$NON-NLS-1$
        CSV_MAPPING.put("PHRepro", FishTableHelper.COLUMN_REPRO_PH, double.class); //$NON-NLS-1$
        CSV_MAPPING.put("GHMin", FishTableHelper.COLUMN_MIN_GH, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("GHMax", FishTableHelper.COLUMN_MAX_GH, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("GHRepro", FishTableHelper.COLUMN_REPRO_GH, int.class); //$NON-NLS-1$
        CSV_MAPPING.put("TailleMale", FishTableHelper.COLUMN_MALE_SIZE, double.class); //$NON-NLS-1$
        CSV_MAPPING.put("TailleFemelle", FishTableHelper.COLUMN_FEMALE_SIZE, double.class); //$NON-NLS-1$
        CSV_MAPPING.put("EsperanceVie", FishTableHelper.COLUMN_LIFE_TIME, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("ZoneDeVie", FishTableHelper.COLUMN_LIFE_ZONE, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Origine", FishTableHelper.COLUMN_ORIGIN, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Description", FishTableHelper.COLUMN_DESCRIPTION, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Dimorphisme", FishTableHelper.COLUMN_DIMORPHISM, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Comportement", FishTableHelper.COLUMN_BEHAVIOR, String.class); //$NON-NLS-1$
        CSV_MAPPING.put("Reproduction", FishTableHelper.COLUMN_REPRODUCTION, String.class); //$NON-NLS-1$
    }

    public static void loadCsv(Context context) {
        TableHelper.loadCsvHelper(context, CSV_FILE_URL, TABLE_NAME, CSV_MAPPING);
    }

    public static String getCreateSQL() {
        final String pattern = "create table {0} (" //$NON-NLS-1$
                             + "{1} integer primary key autoincrement, " //$NON-NLS-1$
                             + "{2} text not null," //$NON-NLS-1$
                             + "{3} text," //$NON-NLS-1$
                             + "{4} text," //$NON-NLS-1$
                             + "{5} integer," //$NON-NLS-1$
                             + "{6} integer," //$NON-NLS-1$
                             + "{7} integer," //$NON-NLS-1$
                             + "{8} real," //$NON-NLS-1$
                             + "{9} real," //$NON-NLS-1$
                             + "{10} real," //$NON-NLS-1$
                             + "{11} integer," //$NON-NLS-1$
                             + "{12} integer," //$NON-NLS-1$
                             + "{13} integer," //$NON-NLS-1$
                             + "{14} real," //$NON-NLS-1$
                             + "{15} real," //$NON-NLS-1$
                             + "{16} text," //$NON-NLS-1$
                             + "{17} text," //$NON-NLS-1$
                             + "{18} text," //$NON-NLS-1$
                             + "{19} text," //$NON-NLS-1$
                             + "{20} text," //$NON-NLS-1$
                             + "{21} text," //$NON-NLS-1$
                             + "{22} text);"; //$NON-NLS-1$
        String sql = MessageFormat.format(pattern, TABLE_NAME, DatabaseHelper.COLUMN_ID,
                                          DatabaseHelper.COLUMN_SCI_NAME,
                                          COLUMN_DESCRIPTOR, COLUMN_FAMILY,
                                          COLUMN_MIN_TEMP, COLUMN_MAX_TEMP, COLUMN_REPRO_TEMP,
                                          COLUMN_MIN_PH, COLUMN_MAX_PH, COLUMN_REPRO_PH,
                                          COLUMN_MIN_GH, COLUMN_MAX_GH, COLUMN_REPRO_GH,
                                          COLUMN_MALE_SIZE, COLUMN_FEMALE_SIZE,
                                          COLUMN_LIFE_TIME, COLUMN_LIFE_ZONE,
                                          COLUMN_ORIGIN, COLUMN_DESCRIPTION, COLUMN_DIMORPHISM,
                                          COLUMN_BEHAVIOR, COLUMN_REPRODUCTION);
        return sql;
    }

    public static String getDropSql() {
        return MessageFormat.format("drop table if exists {0};", TABLE_NAME); //$NON-NLS-1$
    }

    public static Vector<Pair<String, Integer>> getColumnsNames() {
        Vector<Pair<String, Integer>> columns = new Vector<Pair<String,Integer>>();

        columns.add(new Pair<String, Integer>(COLUMN_DESCRIPTOR, R.string.fish_descriptor));
        columns.add(new Pair<String, Integer>(COLUMN_FAMILY ,R.string.fish_family));
        columns.add(new Pair<String, Integer>(COLUMN_MIN_TEMP ,R.string.fish_min_temp));
        columns.add(new Pair<String, Integer>(COLUMN_MAX_TEMP ,R.string.fish_max_temp));
        columns.add(new Pair<String, Integer>(COLUMN_REPRO_TEMP ,R.string.fish_repro_temp));
        columns.add(new Pair<String, Integer>(COLUMN_MIN_PH ,R.string.fish_min_ph));
        columns.add(new Pair<String, Integer>(COLUMN_MAX_PH ,R.string.fish_max_ph));
        columns.add(new Pair<String, Integer>(COLUMN_REPRO_PH ,R.string.fish_repro_ph));
        columns.add(new Pair<String, Integer>(COLUMN_MIN_GH ,R.string.fish_min_gh));
        columns.add(new Pair<String, Integer>(COLUMN_MAX_GH ,R.string.fish_max_gh));
        columns.add(new Pair<String, Integer>(COLUMN_REPRO_GH ,R.string.fish_repro_gh));
        columns.add(new Pair<String, Integer>(COLUMN_MALE_SIZE ,R.string.fish_male_size));
        columns.add(new Pair<String, Integer>(COLUMN_FEMALE_SIZE ,R.string.fish_female_size));
        columns.add(new Pair<String, Integer>(COLUMN_LIFE_TIME ,R.string.fish_life_time));
        columns.add(new Pair<String, Integer>(COLUMN_LIFE_ZONE ,R.string.fish_life_zone));
        columns.add(new Pair<String, Integer>(COLUMN_ORIGIN ,R.string.fish_origin));
        columns.add(new Pair<String, Integer>(COLUMN_DESCRIPTION ,R.string.fish_description));
        columns.add(new Pair<String, Integer>(COLUMN_DIMORPHISM ,R.string.fish_dimorphism));
        columns.add(new Pair<String, Integer>(COLUMN_BEHAVIOR ,R.string.fish_behavior));
        columns.add(new Pair<String, Integer>(COLUMN_REPRODUCTION ,R.string.fish_reproduction));

        return columns;
    }

}




Java Source Code List

org.aquabase.DetailsActivity.java
org.aquabase.DetailsFragment.java
org.aquabase.MainActivity.java
org.aquabase.NavigationDrawerFragment.java
org.aquabase.SpeciesListFragment.java
org.aquabase.data.AquabaseContentProvider.java
org.aquabase.data.CSVParser.java
org.aquabase.data.CrustaceanTableHelper.java
org.aquabase.data.CsvMapping.java
org.aquabase.data.DatabaseHelper.java
org.aquabase.data.FishTableHelper.java
org.aquabase.data.TableHelper.java