David Chan

Ranch Hand
+ Follow
since Jun 11, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Chan

After several rounds of mailing, Sun is now delivering a new developer certificate to me Let me summarize the procedures for the replacement.

1. Before you send the request to Sun, go to http://www.certmanager.net/sun (no slash at the end XD) and verify your personal information if you have not visited this website for a long time like me. Just press the 'Verify' button if you have nothing to update.

2. Send cert replacement request to who2contact@sun.com You need to fill your name, prometric ID (or Sun Candidate ID), cert name (exam code also) in the email.

3. Sun will reply you in 2-5 working days.

It seems there is no service charge needed for the replacement. I am not sure, at least they did not ask me.

I will keep my new 'reborn' cert in secure area. Thank you for reading my post
I lost my developer certificate... Will Sun re-give me a new cert to me if I ask them? If yes, how much it cost and what info I need to tell them?

http://www.certmanager.net/sun/ is down at the moment. I cannot check my exam info...


SCJP,SCJD,SCWCD,SCBCD,OCA
Now the entity bean is now working

I think there is some problem in the deploytool IDE. In conclusion, if you have added a new finder method, you have to rely on the [Generate default SQL] function to generate sql code. Manually adding the select statement seems not work...

<method-param>double</method-param>
double is OK

Thank you for reply.
Dear all,

I can run the create method successully but when I try to run the find method, the client got the following message:

got a context
did the narrow
org.omg.CORBA.UNKNOWN: vmcid: 0x0 minor code: 0 completed: Maybe
at com.sun.corba.ee.internal.core.UEInfoServiceContext.<init>(UEInfoServiceContext.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27
)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at com.sun.corba.ee.internal.core.ServiceContextData.makeServiceContext(ServiceContextData.java:115)
at com.sun.corba.ee.internal.core.ServiceContexts.<init>(ServiceContexts.java:110)



When I open the j2ee server log ($J2EE_HOME\logs\mcqapp_lab1\j2ee\j2ee\error.log), the file shows:

ejb20Finder method = public abstract java.util.Collection headfirst.CustomerHome.findByCreditLimit(double) throws javax.ejb.FinderException,java.rmi.RemoteException
ejb20Finder ejbql = SELECT OBJECT(o) FROM CustomerBeanTable AS o WHERE o.limit = ?1
ejb20Finder query = sql not generated yet
javax.ejb.EJBException: nested exception is: SQL Exception: Syntax error: Encountered "sql" at line 1, column 1.
SQL Exception: Syntax error: Encountered "sql" at line 1, column 1.
at c8e.p.i._f1(Unknown Source)
at c8e.p.q._b84(Unknown Source)
at c8e.p.q.handleException(Unknown Source)
at c8e.p.n.handleException(Unknown Source)
at c8e.p.p.handleException(Unknown Source)
at c8e.p.g.<init>(Unknown Source)
at c8e.ct.a.<init>(Unknown Source)
at c8e.ct.e.newLocalPreparedStatement(Unknown Source)
at c8e.p.n.prepareStatement(Unknown Source)
at c8e.ct.e.prepareStatement(Unknown Source)
at c8e.p.n.prepareStatement(Unknown Source)

It seems there is something wrong in the EJB-SQL select statement, however,
the ejb application passed the Verifer checking. Anyone know how to solve problem? Please help. Thank you.

--- Development environment
OS: NT4.0 with sp 6
j2se ver: 1.4.2_03
j2ee ver: 1.3.1
ejb IDE: java deploytool
database: java/cloudscape

--- Deployment Descriptor
<ejb-jar>

<display-name>Ejb1</display-name>

<enterprise-beans>

<entity>

<display-name>CustomerBean</display-name>

<ejb-name>CustomerBean</ejb-name>

<home>headfirst.CustomerHome</home>

<remote>headfirst.Customer</remote>

<ejb-class>headfirst.CustomerBean</ejb-class>

<persistence-type>Container</persistence-type>

<prim-key-class>java.lang.String</prim-key-class>

<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>

<abstract-schema-name>CustomerBeanTable</abstract-schema-name>

<cmp-field>

<description>no description</description>

<field-name>last</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>limit</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>first</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>custAddress</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>pK</field-name>

</cmp-field>

<primkey-field>pK</primkey-field>

<security-identity>

<description></description>

<use-caller-identity></use-caller-identity>

</security-identity>

<query>

<description></description>

<query-method>

<method-name>findByCreditLimit</method-name>

<method-params>

