Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B & S: stuck on calculating offset for updateRecord()

 
Paul O'Leary
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to determine the offset to write the owner id value, is the length of a record determined by the length of elements in the data array or as per the database schema specified lengths?

Also is the headerLength determined by the filePointer position after reading the column owner heading?


Thanks,
Paul.
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should be determined as per the schema. what you might get in the data array could be strings of length lesser than that specified in schema.

eg if name length is 32 chars, then in the data[0], you might get something like "Bunarotti".

I didnt understand you second question about header lenght determination...?
 
Paul O'Leary
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mary John:
it should be determined as per the schema. what you might get in the data array could be strings of length lesser than that specified in schema.

eg if name length is 32 chars, then in the data[0], you might get something like "Bunarotti".

I didnt understand you second question about header lenght determination...?


Thanks Mary for your reply, my second question is basically about how the header offset is calculated ie. is it the number of bytes that the file pointer offset is at when it has read the last column heading for the 'owner' column?

Also should the contents of the data[] overwrite the existing record fields when the Customer id is written to the data file?
[ April 02, 2008: Message edited by: Paul O'Leary ]
 
Paul O'Leary
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still confused as to how the header length is calculated correctly since the Customer ID is being written to the next row's name column in the JTable instead of the owner column. I am writing the Customer ID to the owner column as follows:

<code>
int lengthRecord = 32 + 64 + 64 + 6 + 8 + 8;
long offset = 0;
offset = headerLength + recNo * (lengthRecord + 1);
//skip the delete flag with an additional byte
offset = offset + 1;
StringBuilder out = new StringBuilder(8);
out.append(data[5].trim()); //Customer id
try{
raf.seek(offset);
raf.write(out.toString().getBytes());
raf.close();
} catch(IOException ex){}
</code>

I am currently calculating the header length by raf.getFilePointer() after reading the Column headings.
I understand the header length is calculated by the size of the file from the beginning of the file to where the records start.
Can anyone comment on how to determine the header length correctly?
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got your question now.
so what I did ( I am not sure if thats the right way, for now) is just calculate the header length from the given schema information

I got mine as 70, and I use that hardcoded in my application.

I guess your is also a good way. Did you find any problems with your way of doing it?
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still confused as to how the header length is calculated correctly since the Customer ID is being written to the next row's name column in the JTable instead of the owner column. I am writing the Customer ID to the owner column as follows


Why would you want to write customer id alone? Dont you have an update method which sends a data array as argument and that needs every column to get updated?

I have the following B&S update method
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException

here i make a string of size "recordLength" and then write the entire string starting at the record's first byte position

in your business method book(), you can choose to provide new value for owner and format your data array there.
I dont know if you thought already about it and your question is something else?
 
Paul O'Leary
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mary John:
I am still confused as to how the header length is calculated correctly since the Customer ID is being written to the next row's name column in the JTable instead of the owner column. I am writing the Customer ID to the owner column as follows

Why would you want to write customer id alone? Dont you have an update method which sends a data array as argument and that needs every column to get updated?

I have the following B&S update method
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException

here i make a string of size "recordLength" and then write the entire string starting at the record's first byte position

in your business method book(), you can choose to provide new value for owner and format your data array there.
I dont know if you thought already about it and your question is something else?


Thanks alot for clearing that up, I had assumed the updateRecord() was for booking the subcontractor only. I have finally been able to calculate the offset correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic