tags:

views:

55

answers:

3

How do i pull the last records from different tables all with various amounts of records in them? here is some of my code, but it is returning nothing as my last set of records:

@HandlesEvent("showFirst")
public Resolution showFirst() {
    setFirstRecord(1);
    setLastRecord(10);
    return defaultHandler();
}

private int firstRecord = 1;

public void setFirstRecord(int firstRecord) {
    this.firstRecord = firstRecord;
}

public int getFirstRecord() {
    return Math.max(1, firstRecord);
}

private int lastRecord = 10;

public void setLastRecord(int lastRecord) {
    this.lastRecord = lastRecord;
}

public int getLastRecord() {
    int last = Math.max(getFirstRecord(), lastRecord);
    AutoFile file = getFile();
    if (file != null)
        last = Math.min(last, file.getSize());
    return last;
}

private int sortBy = -1;

public void setSortBy(int sortBy) {
    this.sortBy = sortBy;
}

public int getSortBy() {
    return sortBy;
}

@HandlesEvent("showPrevious")
public Resolution showPrevious() {
    int numberOfRecords = getLastRecord() - getFirstRecord() + 1;
    setFirstRecord(getFirstRecord() - numberOfRecords);
    setLastRecord(getFirstRecord() + numberOfRecords - 1);
    return defaultHandler();
}

@HandlesEvent("showNext")
public Resolution showNext() {
    int numberOfRecords = getLastRecord() - getFirstRecord() + 1;
    setLastRecord(getLastRecord() + numberOfRecords);
    setFirstRecord(getLastRecord() - numberOfRecords + 1);
    return defaultHandler();
}

@HandlesEvent("showLast")
public Resolution showLast() {
    AutoFile file = getFile();
    if (file != null) {
        int lastRecord = file.getSize();
        int firstRecord = lastRecord - 9;
        setFirstRecord(firstRecord);
        setLastRecord(lastRecord);
    }
    return defaultHandler();
}
A: 

I presume from the annotations that this is Stripes. What is this code doing? How much of it is boilerplate and how much addresses your problem? What's an Autofile? What do the magic numbers 1 and 10 mean?

More importantly, what did you call, what did it return and how is that wrong? You state that "it is returning nothing as my last set of records", but since the getLastRecord() call returns an int, it's not possible that you mean this was returning null. Without any comments in your code it's just not possible to understand what the problem is here.

Please - state the sequence of method calls you made, what you expected the result to be, and what the result actually was. As it stands I really can't extract the question from your post and I don't expect other people will be able to either.

(I know this shouldn't really be posted as an answer, but I fully intend to edit it into one as soon as I know what the question is, and I needed more than a comment's amount of space...)

Andrzej Doyle
A: 

the main problem is with the "show last" section of the code. I am trying to show the last 10 records of a table, but when i execute the program, i am getting that the program is showing record 258 of 258 but there is no record showing at all. i am really trying to fix a program that someone else started.

A: 

It could be zero-based, in which case you would want to set lastRecord to file.getSize()-1. But as dtsazza said, we need more context.

Relic