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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations