/* * Copyright 2005 The Apache Software Foundation. * * 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.apache.jdo.tck.api.persistencemanager; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.jdo.datastore.JDOConnection; import org.apache.jdo.tck.pc.mylib.PCPoint; import org.apache.jdo.tck.util.BatchTestRunner; /** *Title: DataStoreConnection *
*Keywords: *
*Assertion ID: A12.5.2-1 *
*Assertion Description: In order for the application to perform some datastore-specific functions, such as to execute a query that is not directly supported by JDO, applications might need access to the datastore connection used by the JDO implementation. This method returns a wrapped connection that can be cast to the appropriate datastore connection and used by the application. The capability to get the datastore connection is indicated by the optional feature string javax.jdo.option.GetDataStoreConnection. */ public class DataStoreConnection extends PersistenceManagerTest { /** */ private static final String ASSERTION_FAILED = "Assertion A12.5.2-1 (DataStoreConnection) failed: "; /** * The main is called when the class * is directly executed from the command line. * @param args The arguments passed to the program. */ public static void main(String[] args) { BatchTestRunner.run(DataStoreConnection.class); } /** */ protected void localSetUp() { addTearDownClass(PCPoint.class); PCPoint point = new PCPoint(); getPM().currentTransaction().begin(); pm.makePersistent(point); pm.currentTransaction().commit(); } /** */ public void testDataStoreConnection() { if (!(isDataStoreConnectionSupported() && isSQLSupported())) { printUnsupportedOptionalFeatureNotTested( this.getClass().getName(), "getDataStoreConnection AND SQLSupported."); return; } JDOConnection jconn = pm.getDataStoreConnection(); try { pm = getPM(); jconn = pm.getDataStoreConnection(); Connection conn = (Connection)jconn.getNativeConnection(); conn.getAutoCommit(); } catch (Exception ex) { fail(ASSERTION_FAILED + " caught exception:" + ex); } jconn.close(); } }