package com.molina.cvmfs.history;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Jose Molina Colmenero
 */
public class RevisionTag {

    private String name;
    private String hash;
    private int revision;
    private long timestamp;
    private int channel;
    private String description;

    public RevisionTag(ResultSet rs) throws SQLException {
        name = rs.getString(0);
        hash = rs.getString(1);
        revision = rs.getInt(2);
        timestamp = rs.getLong(3);
        channel = rs.getInt(4);
        description = rs.getString(5);
    }

    private static String databaseFields() {
        return "name, hash, revision, timestamp, channel, description";
    }

    public static String sqlQueryAll() {
        return "SELECT " + RevisionTag.databaseFields() +
                " FROM tags ORDER BY timestamp DESC";
    }

    public static String sqlQueryName(String name) {
        return "SELECT " + RevisionTag.databaseFields() +
                " FROM tags WHERE name=" + name + " LIMIT 1";
    }

    public static String sqlQueryRevision(int revision) {
        return "SELECT " + RevisionTag.databaseFields() +
                " FROM tags WHERE revision=" + revision + " LIMIT 1";
    }

    public static String sqlQueryDate(long timestamp) {
        return "SELECT " + RevisionTag.databaseFields() +
                " FROM tags WHERE timestamp >" + timestamp +
                " ORDER BY timestamp ASC LIMIT 1";
    }

    public String getName() {
        return name;
    }

    public String getHash() {
        return hash;
    }

    public int getRevision() {
        return revision;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public int getChannel() {
        return channel;
    }

    public String getDescription() {
        return description;
    }
}

@@ -408,9 +408,9 @@
 ing(
-0
+1
 );%0A 
@@ -428,33 +428,33 @@
  = rs.getString(
-1
+2
 );%0A        revis
@@ -469,17 +469,17 @@
 .getInt(
-2
+3
 );%0A     
@@ -504,17 +504,17 @@
 getLong(
-3
+4
 );%0A     
@@ -536,17 +536,17 @@
 .getInt(
-4
+5
 );%0A     
@@ -575,17 +575,17 @@
 tString(
-5
+6
 );%0A    %7D

Fix revision tag column retrieval