ServerDataModuleBean.java~73~
上传用户:jnhyscl
上传日期:2010-03-08
资源大小:345k
文件大小:5k
- package shiponline;
- import javax.ejb.*;
- import com.borland.dx.dataset.*;
- import com.borland.dx.ejb.*;
- public class ServerDataModuleBean implements SessionBean {
- SessionContext sessionContext;
- LocalEntityBeanProvider vaoPortProvider = new LocalEntityBeanProvider();
- LocalEntityBeanResolver vaoPortResolver = new LocalEntityBeanResolver();
- TableDataSet portDataSet = new TableDataSet();
- VaoPortHome vaoPortHome;
- SequenceGeneratorLocalHome sequenceHome;
- ParameterRow parameterRow = new ParameterRow();
- RowData[] parameterArray = new RowData[3];
- Column column1 = new Column("ProvideType","ProvideType",Variant.STRING);
- Column column2 = new Column("ProvideValue","ProvideValue",Variant.INT);
- public void ejbCreate() throws CreateException {
- /**@todo Complete this method*/
- }
- public void ejbRemove() {
- /**@todo Complete this method*/
- }
- public void ejbActivate() {
- /**@todo Complete this method*/
- }
- public void ejbPassivate() {
- /**@todo Complete this method*/
- }
- public void setSessionContext(SessionContext sessionContext) {
- this.sessionContext = sessionContext;
- try {
- javax.naming.Context context = new javax.naming.InitialContext();
- vaoPortHome = (VaoPortHome) context.lookup("java:comp/env/VaoPort");
- sequenceHome=(SequenceGeneratorLocalHome)context.lookup("java:comp/env/SequenceGenerator");
- vaoPortProvider.setEjbLocal(VaoPort.class);
- vaoPortProvider.setEjbLocalHome(vaoPortHome);
- vaoPortResolver.setEjbLocal(VaoPort.class);
- vaoPortResolver.setEjbLocalHome(vaoPortHome);
- }
- catch (Exception ex) {
- throw new EJBException(ex);
- }
- }
- public VaoPort newVaoPort() {
- /**@todo Complete this method*/
- return null;
- }
- public void addVaoPort(DataSetData[] dataArray) {
- VaoPort newVaoPort=null;
- try{
- newVaoPort = vaoPortHome.create(new Integer(1));
- }catch(Exception e){
- e.printStackTrace();
- }
- resolveVaoPort(dataArray);
- }
- public ServerDataModuleBean() {
- try {
- jbInit();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- private void jbInit() {
- try{
- parameterArray[0]= new RowData();
- parameterRow.addColumn(column2);
- vaoPortResolver.addLocalEntityBeanCreateListener(new com.borland.dx.ejb.
- LocalEntityBeanCreateListener() {
- public void create(LocalEntityBeanCreateEvent e) {
- System.out.println("ylf");
- //VaoPort vaoPort = newVaoPort();
- //e.getLocalEntityBeanResolver().storeDataRowToEntityBean(e.getDataRow(),vaoPort);
- }
- });
- vaoPortProvider.addLocalEntityBeanFindListener(new com.borland.dx.ejb.
- LocalEntityBeanFindListener() {
- public void findEntityBeans(LocalEntityBeanFindEvent e) {
- System.out.println(e.getSource());
- System.out.println("dddddddddddddddddddddddddddddddd");
- try {
- ReadWriteRow paramRow = e.getLocalEntityBeanProvider().
- getParameterRow();
- System.out.println(paramRow.toString());
- if (paramRow != null) {
- Integer portid = new Integer(paramRow.getInt(0));
- System.out.println("ccccccccc="+portid);
- e.setEntityBeanLocal(vaoPortHome.findByPrimaryKey(portid));
- }
- }
- catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- }catch(Exception e){
- }
- portDataSet.setProvider(vaoPortProvider);
- portDataSet.setResolver(vaoPortResolver);
- }
- public DataSetData[] resolveVaoPort(DataSetData[] dataSetDataArray) {
- return EntityBeanConnection.saveChanges(dataSetDataArray, new DataSet [] {portDataSet});
- }
- public DataSetData[] providePort(RowData[] parameterArray, RowData[] masterArray) {
- return EntityBeanConnection.provideDataSets(new StorageDataSet [] {portDataSet}, parameterArray, masterArray);
- }
- public DataSetData[] addNewPort(){
- VaoPort newVaoPort;
- System.out.println("cccccc3");
- try {
- int id = newId("VAOPORT");
- newVaoPort = vaoPortHome.create(id);
- System.out.println("cccccc13");
- System.out.println("cccccc14");
- parameterRow.setInt(0,id);
- System.out.println("cccccc15");
- parameterArray[0].load(parameterRow);
- System.out.println("cccccc16");
- DataSetData[] ds = EntityBeanConnection.provideDataSets(new StorageDataSet [] { portDataSet}, parameterArray, null);
- System.out.println("cccccc17");
- return ds;
- } catch (Exception ex) {
- System.out.println("lihang"+ex);
- return null;
- }
- }
- public int newId(String sequence_name){
- try {
- System.out.println("cccccc4");
- SequenceGeneratorLocal seq = sequenceHome.create(sequence_name);
- System.out.println("cccccccc"+seq.nextSequenceNumber(sequence_name));
- return seq.nextSequenceNumber(sequence_name);
- }catch (Exception ex) {
- throw new EJBException("Error generating id for : " + sequence_name);
- }
- }
- }