Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Some question about DBAccess

 
Wu Ming
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server
Required Interface
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
public interface DBAccess{
public String [] readRecord(long recNo) throws RecordNotFoundException;
public void updateRecord(long recNo, String[] data, long lockCookie) throws RecordNotFoundException, SecurityException;
public void deleteRecord(long recNo, long lockCookie) throws RecordNotFoundException, SecurityException;
public long[] findByCriteria(String[] criteria);
public long createRecord(String [] data) throws DuplicateKeyException;
public long lockRecord(long recNo) throws RecordNotFoundException;
public void unlock(long recNo, long cookie) throws SecurityException;
}
Question:
1. can I modify the DBAccess directly? For example, add some methods to this interface. Such as :
public string[] getFieldInfo() ?
2. can I modify the methods in the DBAccess ? For example, add ' synchronized ' to the method?
Thanks.
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wuu.

1. can I modify the DBAccess directly? For example, add some methods to this interface. Such as :
public string[] getFieldInfo() ?

Not sure. But I don't think so. Would be better if you put those methods in your implementation of the interface. Or create a second interface if you have to. Rather don't change what they gave you (except for the comments)

2. can I modify the methods in the DBAccess ? For example, add ' synchronized ' to the method?

Definitely not. You are not allowed to change the method signatures.
 
Wu Ming
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wuu.
quote:
--------------------------------------------------------------------------------
1. can I modify the DBAccess directly? For example, add some methods to this interface. Such as :
public string[] getFieldInfo() ?
--------------------------------------------------------------------------------
Not sure. But I don't think so. Would be better if you put those methods in your implementation of the interface. Or create a second interface if you have to. Rather don't change what they gave you (except for the comments)

Maybe, It is better for me to define another interface implemenation of the interface DBAccess. And then let Data to implementation DBAccess.
quote:
--------------------------------------------------------------------------------
2. can I modify the methods in the DBAccess ? For example, add ' synchronized ' to the method?
--------------------------------------------------------------------------------
Definitely not. You are not allowed to change the method signatures.
--------------------
That is to say, I can not modify any of the methods they provide. even add 'synchronized ' to the method.

Any guy with the NX give me some advice.
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can extend the DBAccess interface and then implement the new, extended, interface in your Data class.
An interface is not concerned with implementation. Synchronizing a method is one way of implementing it. So no, you cannot add "synchronized" to the method definition in the interface, but you can add "synchronized" to your implementation of that method in your Data class.
Hope that helps.
 
Wu Ming
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is to say, if I add 'synchronize ' to the method, it will meet the requirement of the assignment:
***************************************************************
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
*********************************************************************
public Data implements DBAccess{
public synchronized String [] readRecord(long recNo) throws RecordNotFoundException {}
public synchronized void updateRecord(long recNo, String[] data, long lockCookie) throws RecordNotFoundException, SecurityException {}
public synchronized void deleteRecord(long recNo, long lockCookie) throws RecordNotFoundException, SecurityException{}
public synchronized long[] findByCriteria(String[] criteria){}
public synchronized long createRecord(String [] data) throws DuplicateKeyException{}
public synchronized long lockRecord(long recNo) throws RecordNotFoundException{}
public synchronized void unlock(long recNo, long cookie) throws SecurityException{}
}
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
The reason is that is not considered part of a method's signature.
Hope that helps,
George
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Wu. That is fine.
 
Roel De Nijs
Sheriff
Posts: 10374
132
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Kuzmin,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic