小妹请各位SCJDgg帮个忙

programergirl 2003-08-24 09:48:55
小妹现在正在做285的程序设计题,考试票即将到期,目前被一些IO和lock问题困扰,不知哪位SCJDgg肯给小妹一些指教?请愿意帮忙的SCJDgg留下信箱,以便小妹请教。
...全文
30 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyw8021 2003-08-27
  • 打赏
  • 举报
回复
可以交个朋友吗。我还没有一个女程序员朋友
我的QQ号是:51436222
MSN:dwei0805@hotmail.com
lymkelly 2003-08-27
  • 打赏
  • 举报
回复
帮不上忙,up一下
programergirl 2003-08-27
  • 打赏
  • 举报
回复
小妹明天就正式上课了,笔试考试票是9月30日到期。信箱是sccdgirl1@tom.com,希望各位gg能尽快帮助指点迷津。
RichardKong 2003-08-26
  • 打赏
  • 举报
回复
synchronized不一定就做方法的修饰符,还可以作同步块,另外还有一个volatile修饰符,作用于字段,作用与synchronized差不多,就是基本没有人用。所以实现接口不是困难,由于本人E文太差,其他问题现在只能关注。
RichardKong 2003-08-25
  • 打赏
  • 举报
回复
问题太长 估计是她怕没有人愿意帮忙, 我这里也有 发出来 希望她不见怪
下面是她的问题,文字略有改动 >>>
首先谢谢大家的仗义相助。目前小妹作的是一个订房系统,主要在IO
和lock方面被捆扰。在sun的文挡中,给了一个server端的interface,原文如下:

Server
Required Interface
Your data access class must be called "Data.java", must be in a package called "s
uncertify.db", and must implement the following interface:

package suncertify.db;
public interface DBAccess
{
// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] readRecord(long recNo)
throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n]. Throws SecurityException
// if the record is locked with a cookie other than lockCookie.
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public long[] findByCriteria(String[] criteria);
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public long createRecord(String [] data)
throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// Returned value is a cookie that must be used when the record is unlocked,
// updated, or deleted. If the specified record is already locked by a different
// client, the current thread gives up the CPU and consumes no CPU cycles until
// the record is unlocked.
public long lockRecord(long recNo)
throws RecordNotFoundException;
// Releases the lock on a record. Cookie must be the cookie
// returned when the record was locked; otherwise throws SecurityException.
public void unlock(long recNo, long cookie)
throws SecurityException;
}

Any unimplemented exceptions in this interface must all be created as member clas
ses of the suncertify.db package. Each must have a zero argument constructor and
a second constructor that takes a String that serves as the exception's descripti
on.

Any methods that throw RecordNotFoundException should do so if a specified record
does not exist or is marked as deleted in the database file.

Network Approaches
Your choice of RMI or serialized objects will not affect your grade, but no other
approach is acceptable. In either case, the program must allow the user to speci
fy the location of the database, and it must also accept an indication that a loc
al database is to be used, in which case, the networking must be bypassed entirel
y. No authentication is required for database access.
Locking
Your server must be capable of handling multiple concurrent requests, and as part
of this capability, must provide locking functionality as specified in the inter
face provided above. You may assume that at any moment, at most one program is a
ccessing the database file; therefore your locking system only needs to be concer
ned with multiple concurrent clients of your server. Any attempt to lock a resou
rce that is already locked should cause the current thread to give up the CPU, co
nsuming no CPU cycles until the desired resource becomes available.
而关于文件是这样写的:

Data file Format
The format of data in the database file is as follows:
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

Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Record containing fields in order specified in schema section, no separators betw
een fields, each field fixed length at maximum specified in schema information

End of file

All numeric values are stored in the header information use the formats of the Da
taInputStream and DataOutputStream classes. All text values, and all fields (whic
h are text only), contain only 8 bit characters, null terminated if less than the
maximum length for the field. The character encoding is 8 bit US ASCII.

Database schema
The database that URLyBird uses contains the following fields: Field descriptive
name Database field name Field length Detailed description
Hotel Name name 64 The name of the hotel this vacancy record relates to
City location 64 The location of this hotel
Maximum occupancy of this room size 4 The maximum number of people permitted in t
his room, not including infants
Is the room smoking or non-smoking smoking 1 Flag indicating if smoking is permit
ted. Valid values are "Y" indicating a smoking room, and "N" indicating a non-smo
king room
Price per night rate 8 Charge per night for the room. This field includes the cur
rency symbol
Date available date 10 The single night to which this record relates, format is y
yyy/mm/dd.
Customer holding this record owner 8 The id value (an 8 digit number) of the cust
omer who has booked this. Note that for this application, you should assume that
customers and CSRs know their customer ids. The system you are writing does not i
nteract with these numbers, rather it simply records them. If this field is all b
lanks, the record is available for sale.

主要在实现这个DBAccess interface方面有困难。


目前在Data file Format中的The format of data in the database file和Database schem
a之间的关系没搞懂,在db文件中似乎没有看到The format of data in the database file的
东西。致使小妹对实现DBaccess接口中的方法还有些问题。在给的db文件里第一条记录居然没
有什麽实质内容,让人费解(照理说应该是保存此db文件的信息)。在Data file Format中提
到的delected flag在记录中似乎也没有。关于luck也出乎我的意料,本来我想的是用synchr
onized,但根据给的interface,又不行,不知该怎麽做。还有,在interface中的readRecor
d方法的recNo参数到底是record中的哪一个?请尽快给我一个答复,谢谢!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