001    package railo.runtime.db;
002    
003    import java.sql.PreparedStatement;
004    import java.sql.SQLException;
005    
006    
007    public class DataSourceUtil {
008    
009            public static boolean isMSSQL(DatasourceConnection dc) {
010                    try {
011                            if(dc.getConnection().getMetaData().getDatabaseProductName().indexOf("Microsoft")!=-1) return true;
012                    } 
013                    catch (SQLException e) {
014                            String className=dc.getDatasource().getClazz().getName();
015                            if(className.equals("com.microsoft.jdbc.sqlserver.SQLServerDriver") || className.equals("net.sourceforge.jtds.jdbc.Driver"))
016                                    return true;
017                    }
018                    return false;
019                    
020            }
021            public static boolean isMSSQLDriver(DatasourceConnection dc) {
022                    try {
023                            if(dc.getConnection().getMetaData().getDriverName().indexOf("Microsoft SQL Server JDBC Driver")!=-1)
024                                    return true;
025                    } 
026                    catch (SQLException e) {}
027                    
028                    String className=dc.getDatasource().getClazz().getName();
029                    return className.equals("com.microsoft.jdbc.sqlserver.SQLServerDriver");
030            }
031    
032            public static boolean isValid(DatasourceConnection dc, int timeout) throws Throwable {
033                    return dc.getConnection().isValid(timeout); 
034            }
035            
036            
037            public static boolean isClosed(PreparedStatement ps, boolean defaultValue) {
038                    try {
039                            return ps.isClosed();
040                    } 
041                    catch (Throwable t) {
042                            return defaultValue;
043                    }
044            }
045    
046    }