<method-param>double</method-param>

</method-params>

</query-method>

<ejb-ql>SELECT OBJECT(o) FROM CustomerBeanTable AS o WHERE o.limit = ?1</ejb-ql>

</query>

</entity>

</enterprise-beans>


--- CustomerHome.java source
package headfirst;

import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Collection;

public interface CustomerHome extends EJBHome {
public Customer create(String last, String first, String addr, String ID) throws CreateException, RemoteException;
public Customer findByPrimaryKey(String key) throws FinderException, RemoteException;
public Collection findByCreditLimit(double greaterThanAmt) throws FinderException, RemoteException;
}

--- CustomerClient.java source
Context ic = new InitialContext();
System.out.println("got a context");

Object o = ic.lookup("Customer");
System.out.println("got an object" + o);

CustomerHome home = (CustomerHome) PortableRemoteObject.narrow(o, CustomerHome.class);
System.out.println("did the narrow");

Collection collection = home.findByCreditLimit(100.00);
System.out.println("did the find");
I have downloaded the latest JDK to compile the code, all OK. But I run the application, it failed. Please help.
When I type java -jar runme.jar, show the following error message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/j2sdk1.4.2_03/jre/lib/sparc/motif12/libmawt.so
: ld.so.1: java: fatal: libXm.so.4: open failed: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1456)
at java.lang.Runtime.load0(Runtime.java:737)
at java.lang.System.load(System.java:811)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1477)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)
at sun.awt.DebugHelper.<clinit>(DebugHelper.java:29)
at java.awt.Component.<clinit>(Component.java:506)
at suncertify.RunMe.main(RunMe.java:22)
I have checked the directory /opt/j2sdk1.4.2_03/jre/lib/sparc/, there only have motif21 directory but have no motif12 directory.
My solarix version:
SunOS labppsms 5.6 Generic_105181-28 sun4u sparc SUNW,Ultra-80
JDK version:
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

David
I have downloaded the latest JDK to compile the code, all OK. But I run the application, it failed. Please help.
When I type java -jar runme.jar, show the following error message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/j2sdk1.4.2_03/jre/lib/sparc/motif12/libmawt.so
: ld.so.1: java: fatal: libXm.so.4: open failed: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1456)
at java.lang.Runtime.load0(Runtime.java:737)
at java.lang.System.load(System.java:811)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1477)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)
at sun.awt.DebugHelper.<clinit>(DebugHelper.java:29)
at java.awt.Component.<clinit>(Component.java:506)
at suncertify.RunMe.main(RunMe.java:22)
I have checked the directory /opt/j2sdk1.4.2_03/jre/lib/sparc/, there only have motif21 directory but have no motif12 directory.
My solarix version:
SunOS labppsms 5.6 Generic_105181-28 sun4u sparc SUNW,Ultra-80
JDK version:
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

David
In Max's DVD example, does the server implement as multiple instance or single instance? There is a static Vector variable to keep track of all DVDs that are reserved at any given time, but I do not see any connection factory used in the example (it seems the single instance serves for all client request). Can I say that is single instance and relys on RMI for mutlithreading? If it is single instance server, why he declare the Vector variable as static?
David
In Max's DVD example, does the server implement as multiple instance or single instance? There is a static Vector variable to keep track of all DVDs that are reserved at any given time, but I do not see any connection factory used in the example (it seems the single instance serves for all client request). Can I say that is single instance and relys on RMI for mutlithreading? If it is single instance server, why he declare the Vector variable as static?

David
George,
Thanks for your reply and your solution.
I think it is OK that DataAccessException inherit from IOException to solve the problem. But what if I want to throw BookedAlreadyException, it is not OK to inherit from IOException because record booked already is related to IO error, it just because the application "rule" does not allow.
Is it exception limitation when used with RMI?

David
Sorry, maybe I posted too many source code such that you can find the diff. The main difference between 2 posts is that in updated version the readAll() does not throw RemoteException because Database interface RemoteException does not (as you said).
To simulate my problem is very simple. Copy and paste into java files (totally there are 5 files). Type javac *.java, first time all compilation is OK and you will not get error. Then replace all words IOException by DataAccessException, compile once again, it will appear the error message.
Thanks for your help.

