Package org.servicemix.components.xsql

Source Code of org.servicemix.components.xsql.XSQLTest

/**
*
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.components.xsql;

import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.xsql.XSQLConnection;
import oracle.xml.xsql.XSQLConnectionManager;
import oracle.xml.xsql.XSQLConnectionManagerFactory;
import oracle.xml.xsql.XSQLPageRequest;
import oracle.xml.xsql.XSQLRequest;
import org.axiondb.jdbc.AxionDataSource;
import org.servicemix.TestSupport;
import org.servicemix.jbi.jaxp.SourceTransformer;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.w3c.dom.Document;

import javax.sql.DataSource;
import javax.xml.namespace.QName;
import javax.xml.transform.dom.DOMSource;
import java.io.StringReader;
import java.net.URL;
import java.sql.SQLException;

/**
* @version $Revision: 603 $
*/
public class XSQLTest extends TestSupport {
    protected DataSource dataSource;
    protected JdbcTemplate template;
    protected SourceTransformer transformer = new SourceTransformer();

    public void testXSQL() throws Exception {
        QName service = new QName("http://servicemix.org/cheese/", "xsql");

        assertSendAndReceiveMessages(service);
    }

    public void XXXXtestTemplate() throws Exception {

        XSQLConnectionManagerFactory factory = new XSQLConnectionManagerFactory() {
            public XSQLConnectionManager create() {
                return new XSQLConnectionManager() {
                    public XSQLConnection getConnection(String s, XSQLPageRequest xsqlPageRequest) throws SQLException {
                        return new XSQLConnection(dataSource.getConnection(), s);
                    }

                    public void releaseConnection(XSQLConnection xsqlConnection, XSQLPageRequest xsqlPageRequest) {
                        try {
                            xsqlConnection.getJDBCConnection().close();
                        }
                        catch (SQLException e) {
                            throw new RuntimeException(e);
                        }
                    }
                };
            }
        };

        DOMParser parser = new DOMParser();
        parser.parse(new StringReader("<xsql:query xmlns:xsql='urn:oracle-xsql' connection='demo' tag-case='lower' row-element='cheese' rowset-element='food'> select * from cheese </xsql:query>"));
        XMLDocument document = parser.getDocument();
        XSQLRequest request = new XSQLRequest(factory, document, new URL("http://foo.com"));
        Document response = request.processToXML();
        System.out.println("XML is:");
        System.out.println(transformer.toString(new DOMSource(response)));
    }

    protected AbstractXmlApplicationContext createBeanFactory() {
        return new ClassPathXmlApplicationContext("org/servicemix/components/xsql/example.xml");
    }

    protected void setUp() throws Exception {
        super.setUp();

        dataSource = (DataSource) getBean("dataSource");
        template = new JdbcTemplate(dataSource);

        // lets create a schema
        template.execute("create table cheese (id NUMBER PRIMARY KEY, name VARCHAR(255), description VARCHAR(255))");
        template.execute("insert into cheese (id, name) values (1, 'Edam')");
        template.execute("insert into cheese (id, name) values (2, 'Cheddar')");
        template.execute("insert into cheese (id, name) values (3, 'Brie')");

        System.out.println("Data is: " + template.queryForList("select * from cheese"));
    }
}
TOP

Related Classes of org.servicemix.components.xsql.XSQLTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.