• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

My seek point is calculated correctly?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting with this formula:


my calculation is correct?

I ask this because when I create a record with the method create () an error is occurring:




Turns out doing a loop in the test often is the Customer ID is recorded with only 7 digits. I insert this:




When you do this, often the record is recorded with the customer ID with seven digits:
Contractor Teste --- Rio de Janeiro --- Tecnology --- 2 --- $100.00 --- 1234567


I do not know if this error can be caused because of an incorrect formula to seek point?

could be?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roman,

Welcome to the ranch!

Let me ask you some questions:
a) "the total size of all records", i guess you mean "the total size of all fields in a record"
b) does your recordNumber start at 0 or 1?
c) in my db-schema i have first a delete flag (indicating if that record is a deleted or a valid record) and then i have the actual record. did you add that byte (or bytes) to your sizeRecords?

your formula you use looks fine to me (if of course recNo starts at 1): dataOffset + (recNo - 1) * recordLength


 
Roman Traze
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:Hi Roman,

Welcome to the ranch!

Let me ask you some questions:
a) "the total size of all records", i guess you mean "the total size of all fields in a record"
b) does your recordNumber start at 0 or 1?
c) in my db-schema i have first a delete flag (indicating if that record is a deleted or a valid record) and then i have the actual record. did you add that byte (or bytes) to your sizeRecords?

your formula you use looks fine to me (if of course recNo starts at 1): dataOffset + (recNo - 1) * recordLength




a) sorry, you are right, the total size of all fields in a record

b) my recordNumber start on 1

c) I'm using for checking the registry ( VALID_FLAG = 0; or INVALID_FLAG = 0xFF;)


the problem is that I do debug, but I can not find the error which he writes only seven digits in the customer ID.
I often run and is NOT a problem, it works perfect.
The behavior is random.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
random behavior is idd a big problem to debug I had also a problem with reading/writing the file but i was lucky: problem appeared with each run, so the bug was found easily.

don't forget to start each run with a brand new copy of your data file so you are completely sure the data isn't already corrupted

a) what's the length of all your fields?
b) what's the size of the "deleted" flag (according to your instruction)
c) what is getSizeRecord() returning? the length of all your fields? or the length of all your fields + the size of the deleted flag?
d) if you create your record don't forget to write the "deleted"-flag also


 
Roman Traze
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:random behavior is idd a big problem to debug I had also a problem with reading/writing the file but i was lucky: problem appeared with each run, so the bug was found easily.

don't forget to start each run with a brand new copy of your data file so you are completely sure the data isn't already corrupted

a) what's the length of all your fields?
b) what's the size of the "deleted" flag (according to your instruction)
c) what is getSizeRecord() returning? the length of all your fields? or the length of all your fields + the size of the deleted flag?
d) if you create your record don't forget to write the "deleted"-flag also




my instruction says : 1 byte "deleted" flag. 0 implies valid record, 0xFF implies deleted record
getSizeRecord() returning == 183 and the length of all my fields (not include delete flag)


if you create your record don't forget to write the "deleted"-flag also



I do not understand your statement, in fact when I create a record, I write a "valid" flag, look:





I did something wrong in code?


 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


my calculation is correct?

I ask this because when I create a record with the method create () an error is occurring:



you don't use the calculateSeekPoint-method in your create-method, because you use seek(getFile().length());

getSizeRecord() returning == 183 and the length of all my fields (not include delete flag)



if it returns the length of all my fields, your calculate method is wrong, it should be



because the length of a record = length of all your fields + the deleted/valid flag
 
Roman Traze
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:


my calculation is correct?

I ask this because when I create a record with the method create () an error is occurring:



you don't use the calculateSeekPoint-method in your create-method, because you use seek(getFile().length());

getSizeRecord() returning == 183 and the length of all my fields (not include delete flag)



if it returns the length of all my fields, your calculate method is wrong, it should be



because the length of a record = length of all your fields + the deleted/valid flag




you are correct, I do not use this method calculateSeekPoint() for create, I use it seek(getFile().length().

I do not need to use:

the method of calculating the size of the records, I start with 1, look:


this method I set each field in the column and its size, all are correct I have checked.

In fact the exception that I reported above java.io.EOFException , occurs during the read() method and not on create().

Now I'm just testing the method create, and yes still entering only seven digits, but always random.

My instructions see:

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record



and I include this:


this is working correctly, listing all records perfect.


Frankly, I do not know where more can be the error.




 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know your record is incomplete? I mean, how do you read it from the database?

Try writing only one record and see if the record is ok. (check it with a byte editor like HxD).
Write another one and check if the previous record is still ok (maybe you're overwriting the last digit?).
If it's still ok, write new records until you see the error happening, maybe you'll find out what's going wrong (do a debugging session in you IDE).
If the byte editor says everything is ok, maybe the error is in your readRecord functionality.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just said to add 1 because i asked about the getSizeRecord()

and you said

returning == 183 and the length of all my fields (not include delete flag)



so i concluded that you didn't add the length of the deleted flag, but apparently you did add it

if you sysout dataValues, does it show all expected info or not?

before you create the record do a sysout from the length of the file. after writing the record to the file, do the same again. it should be a difference of 183 bytes. is that true?
 
reply
    Bookmark Topic Watch Topic
  • New Topic