David
*** Previous ****************************************************
public class DatabaseAdapter implements Database {

public List readAll() throws RemoteException,
IOException {

return new Vector();
}
}
*** Updated *****************************************************
import java.io.*;
import java.util.*;
public class DatabaseAdapter implements Database {
public DatabaseAdapter() {
}

public List readAll() throws IOException {

return new Vector();
}
}
Thanks for reply from both of you.
getNextCookie() without synchronized: if just look at CookieGenerator, grader may think the lock-unlock is totally failed due to "++" operation -> automatic failure
getNextCookie() is synchronized: grader may think the lock method is over-synchronized -> bad consideration. Can all graders concentrated enough to notice getNextCookie() in a synchronized block?
I am confused when it is considered as over-synchronized...

David


- if change to: public List readAll() throws DataAccessException


I mean readAll() is changed to throw DataAccessException in ALL files. (i.e. replace words IOException by DataAccessException)
Hope that it will make clear, thanks.

David
Sorry, I have made some mistakes when post the source code previously. The problem is that:
- public List readAll() throws IOException
[All compilation is OK]
- if change to: public List readAll() throws DataAccessException
[javac DatabaseAdapter.java OK]
[javac DatabaseServiceImpl.java FAIL]
DatabaseServiceImpl.java:6: readAll() in DatabaseServiceImpl cannot implement readAll() in Database; overridden method does not throw java.rmi.RemoteException public class DatabaseServiceImpl extends UnicastRemoteObject
Please help, thank you.

David

Here is tested source code:
***********************************************************
import java.io.*;
import java.util.*;
public interface Database {
public List readAll() throws IOException;
}
***********************************************************
import java.io.*;
import java.util.*;
public class DatabaseAdapter implements Database {
public DatabaseAdapter() {
}
public List readAll() throws IOException {
return new Vector();
}
}
***********************************************************
import java.rmi.*;
public interface DatabaseService extends Remote, Database {
}
***********************************************************
import java.io.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
public class DatabaseServiceImpl extends UnicastRemoteObject
implements DatabaseService {
DatabaseAdapter dbAdapter;
public DatabaseServiceImpl() throws RemoteException {
dbAdapter = new DatabaseAdapter();
}
public List readAll() throws RemoteException,
IOException {
return dbAdapter.readAll();
}
}
***********************************************************
public class DataAccessException extends Exception {
public DataAccessException() {
super();
}
public DataAccessException(String message) {
super(message);
}
public DataAccessException(Throwable cause) {
super(cause);
}
public DataAccessException(String message, Throwable cause) {
super(message, cause);
}
}
public interface Database {
public List readAll() throws IOException;
}
public class DatabaseAdapter implements Database {
public List readAll() throws RemoteException,
IOException {

return new Vector();
}
}
public interface DatabaseService extends Remote, Database {
}
public class DatabaseServiceImpl extends UnicastRemoteObject
implements DatabaseService {
public List readAll() throws RemoteException,
IOException {

return dbAdapter.readAll();
}
}
Above files can be compiled fine. The problem is that if the IOException is replaced by DataAccessException which is created by myself, it appears compilation error when compile DatabaseServiceImpl file:
javac DatabaseAdapter.java [OK]
javac DatabaseServiceImpl.java
DatabaseServiceImpl.java:9: readAll() in suncertify.remote.DatabaseServiceImpl cannot implement readAll() in suncertify.db.Database; overridden method does not throw java.rmi.RemoteException public class DatabaseServiceImpl extends UnicastRemoteObject
Here is the exception source code:
package suncertify.db;
public class DataAccessException extends Exception
{
public DataAccessException() {
super();
}
public DataAccessException(String message) {
super(message);
}
public DataAccessException(Throwable cause) {
super(cause);
}
public DataAccessException(String message, Throwable cause) {
super(message, cause);
}
}

Is there any problem in my defined exception?
Thanks for you help.

David
Since my lock-unlock mechanism is performed in server side, my thought is that the cookie value is no need to set very long to prevent the cookie duplication (one sent from clientA and another sent from clientB). But if I generate the cookie just by increment by one, is there any problem if I used with my lock method? Is this cookie generator OK?
public class CookieGenerator {
private static long cookie = 1;
public static long getNextCookie() {
return cookie++;
}
}
public long lockRecord(long recNo)
throws RecordNotFoundException {
synchronized(lockedRecords) {
try {
if(!isValidRecord(recNo))
throw new RecordNotFoundException();
long cookie = CookieGenerator.getNextCookie();
lockedRecords.put(new Long(recNo), new Long(cookie));
return cookie;
} catch(IOException ioe) {
throw new RuntimeException(ioe);
} catch(InterruptedException ire) {
throw new RuntimeException(ire);
}
}
}

David