Back to project page AquaBase.
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.
/* * This file is part of AquaBase./*from w w w. java 2 s.co 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 CrustaceanTableHelper { public static final String TABLE_NAME = "crustacean"; //$NON-NLS-1$ public static final String COLUMN_SIZE = "size"; //$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_ORIGIN = "origin"; //$NON-NLS-1$ public static final String COLUMN_FOOD = "food"; //$NON-NLS-1$ public static final String COLUMN_REPRODUCTION = "reproduction"; //$NON-NLS-1$ public static final String COLUMN_USEFULNESS = "usefulness"; //$NON-NLS-1$ public static final String COLUMN_SPECIAL = "special"; //$NON-NLS-1$ private static final String CSV_FILE_URL = "http://www.aquabase.org/crustacea/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("Taille", CrustaceanTableHelper.COLUMN_SIZE, double.class); //$NON-NLS-1$ CSV_MAPPING.put("TempMin", CrustaceanTableHelper.COLUMN_MIN_TEMP, int.class); //$NON-NLS-1$ CSV_MAPPING.put("TempMax", CrustaceanTableHelper.COLUMN_MAX_TEMP, int.class); //$NON-NLS-1$ CSV_MAPPING.put("Origine", CrustaceanTableHelper.COLUMN_ORIGIN, String.class); //$NON-NLS-1$ CSV_MAPPING.put("Alimentation", CrustaceanTableHelper.COLUMN_FOOD, String.class); //$NON-NLS-1$ CSV_MAPPING.put("Reproduction", CrustaceanTableHelper.COLUMN_REPRODUCTION, String.class); //$NON-NLS-1$ CSV_MAPPING.put("Utilite", CrustaceanTableHelper.COLUMN_USEFULNESS, String.class); //$NON-NLS-1$ CSV_MAPPING.put("Particularite", CrustaceanTableHelper.COLUMN_SPECIAL, 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} real," //$NON-NLS-1$ + "{4} integer," //$NON-NLS-1$ + "{5} integer," //$NON-NLS-1$ + "{6} text," //$NON-NLS-1$ + "{7} text," //$NON-NLS-1$ + "{8} text," //$NON-NLS-1$ + "{9} text," //$NON-NLS-1$ + "{10} text);"; //$NON-NLS-1$ String sql = MessageFormat.format(pattern, TABLE_NAME, DatabaseHelper.COLUMN_ID, DatabaseHelper.COLUMN_SCI_NAME, COLUMN_SIZE, COLUMN_MIN_TEMP, COLUMN_MAX_TEMP, COLUMN_ORIGIN, COLUMN_FOOD, COLUMN_REPRODUCTION, COLUMN_USEFULNESS, COLUMN_SPECIAL); 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_SIZE, R.string.crustacean_size)); columns.add(new Pair<String, Integer>(COLUMN_MIN_TEMP, R.string.crustacean_min_temp)); columns.add(new Pair<String, Integer>(COLUMN_MAX_TEMP, R.string.crustacean_max_temp)); columns.add(new Pair<String, Integer>(COLUMN_ORIGIN, R.string.crustacean_origin)); columns.add(new Pair<String, Integer>(COLUMN_FOOD, R.string.crustacean_food)); columns.add(new Pair<String, Integer>(COLUMN_REPRODUCTION, R.string.crustacean_reproduction)); columns.add(new Pair<String, Integer>(COLUMN_USEFULNESS, R.string.crustacean_usefulness)); columns.add(new Pair<String, Integer>(COLUMN_SPECIAL, R.string.crustacean_special)); return columns; } }