diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
index a38c8ca3db..32b140921e 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml
@@ -75,16 +75,19 @@
org.jscep.transaction,
org.w3c.dom,
org.xml.sax,
+ javax.sql,
+ javax.cache,
+ javax.naming,
+ javax.xml.bind.annotation,
javax.xml.bind,
+ org.wso2.carbon.utils.*,
+ org.wso2.carbon.device.mgt.common.*,
+ org.wso2.carbon.device.mgt.core.*,
org.bouncycastle.pkcs.jcajce
!org.wso2.carbon.certificate.mgt.core.internal.*,
- org.wso2.carbon.certificate.mgt.core.dto.*,
- org.wso2.carbon.certificate.mgt.core.exception.*,
- org.wso2.carbon.certificate.mgt.core.impl.*,
- org.wso2.carbon.certificate.mgt.core.service.*,
- org.wso2.carbon.certificate.mgt.core.util.*
+ org.wso2.carbon.certificate.mgt.core.*
@@ -113,8 +116,8 @@
org.eclipse.osgi
- org.eclipse.osgi
- org.eclipse.osgi.services
+ org.eclipse.equinox
+ org.eclipse.equinox.commonorg.testng
@@ -148,6 +151,20 @@
commons-io.wso2commons-io
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateConfigurationManager.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateConfigurationManager.java
new file mode 100644
index 0000000000..4329a1523f
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateConfigurationManager.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.config;
+
+import org.w3c.dom.Document;
+import org.wso2.carbon.certificate.mgt.core.config.datasource.DataSourceConfig;
+import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
+import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants;
+import org.wso2.carbon.certificate.mgt.core.util.CertificateManagerUtil;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+
+/**
+ * Class responsible for the certificate manager configuration initialization
+ */
+public class CertificateConfigurationManager {
+
+ private CertificateManagementConfig currentPolicyConfig;
+ private static CertificateConfigurationManager certificateConfigurationManager;
+
+ private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ CertificateManagementConstants.DEVICE_CONFIG_XML_NAME;
+
+ public static CertificateConfigurationManager getInstance() {
+ if (certificateConfigurationManager == null) {
+ synchronized (CertificateConfigurationManager.class) {
+ if (certificateConfigurationManager == null) {
+ certificateConfigurationManager = new CertificateConfigurationManager();
+ }
+ }
+ }
+ return certificateConfigurationManager;
+ }
+
+ public synchronized void initConfig() throws CertificateManagementException {
+ try {
+ File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
+ Document doc = CertificateManagerUtil.convertToDocument(deviceMgtConfig);
+
+ /* Un-marshaling Device Management configuration */
+ JAXBContext rssContext = JAXBContext.newInstance(CertificateManagementConfig.class);
+ Unmarshaller unmarshaller = rssContext.createUnmarshaller();
+ this.currentPolicyConfig = (CertificateManagementConfig) unmarshaller.unmarshal(doc);
+ } catch (Exception e) {
+ throw new CertificateManagementException("Error occurred while initializing device config", e);
+ }
+ }
+
+ public CertificateManagementConfig getPolicyManagementConfig() {
+ return currentPolicyConfig;
+ }
+
+ public DataSourceConfig getDataSourceConfig() {
+ return currentPolicyConfig.getCertificateManagementRepository().getDataSourceConfig();
+ }
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementConfig.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementConfig.java
new file mode 100644
index 0000000000..79f67b148a
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementConfig.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.wso2.carbon.certificate.mgt.core.config;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents Device Mgt configuration.
+ */
+@XmlRootElement(name = "DeviceMgtConfiguration")
+public final class CertificateManagementConfig {
+
+ public void setCertificateManagementRepository(CertificateManagementRepository certificateManagementRepository) {
+ this.certificateManagementRepository = certificateManagementRepository;
+ }
+
+ private CertificateManagementRepository certificateManagementRepository;
+
+ @XmlElement(name = "ManagementRepository", nillable = false)
+ public CertificateManagementRepository getCertificateManagementRepository() {
+ return certificateManagementRepository;
+ }
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementRepository.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementRepository.java
new file mode 100644
index 0000000000..47ce800468
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/CertificateManagementRepository.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.wso2.carbon.certificate.mgt.core.config;
+
+import org.wso2.carbon.certificate.mgt.core.config.datasource.DataSourceConfig;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding management repository data
+ */
+@XmlRootElement(name = "ManagementRepository")
+public class CertificateManagementRepository {
+
+ private DataSourceConfig dataSourceConfig;
+
+ @XmlElement(name = "DataSourceConfiguration", nillable = false)
+ public DataSourceConfig getDataSourceConfig() {
+ return dataSourceConfig;
+ }
+
+ public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
+ this.dataSourceConfig = dataSourceConfig;
+ }
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/DataSourceConfig.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/DataSourceConfig.java
new file mode 100644
index 0000000000..e9c72bb649
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/DataSourceConfig.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * you may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding data source configuration in cdm-config.xml at parsing with JAXB
+ */
+@XmlRootElement(name = "DataSourceConfiguration")
+public class DataSourceConfig {
+
+ private JNDILookupDefinition jndiLookupDefinition;
+
+ @XmlElement(name = "JndiLookupDefinition", nillable = true)
+ public JNDILookupDefinition getJndiLookupDefinition() {
+ return jndiLookupDefinition;
+ }
+
+ public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
+ this.jndiLookupDefinition = jndiLookupDefinition;
+ }
+}
+// CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
+// ID INTEGER auto_increment NOT NULL,
+// SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
+// CERTIFICATE BLOB DEFAULT NULL,
+// PRIMARY KEY (ID)
+// );
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/JNDILookupDefinition.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/JNDILookupDefinition.java
new file mode 100644
index 0000000000..0e9fffde87
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/config/datasource/JNDILookupDefinition.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * you may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.config.datasource;
+
+import javax.xml.bind.annotation.*;
+import java.util.List;
+
+/**
+ * Class for hold JndiLookupDefinition of cdm-config.xml at parsing with JAXB
+ */
+@XmlRootElement(name = "JndiLookupDefinition")
+public class JNDILookupDefinition {
+
+ private String jndiName;
+ private List jndiProperties;
+
+ @XmlElement(name = "Name", nillable = false)
+ public String getJndiName() {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+ @XmlElementWrapper(name = "Environment", nillable = false)
+ @XmlElement(name = "Property", nillable = false)
+ public List getJndiProperties() {
+ return jndiProperties;
+ }
+
+ public void setJndiProperties(List jndiProperties) {
+ this.jndiProperties = jndiProperties;
+ }
+
+ @XmlRootElement(name = "Property")
+ public static class JNDIProperty {
+
+ private String name;
+
+ private String value;
+
+ @XmlAttribute(name = "Name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlValue
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+}
+
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java
new file mode 100644
index 0000000000..bffe744fb9
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateDAO.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.dao;
+
+import java.io.ByteArrayInputStream;
+
+/**
+ * This class represents the key operations associated with persisting certificate related
+ * information.
+ */
+public interface CertificateDAO {
+
+ /**
+ * This can be used to store a certificate in the database, where it will be stored against the serial number
+ * of the certificate.
+ * @param byteArrayInputStream Holds the certificate.
+ * @param serialNumber Serial number of the certificate.
+ * @throws CertificateManagementDAOException
+ */
+ void addCertificate(ByteArrayInputStream byteArrayInputStream, String serialNumber
+ ) throws CertificateManagementDAOException;
+
+ /**
+ * Usage is to obtain a certificate stored in the database by providing the serial number.
+ * @param serialNumber Serial number of the certificate.
+ * @return representation of the certificate.
+ * @throws CertificateManagementDAOException
+ */
+ byte[] retrieveCertificate(String serialNumber
+ ) throws CertificateManagementDAOException;
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOException.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOException.java
new file mode 100644
index 0000000000..e37eef0fef
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOException.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.dao;
+
+/**
+ * Custom exception class for data access related exceptions.
+ */
+public class CertificateManagementDAOException extends Exception {
+
+ private String message;
+ private static final long serialVersionUID = 2021891706072918864L;
+
+ /**
+ * Constructs a new exception with the specified detail message and nested exception.
+ *
+ * @param message error message
+ * @param nestedException exception
+ */
+ public CertificateManagementDAOException(String message, Exception nestedException) {
+ super(message, nestedException);
+ setErrorMessage(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message the detail message.
+ * @param cause the cause of this exception.
+ */
+ public CertificateManagementDAOException(String message, Throwable cause) {
+ super(message, cause);
+ setErrorMessage(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message
+ *
+ * @param message the detail message.
+ */
+ public CertificateManagementDAOException(String message) {
+ super(message);
+ setErrorMessage(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified and cause.
+ *
+ * @param cause the cause of this exception.
+ */
+ public CertificateManagementDAOException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.message = errorMessage;
+ }
+
+}
diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOFactory.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOFactory.java
new file mode 100644
index 0000000000..cfe65cdb7b
--- /dev/null
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/CertificateManagementDAOFactory.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.certificate.mgt.core.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.certificate.mgt.core.config.datasource.DataSourceConfig;
+import org.wso2.carbon.certificate.mgt.core.config.datasource.JNDILookupDefinition;
+import org.wso2.carbon.certificate.mgt.core.dao.impl.GenericCertificateDAOImpl;
+import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
+import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
+import org.wso2.carbon.device.mgt.common.TransactionManagementException;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.List;
+
+public class CertificateManagementDAOFactory {
+
+ private static DataSource dataSource;
+ private static String databaseEngine;
+ private static final Log log = LogFactory.getLog(CertificateManagementDAOFactory.class);
+ private static ThreadLocal currentConnection = new ThreadLocal();
+
+
+ public static CertificateDAO getCertificateDAO() {
+ return new GenericCertificateDAOImpl();
+ }
+
+ public static void init(DataSourceConfig config) {
+ dataSource = resolveDataSource(config);
+ try {
+ databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException e) {
+ log.error("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void init(DataSource dtSource) {
+ dataSource = dtSource;
+ try {
+ databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException e) {
+ log.error("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void beginTransaction() throws TransactionManagementException {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ try {
+ conn = dataSource.getConnection();
+ conn.setAutoCommit(false);
+ currentConnection.set(conn);
+ } catch (SQLException e) {
+ throw new TransactionManagementException("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void openConnection() throws SQLException {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ conn = dataSource.getConnection();
+ currentConnection.set(conn);
+ }
+
+ public static Connection getConnection() throws SQLException {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ return conn;
+ }
+
+ public static void commitTransaction() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.commit();
+ } catch (SQLException e) {
+ log.error("Error occurred while committing the transaction", e);
+ }
+ }
+
+ public static void rollbackTransaction() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.rollback();
+ } catch (SQLException e) {
+ log.warn("Error occurred while roll-backing the transaction", e);
+ }
+ }
+
+ public static void closeConnection() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ log.warn("Error occurred while close the connection");
+ }
+ currentConnection.remove();
+ }
+
+
+ /**
+ * Resolve data source from the data source definition.
+ *
+ * @param config data source configuration
+ * @return data source resolved from the data source definition
+ */
+ private static DataSource resolveDataSource(DataSourceConfig config) {
+ DataSource dataSource = null;
+ if (config == null) {
+ throw new RuntimeException(
+ "Device Management Repository data source configuration " + "is null and " +
+ "thus, is not initialized"
+ );
+ }
+ JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
+ if (jndiConfig != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing Device Management Repository data source using the JNDI " +
+ "Lookup Definition");
+ }
+ List jndiPropertyList =
+ jndiConfig.getJndiProperties();
+ if (jndiPropertyList != null) {
+ Hashtable