Skip to content

Commit

Permalink
Changes for Match criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
nrkkalyan committed Sep 8, 2011
1 parent 0c68113 commit f05ea23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 75 deletions.
74 changes: 2 additions & 72 deletions src/com/unitedcaterers/db/DataBaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -157,68 +154,6 @@ private String[] parseRecord(String recorddata) {
return returnValue;
}

private synchronized Room roomInstanceFromByteArray(final byte[] array, int recordNumber) throws IOException {
if (array == null) {
throw new IllegalArgumentException("Invalid parameter length");
}

class RecordFieldReader {

private int offset1 = 1;

private String read(int length) throws UnsupportedEncodingException {
String str = new String(array, offset1, length, CHARSET);
offset1 += length;
return str.trim();
}
}
RecordFieldReader readRecord = new RecordFieldReader();
Room room = new Room();
room.setRecordNumber(recordNumber);
room.setValid(true);
room.setName(readRecord.read(DBConstants.HOTEL_NAME_LENGTH));
room.setLocation(readRecord.read(DBConstants.CITY_LENGTH));
room.setSize(readRecord.read(DBConstants.SIZE_LENGTH));
room.setSmoking(readRecord.read(DBConstants.SMOKING_LENGTH));
room.setRate(readRecord.read(DBConstants.RATE_LENGTH));
room.setDate(dateStringToDate(readRecord.read(DBConstants.DATE_LENGTH)));
room.setCustomerId(readRecord.read(DBConstants.CUSTOMER_ID_LENGTH));

return room;

}

private boolean validityFlagToboolean(byte flag) {
return DBConstants.VALID_RECORD_FLAG == flag;
}

public Date dateStringToDate(String date) {
if (date != null) {
try {
synchronized (DBConstants.DATEFORMAT) {
return DBConstants.DATEFORMAT.parse(date);
}
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
return null;
}

public static Boolean smokingFlagToBoolean(String flag) {
if (DBConstants.SMOKING_FLAG_YES.equals(flag)) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}

private synchronized String readNBytes(byte[] input, int length) throws IOException {
String str = new String(input, offset, length, CHARSET);
offset += length;
return str.trim();
}

/**
* This method takes the record number, record data, and the lockkey and
* update the record.
Expand Down Expand Up @@ -373,15 +308,13 @@ public synchronized int[] find(String[] criteria) {
recno++;
continue;
}
Room room = roomInstanceFromByteArray(ba, recno);
System.out.println(room);
String[] fielddata = parseRecord(rec);
boolean match = true;
for (int i = 0; i < fieldnames.length; i++) {
if (criteria[i] == null) {
continue;
}
if (!fielddata[i].startsWith(criteria[i])) {
if (!fielddata[i].matches(criteria[i])) {
match = false;
break;
}
Expand Down Expand Up @@ -446,13 +379,10 @@ private int getDeletedRecordNo() {
int retval = 0;
ras.seek(offset);
byte[] ba = new byte[recordlength];
int noofbytesread = 0;
while ((noofbytesread = ras.read(ba)) == recordlength) {

while (ras.read(ba) == recordlength) {
if (ba[0] == DELETEDROW_BYTE1) {
return retval;
}

retval++;
ba = new byte[recordlength];
}
Expand Down
6 changes: 3 additions & 3 deletions unitedcaterers.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Properties captured by PropertiesDialog : com.unitedcaterers.client.gui.UCClientPropertiesDialog
#Wed Sep 07 23:37:39 CEST 2011
server.dbfile=C\:\\SCJD\\db-1x1.db
#Thu Sep 08 22:08:45 CEST 2011
server.dbmagiccode=UCDB
server.dbfile=C\:\\SCJD\\db-1x1.db
server.port=1099
client.serverhost=localhost
client.localdbmagiccode=UCDB
client.serverport=1099
client.localdbfile=C\:\\SCJD\\db-1x1.db
client.serverport=1099

0 comments on commit f05ea23

Please sign in to comment.