_Dealing with Java Persistence_
by Johnny Martin


Listing One
<code fileSuffix=.cpp sect=3 kind=String>
/* Class:     %underScoredPackageName%_%className%
 * Method:    %methodname%
 * Signature: (I)%Ljava/lang/String%
 */
JNIEXPORT jstring JNICALL
Java_%underScoredPackageName%_%className%_%methodname%__I
  (JNIEnv * env, jobject obj, jint handle) {
  ooHandle(%className%) & %lowerCaseClassName% = *(ooHandle(%className% )*) handle;
  return env->NewStringUTF(%lowerCaseClassName%->%name%());
}

Listing Two
package COM.objectGuild.directExpress;

class Patient {
  int medicalID;
  String name;
  String ssn;
  Chart myChart;
  transient int guiCount;
}


Listing Three
  /** DO NOT EDIT. This file is generated by Direct Express. */

package COM.objectGuild.directExpress;

class Patient {
  /*persistent int medicalID;*/
  /*persistent String name;*/
  /*persistent String ssn;*/
  /*persistent Chart myChart;*/
  int guiCount;

  /** Return the medicalID field of class Patient object
   */
  public int medicalID() throws OGDBException {
    return p_medicalID(counterpart());
  }

  /** Set the medicalID field of the Patient object to the specified int
   */
  public void medicalID(int inmedicalID) throws OGDBException {
    p_medicalID(counterpart(),inmedicalID);
  }

  /** Native method that creates the counterpart in C++.
   * @return Address of the handle to the C++ object.
   */
  private native int makeCxxCounterpart();

  /**
   * Private native methods for medicalID
   */
  private native int p_medicalID (int handle) throws OGDBException;
  private native void p_medicalID (int handle, int medicalID)
    throws OGDBException;

  ...

}


Listing Four
class Patient : public ooObj {
  private:
    int _medicalID;
  int medicalID() const {
    return _medicalID;
  }
  void medicalID (int medicalID) {
    _medicalID = medicalID;
  }


Listing Five
/* Class:     COM_objectGuild_directExpress_Patient
 * Method:    medicalID
 * Signature: (I)INT
 */
JNIEXPORT jint JNICALL
Java_COM_objectGuild_directExpress_Patient_medicalID__I
  (JNIEnv * env, jobject obj, jint handle) {
  ooHandle(Patient) & patient = *(ooHandle(Patient )*) handle;
  return patient->_medicalID();
}
/* Class:     COM_objectGuild_directExpress_Patient
 * Method:    medicalID
 * Signature: (II)INT
 */
JNIEXPORT void JNICALL
Java_COM_objectGuild_directExpress_Patient_medicalID__IINT
  (JNIEnv * env, jobject obj, jint handle, int j_medicalID) {
  ooHandle(Patient) & patient = *(ooHandle(Patient )*) handle;
  patient->medicalID(j_medicalID);
}


