Adding the datasources changes

4.x.x
Geeth Munasinghe 10 years ago
parent 28fa871eda
commit e4d6070bee

@ -25,6 +25,8 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class PolicyDAOImpl implements PolicyDAO { public class PolicyDAOImpl implements PolicyDAO {
@ -70,4 +72,13 @@ public class PolicyDAOImpl implements PolicyDAO {
public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException { public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException {
return null; return null;
} }
private Connection getConnection() throws PolicyManagerDAOException {
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while obtaining a connection from the policy " +
"management metadata repository datasource", e);
}
}
} }

@ -18,11 +18,21 @@
package org.wso2.carbon.policy.mgt.core.dao.util; package org.wso2.carbon.policy.mgt.core.dao.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable; import java.util.Hashtable;
public class PolicyManagementDAOUtil { public class PolicyManagementDAOUtil {
private static final Log log = LogFactory.getLog(PolicyManagementDAOUtil.class);
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) { public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
try { try {
if (jndiProperties == null || jndiProperties.isEmpty()) { if (jndiProperties == null || jndiProperties.isEmpty()) {
@ -35,4 +45,28 @@ public class PolicyManagementDAOUtil {
} }
} }
public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
log.warn("Error occurred while closing result set", e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.warn("Error occurred while closing prepared statement", e);
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
log.warn("Error occurred while closing database connection", e);
}
}
}
} }

Loading…
Cancel
Save