实例1:返回INT

Example1
(getting Tblogin's count). 
1. mysql: database(spring), testing table(spring)
2. axisclasspath: ...... D:/mydemos/axis_text/src
3. java codes for server: (D:/mydemos/axis_text/src/)
a) hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
    <property name="myeclipse.connection.profile">mySpring</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/spring</property>
    <property name="connection.username">root</property>
    <property name="connection.password">fangjean</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
   
    <mapping resource="cn/com/mytest/dao/hibernate/Tblogin.hbm.xml" />


</session-factory>

</hibernate-configuration>
2) Tblogin.hbm.xml
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration.                   -->
<!-- Created Wed Jun 11 12:14:47 CST 2008                         -->
<hibernate-mapping package="cn.com.mytest.dao.hibernate">

    <class name="Tblogin" table="tblogin">
        <id name="loginid" column="loginid" type="integer">
            <generator class="increment"/>
        </id>
 
        <property name="logincode" column="logincode" type="string" />
        <property name="loginpwd" column="loginpwd" type="string" />
        <property name="isusable" column="isusable" type="integer" />
        <property name="realname" column="realname" type="string" />
        <property name="loginpwd2" column="loginpwd2" type="string" />
    </class>
   
</hibernate-mapping>
** Tblogin.java省略
3). LoginDaoImpl.java
package cn.com.mytest.dao;

import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;

import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.Query;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

import cn.com.mytest.dao.hibernate.config.SessionFactoryClass;

public class LoginDaoImpl {
    private static final Log log = LogFactory.getLog(LoginDaoImpl.class);
    public void add(Serializable object){
        if(object!=null){
            Session session = null;
            Transaction transaction = null;
           
            try{
                session = SessionFactoryClass.currentSession();
                transaction = session.beginTransaction();
               
                transaction.commit();
               
            }catch(HibernateException hex){
                transaction.rollback();
                log.error("add(Serializable object) error:" + hex.getMessage());
                hex.printStackTrace();
            }catch(Exception ex){
                log.error("add(Serializable object) error:" + ex.getMessage());
                ex.printStackTrace();
            }finally{
                transaction = null;
                SessionFactoryClass.closeSession();
            }
           
        }
       
    }
    public List list(){
        Session session = null;
        List list = new ArrayList();
        try{
            session = SessionFactoryClass.currentSession();
            String hql = "from Tblogin where isusable=0";
            Query query = session.createQuery(hql);
            list = query.list();
           
        }catch(HibernateException hex){
            log.error("add(Serializable object) error:" + hex.getMessage());
            hex.printStackTrace();
        }catch(Exception ex){
            log.error("add(Serializable object) error:" + ex.getMessage());
            ex.printStackTrace();
        }finally{
            SessionFactoryClass.closeSession();
        }
        return list;
    }
           

}
4) LoginImpl.java
package cn.com.mytest.server;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.mytest.dao.hibernate.Tblogin;
import cn.com.mytest.dao.LoginDaoImpl;

public class LoginImpl {
    private static final Log log = LogFactory.getLog(LoginImpl.class);
    LoginDaoImpl dao = new LoginDaoImpl();
    public List list(){
        List list = dao.list();
        if(list!=null){
            for(int i=0;i<list.size();i++){
                Tblogin login = (Tblogin) list.get(i);
                log.info("the login result: number " + i + ", loginname=" + login.getLogincode().trim().toUpperCase());
            }
        }else{
            log.info("there is no rows in the table Tblogin");
        }
       
        return list;
    }
    public Integer count(){
        Integer count = new Integer(0);
        List list = dao.list();
        if(list!=null) count = new Integer(list.size());
        log.info("the count of Tblogin is: " + count.intValue());
        return count;
    }

}
4. wsdd file: deploy.wsdd (cn/com/mytest/server/deploy.wsdd)
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

 <service name="LoginService" provider="java:RPC">
  <parameter name="className" value="cn.com.mytest.server.LoginImpl"/>
  <parameter name="allowedMethods" value="*"/>
 </service>

</deployment>
wsdd file: undeploy.wsdd(cn/com/mytest/server/undeploy.wsdd)
<undeployment xmlns="http://xml.apache.org/axis/wsdd/">
 <service name="LoginService"/>
</undeployment>
5) Testing from client:
package cn.com.mytest.client;

import java.util.List;
import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class TestClient {
    public static void main(String [] args)
    {
        try {
            ///Options options = new Options(args);
           
            String endpointURL = "http://localhost:1234/axis/services/LoginService";
           
            Service  service = new Service();
            Call     call    = (Call) service.createCall();

            call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
            call.setOperationName( new QName("http://server.mytest.com.cn", "count") );

            Integer res = (Integer) call.invoke( new Object[] {} );

            System.out.println( "I got tblogin's count value, which is: " + res.intValue());
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值