Got a question. Did you checked if the criteria array passed to the find(String) method has less or equal number of elements than data?
At this moment, when I've got less elements in criteria array than in data - it's fine, I treat them as they would never exist. But if there are more criterias than fields I'm not handling such a situation, and ArrayIndexOutOfBound is thrown.
Did you used some validation on Data class level?
And another one - did you validate the number of fields passed to create(String) method? I mean - did you check the user provided more (or less) fields than expected from the database file schema?
I've got my own InvalidRecordFormatException which is thrown when something is not OK with the record while reading or writing. The problem is, it is a low-level exception (not on Data Class but in underlying Data Access Manager) and it is checked. Therefore I cannot add it as a throwable from my Data Class...
OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Did you checked if the criteria array passed to the find(String) method has less or equal number of elements than data?
Well champ, in my case, if you pass null or an array whose size is different from the number of fields that a record has, then an IllegalArgumentException is thrown.
And another one - did you validate the number of fields passed to create(String) method?
Yup. The same way, if you pass null, or an array whose size is different from the number of fields of a record, or if any of the elements in the array is null, then an IllegalArgumentException is thrown.
Although I think it is a good idea to have an exception like InvalidRecordFormatException, I'd stay with the ones that already exist in the Java API. But if you decide to stay with InvalidRecordFormatException, then you can make it extend RuntimeException, then you'll be able to throw it wherever you find necessary.
I've decided to leave my InvalidRecordFormatException only for the lower layer, as I use it to indicate possible file corruption. It will still be checked.
In Data class, however, I will use the IllegalArgumentException to indicate that that:
(crate and update methods)
- inserted/updated record is null,
- inserted/updated record's fields number is not equal to defined in the schema,
- criteria's size is BIGGER than the fields number defined in the schema, (less data is OK, as I will assume that the rest of the criterias are not important); null value passed as a criteria is also OK for me - I treat is as a 'find all' situation, just like a criterias filled with nulls, empty strings or mixed nulls and empty strings.
other methods are not tested for null values, as they are primitives.
Just wondering - did you test if the record's number is lower than 0?