`
jncz
  • 浏览: 29408 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

【提问】对于自关联的表 使用dbunit如何保持数据库状态

阅读更多
比如区域,会有下级地市等等,对于dbunit来说他貌似只能对表与表之间的关联关系进行处理,对于同一表中记录与记录之间的关系,他处理不了,会出现外键约束违例。由于对dbunit目前了解的比较肤浅,还请大家能不吝赐教。
分享到:
评论
1 楼 long110 2007-05-17  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  
package com.javaeye.jms.jboss;  
  
import javax.jms.Connection;  
import javax.jms.ConnectionFactory;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageConsumer;  
import javax.jms.MessageProducer;  
import javax.jms.Queue;  
import javax.jms.QueueSender;  
import javax.jms.Session;  
import javax.jms.TextMessage;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
  
public class JbossNativeJmsImpl {  
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp sender will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection

     *        [spec to jms 1.1 apito get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> start the Producer[jms1.1 spec] by a session 
     *     6> get messege Object or initial it yourself by implements the messegeor 

     *        it's sub interfaces 
     *     7> call sender or send it selfing 
     *     8> finallized the connection object or it will throw a warning to you! 
     * 
     * @param messege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public void sendingProcessing(String messege) throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageProducer msgp = session.createProducer(dest);  
        QueueSender sender = (QueueSender) msgp;  
        TextMessage msg = session.createTextMessage();  
        msg.setText(messege);  
        sender.send(msg);  
        conn.close();  
    }  
     
     
     
    /** 
     * @author zuly 
     * 
     * following jms ptp domain, use an simple text message to test 
     * 
     * A jms ptp retriver will following the steps below! 
     *     1> get an ConnectionFactory use JNDI Lookup Or Initial it yourself 
     *     2> use this ConnectionFactory to start a jms connection 
     *        [spec to jms 1.1 api to get the main idea of it ] 
     *     3> use connection to create a jms session 
     *     4> get a queue destination / messege agent 
     *     5> retrive a consumer from session 
     *     6> start the jms connection to retrivte the message 
     *     7> get message from consumer 
     *  
     * @return textMessege 
     * @throws NamingException 
     * @throws JMSException 
     */  
    public String retriveingProcessing() throws NamingException, JMSException{  
        Context ctx = new InitialContext();  
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");  
        Connection conn = cf.createConnection();  
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);  
        Destination dest = (Queue) ctx.lookup("queue/A");  
        MessageConsumer msgconsumer = session.createConsumer(dest);  
        //MessageListener ml = new JmsListenner();  
        //msgconsumer.setMessageListener(ml);  
        conn.start();  
        TextMessage msg = (TextMessage) msgconsumer.receive();  
        conn.close();  
        System.out.println("messege is" + msg.getText());  
        return msg.getText();  
    }  
}  






















相关推荐

    使用dbunit测试数据库

    你可以为 SQL 查询、插入、更新和删除等操作创建相应的测试数据,然后在测试用例中调用这些 SQL,通过 DbUnit 检查操作前后的数据库状态变化,确保 SQL 的正确执行。 总的来说,DbUnit 是一个强大的工具,它简化了...

    使用DbUnit测试数据库.pdf

    总结来说,DbUnit是进行数据库驱动的单元测试的强大工具,它通过管理数据库状态,帮助开发者编写可靠且可重复的测试,尤其是在面对复杂的业务逻辑和数据交互时。通过合理的使用,可以极大地提高代码质量,降低维护...

    Dbunit数据库连接下载

    它可以将数据库状态定义为一种“数据集”,这种数据集可以是XML、CSV或者Excel格式的文件。这使得开发人员能够方便地创建和维护测试用例的数据环境,无论是在单元测试还是集成测试中都非常有用。 在描述中提到的...

    DBUNIT使用

    DbUnit 的主要用途是准备数据库和验证数据库,它可以在执行每个测试方法前用已知内容设置表,并在执行每个测试方法后更方便地验证表的内容。 DbUnit 的使用可以分为两个部分:设置 DbUnit 和使用 DbUnit 进行测试。...

    dbunit使用必需Jar包

    在Java应用程序的测试过程中,确保数据库状态的一致性是非常重要的,DBUnit 提供了这样的功能,它允许开发者导入和导出数据库数据,以进行精确的测试。 在使用 DBUnit 时,有几个必需的 Jar 包是必不可少的,这些 ...

    如何使用DBUnit做数据备份恢复

    DBUnit 是一个开源的 Java 库,专门用于数据库测试,它提供了一种方式来管理和操作数据库的数据,包括数据的导入导出、备份和恢复。在本文中,我们将深入探讨如何利用 DBUnit 进行数据库的备份与恢复。 首先,我们...

    spring+dbunit测试访问数据库代码

    标题中的“spring+dbunit测试访问数据库代码”指的是在Java开发中使用Spring框架与DBUnit进行集成,以实现对数据库的测试。DBUnit是用于数据库单元测试的工具,它可以加载和验证数据库的数据状态,确保测试的隔离性...

    通过DBUNIT做批量对比测试

    7. **异常处理**:如果数据库状态与预期不符,DBUNIT 会抛出异常,提示哪些表或行不匹配,这样就可以定位并修复问题。 在进行批量对比测试时,还可以利用 DBUNIT 的其他特性,例如过滤敏感数据、处理自增主键、忽略...

    dbunit-2.4.9 源码

    在版本 2.4.9 中,DBUnit 提供了一系列的功能,帮助开发者在进行单元测试时能够管理和操作数据库的数据状态。 DBUnit 的核心功能包括: 1. 数据初始化:在测试前,DBUnit 可以导入 CSV、XML 或 Excel 文件中的数据...

    dbunit-2.4.7所有jar以及dbunit入门教程

    在数据库驱动的项目中,DBUnit 可以帮助开发者确保数据库状态的一致性,使得测试更加可靠。DBUnit 2.4.7 版本包含了所有的必需 jar 包,为开发者提供了完整的功能集。 DBUnit 的核心概念包括数据集、操作模式和数据...

    DBUnit 进行单元测试

    5. 执行测试:运行测试代码,检查数据库状态是否符合预期。 6. 清理:如果需要,使用`DatabaseOperation.CLEAN_INSERT`之类的操作清理数据库,以便于下一次测试。 对于开发团队而言,使用DBUnit 可以提高测试覆盖率...

    dbunit使用实例

    在软件开发中,确保数据库状态的一致性和准确性是至关重要的,尤其是在进行集成测试时。DBUnit 提供了一种简单且结构化的机制来导入和导出数据库数据,帮助开发者有效地管理和维护测试数据。 ### DBUnit 的基本概念...

    dbunit测试demo

    6. **执行测试**:在测试方法中,使用 `DatabaseTester` 或 `DBUnitHelper` 类来运行 DBUnit 的操作,如 `assertTableCounts()` 或 `assertDataEquals()`,来验证数据库状态。 7. **异常处理**:在测试过程中,如果...

    dbunit数据库测试工具

    用于数据库测试的一个工具,具有很强的灵活性。也是自己在网上找的,分享一下

    DBUnit最佳实践之数据备份与恢复

    这使得在不同测试用例之间保持数据库状态的一致性成为可能。通过在测试前后执行特定的数据操作,我们可以确保每个测试都是独立的,不受其他测试结果的影响。 数据备份是任何数据库管理策略的核心部分。在DBUnit中,...

    dbunit开发文档

    在数据库驱动的项目中,DBUnit 提供了一种结构化的方法来设置和验证数据库状态,从而确保测试的一致性和可靠性。这篇开发文档将深入探讨 DBUnit 的核心概念、用法以及如何将其集成到你的开发流程中。 一、DBUnit ...

    dbunit2.2

    DBUnit 的主要功能在于帮助开发者在执行测试前后对数据库进行初始化和清理,确保每次测试都在一个已知的、干净的状态下开始。这样可以避免因为数据残留或依赖关系导致的测试不准确。以下是一些关于DBUnit 2.2的知识...

Global site tag (gtag.js) - Google Analytics