merge-requests/7/head
hasuniea 9 years ago
commit f176f73067

@ -26,9 +26,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -43,6 +41,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
int applicationId = -1; int applicationId = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
@ -58,7 +58,12 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setString(6, application.getLocationUrl()); stmt.setString(6, application.getLocationUrl());
stmt.setString(7, application.getImageUrl()); stmt.setString(7, application.getImageUrl());
stmt.setInt(8, tenantId); stmt.setInt(8, tenantId);
stmt.setObject(9, application.getAppProperties());
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(application.getAppProperties());
stmt.setBytes(9, bao.toByteArray());
stmt.setString(10, application.getApplicationIdentifier()); stmt.setString(10, application.getApplicationIdentifier());
stmt.execute(); stmt.execute();
@ -70,7 +75,23 @@ public class ApplicationDAOImpl implements ApplicationDAO {
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while adding application '" + throw new DeviceManagementDAOException("Error occurred while adding application '" +
application.getName() + "'", e); application.getName() + "'", e);
} catch (IOException e) {
throw new DeviceManagementDAOException("Error occurred while serializing application properties object", e);
} finally { } finally {
if (bao != null) {
try {
bao.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -81,6 +102,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
List<Integer> applicationIds = new ArrayList<>(); List<Integer> applicationIds = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
@ -99,7 +122,12 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setString(6, application.getLocationUrl()); stmt.setString(6, application.getLocationUrl());
stmt.setString(7, application.getImageUrl()); stmt.setString(7, application.getImageUrl());
stmt.setInt(8, tenantId); stmt.setInt(8, tenantId);
stmt.setObject(9, application.getAppProperties());
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(application.getAppProperties());
stmt.setBytes(9, bao.toByteArray());
stmt.setString(10, application.getApplicationIdentifier()); stmt.setString(10, application.getApplicationIdentifier());
stmt.executeUpdate(); stmt.executeUpdate();
@ -111,7 +139,23 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return applicationIds; return applicationIds;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while adding bulk application list", e); throw new DeviceManagementDAOException("Error occurred while adding bulk application list", e);
} catch (IOException e) {
throw new DeviceManagementDAOException("Error occurred while serializing application properties object", e);
} finally { } finally {
if (bao != null) {
try {
bao.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
DeviceManagementDAOUtil.cleanupResources(stmt, null); DeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
} }

Loading…
Cancel
Save