Hello,

I'm using the Sun System Application Server 8.2 in combination with the jdk 1.6 
and xdoclet 1.2.3.

When generating the ejb-jar.xml for my Session-EJB, there are a couple of 
issues I've not solved currently to get a working ear file.

1. issue:
The Session-EJB does not register itself in jndi under the specified name.

2. issue:
The resource-ref does not specify the jndi-name as well as userid and passwd.

All this issues can be worked around by editing the ear file with the 
deploytool delivered with the server.
Is there a way to create the necessary sun-ejb-jar.xml file, so I don't have to 
work around this issues?

Below is the source of my ejb:

package jav18.ejb;

import jav18.utils.Frage;

import java.io.IOException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.ejb.EJBException;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * 
 * <!-- begin-user-doc --> A generated session bean <!-- end-user-doc --> * <!--
 * begin-xdoclet-definition -->
 * 
 * @ejb.bean name="Umfrage" description="Einfache Umfrage als Session-EJB
 *           (Lehrheft JAV18)" display-name="ejb/UmfrageJNDI"
 *           local-jndi-name="ejb/UmfrageJNDI" jndi-name="ejb/UmfrageJNDI"
 *           type="Stateful" transaction-type="Bean"
 * @ejb.resource-ref res-ref-name="jdbc/Fragen" res-type="javax.sql.DataSource"
 *                   res-auth="Application" jndi-name="jdbc/Oracle"
 * @generated
 */

public class UmfrageBean implements javax.ejb.SessionBean {
    /**
     * 
     */
    private int teilnehmer;

    private double average;

    private int bereich;

    private Connection connection;

    int frageID;

    String frage, queryString;

    /**
     * 
     * <!-- begin-xdoclet-definition -->
     * 
     * @ejb.create-method view-type="remote" <!-- end-xdoclet-definition -->
     * @generated
     * 
     */
    public void ejbCreate() {
        try {
            connection = holeOracleConn();
            teilnehmer = 0;
            average = 0.0;
            bereich = 0;
            frageID = 0;
            frage = null;
            queryString = null;
        } catch (IOException e) {
            System.out.println("Error while creating " + "database connection"
                    + e.getMessage());
        }
    }

    /**
     * 
     * <!-- begin-xdoclet-definition -->
     * 
     * @ejb.interface-method view-type="remote" <!-- end-xdoclet-definition
     *                       -->
     * 
     */
    public Frage getFrage(int frageID) {
        if (queryString == null)
            dbAbfrage(frageID);
        return new Frage(frage, bereich, teilnehmer, average);
    }

    /**
     * Setzt die Antwort
     * 
     * @ejb.interface-method view-type="remote"
     */
    public void setAntwort(int wert) {
        average = (average * teilnehmer + wert) / (teilnehmer + 1);
        teilnehmer++;
        queryString = "UPDATE Fragen SET average=" + average + ", teilnehmer="
        + teilnehmer + " WHERE frageID=" + frageID;
        try {
            PreparedStatement stmt = connection.prepareStatement(queryString);
            stmt.executeUpdate();
        } catch (SQLException e) {
            System.out.println("Error while setting data: " + e.getMessage());
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() throws EJBException, RemoteException {
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() throws EJBException, RemoteException {
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() throws EJBException, RemoteException {
        try {
            connection.close();
        } catch (SQLException e) {
            throw new EJBException("Error while closing "
                    + "Database connection: " + e.getMessage());
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    public void setSessionContext(SessionContext arg0) throws EJBException,
    RemoteException {
    }

    /**
     * 
     */
    public UmfrageBean() {
        teilnehmer = 0;
        average = 0.0;
        bereich = 7;
    }

    private Connection holeOracleConn() throws IOException {
        DataSource ds = null;
        try {
            InitialContext ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("jdbc/Fragen");
        } catch (NamingException e) {
            throw new IOException("NamingException while "
                    + "looking up DBContext: " + e.getMessage());
        }
        try {
            Connection conn = null;
            if (ds != null)
                conn = ds.getConnection();
            return conn;
        } catch (SQLException e) {
            throw new IOException("SQLException while "
                    + "getting DBConnection: " + e.getMessage());
        }
    }

    private void dbAbfrage(int frageID) {
        queryString = "SELECT * FROM Fragen where frageID=" + frageID;
        try {
            PreparedStatement stmt = connection.prepareStatement(queryString);
            ResultSet res = stmt.executeQuery();
            if (res.next()) {
                teilnehmer = res.getInt("teilnehmer");
                average = res.getDouble("average");
                bereich = res.getInt("bereich");
                frageID = res.getInt("frageID");
                frage = res.getString("frage");
            }
        } catch (SQLException e) {
            System.out
            .println("Error while retrieving data: " + e.getMessage());
        }
    }
}


With kind regards
Florian Reiser
-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
xdoclet-user mailing list
xdoclet-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to