Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NX: Some question about DBAccess

 
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.
 
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{}
}
 
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Kuzmin,
Your post was moved to a https://coderanch.com:80/t/568859";" target="_new" rel="nofollow">new topic.
 
BWA HA HA HA HA HA HA! Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic