Search in sources :

Example 16 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.

the class AbstractJPAVendorAdapter method determineDbType.

protected DatabaseType determineDbType() {
    Connection con = null;
    DatabaseType dbType = null;
    try {
        con = getDBConnection();
        DatabaseMetaData metaData = con.getMetaData();
        if (metaData != null) {
            String dbProductName = metaData.getDatabaseProductName().toLowerCase();
            int dbMajorVer = metaData.getDatabaseMajorVersion();
            if (log.isDebugEnabled()) {
                log.debug("Using database " + dbProductName + " major version " + dbMajorVer);
            }
            if (dbProductName.contains("db2")) {
                dbType = DatabaseType.DB2;
            } else if (dbProductName.contains("oracle")) {
                dbType = DatabaseType.ORACLE;
            } else if (dbProductName.contains("derby")) {
                dbType = DatabaseType.DERBY;
            } else if (dbProductName.contains("h2")) {
                dbType = DatabaseType.H2;
            } else if (dbProductName.contains("hsql")) {
                dbType = DatabaseType.HSQL;
            } else if (dbProductName.contains("microsoft sql")) {
                dbType = DatabaseType.SQL_SERVER;
            } else if (dbProductName.contains("mysql")) {
                dbType = DatabaseType.MYSQL;
            } else if (dbProductName.contains("postgresql")) {
                dbType = DatabaseType.POSTGRESQL;
            } else if (dbProductName.contains("sybase")) {
                dbType = DatabaseType.SYBASE;
            }
        }
    } catch (SQLException e) {
        log.warn("Unable to determine database dialect.", e);
    } finally {
        close(con);
    }
    return dbType;
}
Also used : DatabaseType(org.wso2.carbon.bpel.b4p.coordination.dao.DatabaseType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 17 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.

the class AbstractJPAVendorAdapter method determineDbType.

protected DatabaseType determineDbType() {
    Connection con = null;
    DatabaseType dbType = null;
    try {
        con = getDBConnection();
        DatabaseMetaData metaData = con.getMetaData();
        if (metaData != null) {
            String dbProductName = metaData.getDatabaseProductName().toLowerCase();
            int dbMajorVer = metaData.getDatabaseMajorVersion();
            if (log.isDebugEnabled()) {
                log.debug("Using database " + dbProductName + " major version " + dbMajorVer);
            }
            if (dbProductName.contains("db2")) {
                dbType = DatabaseType.DB2;
            } else if (dbProductName.contains("oracle")) {
                dbType = DatabaseType.ORACLE;
            } else if (dbProductName.contains("derby")) {
                dbType = DatabaseType.DERBY;
            } else if (dbProductName.contains("h2")) {
                dbType = DatabaseType.H2;
            } else if (dbProductName.contains("hsql")) {
                dbType = DatabaseType.HSQL;
            } else if (dbProductName.contains("microsoft sql")) {
                dbType = DatabaseType.SQL_SERVER;
            } else if (dbProductName.contains("mysql")) {
                dbType = DatabaseType.MYSQL;
            } else if (dbProductName.contains("postgresql")) {
                dbType = DatabaseType.POSTGRESQL;
            } else if (dbProductName.contains("sybase")) {
                dbType = DatabaseType.SYBASE;
            }
        }
    } catch (SQLException e) {
        log.warn("Unable to determine database dialect.", e);
    } finally {
        close(con);
    }
    return dbType;
}
Also used : DatabaseType(org.wso2.carbon.humantask.core.dao.DatabaseType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 18 with Database

use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.

the class ConnectedCupDAO method getDevice.

public Device getDevice(String deviceId) throws ConnectedCupDeviceMgtPluginException {
    Connection conn = null;
    PreparedStatement stmt = null;
    Device connectedCupDevice = null;
    ResultSet resultSet = null;
    try {
        conn = ConnectedCupDAOUtil.getConnection();
        String selectDBQuery = "SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME FROM CONNECTED_CUP_DEVICE WHERE CONNECTED_CUP_DEVICE_ID = ?";
        stmt = conn.prepareStatement(selectDBQuery);
        stmt.setString(1, deviceId);
        resultSet = stmt.executeQuery();
        if (resultSet.next()) {
            connectedCupDevice = new Device();
            connectedCupDevice.setName(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
            if (log.isDebugEnabled()) {
                log.debug("Connected Cup service " + deviceId + " data has been fetched from" + "Connected Cup database.");
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while fetching Connected Cup device : '" + deviceId + "'";
        log.error(msg, e);
        throw new ConnectedCupDeviceMgtPluginException(msg, e);
    } finally {
        ConnectedCupUtils.cleanupResources(stmt, resultSet);
        ConnectedCupDAOUtil.closeConnection();
    }
    return connectedCupDevice;
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) SQLException(java.sql.SQLException) Device(org.wso2.carbon.device.mgt.common.Device) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 19 with Database

use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.

the class DeviceTypeDAOImpl method addDevice.

public boolean addDevice(Device device) throws DeviceMgtPluginException {
    boolean status = false;
    Connection conn;
    PreparedStatement stmt = null;
    try {
        conn = DeviceTypeDAO.getConnection();
        String createDBQuery = "INSERT INTO sampledevice_DEVICE(sampledevice_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
        stmt = conn.prepareStatement(createDBQuery);
        stmt.setString(1, device.getDeviceIdentifier());
        stmt.setString(2, device.getName());
        int rows = stmt.executeUpdate();
        if (rows > 0) {
            status = true;
            if (log.isDebugEnabled()) {
                log.debug("sampledevice device " + device.getDeviceIdentifier() + " data has been" + " added to the sampledevice database.");
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while adding the sampledevice device '" + device.getDeviceIdentifier() + "' to the sampledevice db.";
        log.error(msg, e);
        throw new DeviceMgtPluginException(msg, e);
    } finally {
        DeviceTypeUtils.cleanupResources(stmt, null);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 20 with Database

use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.

the class DeviceTypeDAOImpl method deleteDevice.

public boolean deleteDevice(String deviceId) throws DeviceMgtPluginException {
    boolean status = false;
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = DeviceTypeDAO.getConnection();
        String deleteDBQuery = "DELETE FROM sampledevice_DEVICE WHERE sampledevice_DEVICE_ID = ?";
        stmt = conn.prepareStatement(deleteDBQuery);
        stmt.setString(1, deviceId);
        int rows = stmt.executeUpdate();
        if (rows > 0) {
            status = true;
            if (log.isDebugEnabled()) {
                log.debug("sampledevice device " + deviceId + " data has deleted" + " from the sampledevice database.");
            }
        }
    } catch (SQLException e) {
        String msg = "Error occurred while deleting sampledevice device " + deviceId;
        log.error(msg, e);
        throw new DeviceMgtPluginException(msg, e);
    } finally {
        DeviceTypeUtils.cleanupResources(stmt, null);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SQLException (java.sql.SQLException)29 PreparedStatement (java.sql.PreparedStatement)28 Connection (java.sql.Connection)24 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)23 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)13 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)12 Map (java.util.Map)6 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)6 HashMap (java.util.HashMap)5 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)5 File (java.io.File)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)4 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)4 Device (org.wso2.carbon.device.mgt.common.Device)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 DataSource (javax.sql.DataSource)3 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)3