1 23 24 package org.objectweb.jorm.mapper.rdb.lib; 25 26 import org.objectweb.jorm.api.PException; 27 import org.objectweb.jorm.api.PExceptionIO; 28 import org.objectweb.jorm.api.PExceptionProtocol; 29 import org.objectweb.perseus.persistence.api.ConnectionHolder; 30 31 import java.sql.Connection ; 32 33 38 public class RdbConnectionWrapper { 39 45 public static Connection narrow2SQL(Object conn) throws PException { 46 if (conn == null) { 47 throw new PExceptionProtocol("Impossible to narrow a null connection"); 48 } 49 if (conn instanceof Connection ) 50 return (Connection ) conn; 51 if (conn instanceof ConnectionHolder) { 52 try { 53 return (Connection ) ((org.objectweb.perseus.persistence.api.ConnectionHolder) conn).getCHConnectionForWrite(); 54 } catch (org.objectweb.perseus.persistence.api.PersistenceException e) { 55 throw new PExceptionIO(e, "Impossible to fetch a connection to access to the RDB."); 56 } 57 } 58 throw new PExceptionProtocol("Unknow type of connection to be narrowed to a SQL connection."); 59 } 60 } 61 | Popular Tags |