Reverting the changes done to GenericFeatureDAOImpl.

revert-70aa11f8
sinthuja 8 years ago
parent ce5ca09e51
commit f2ea96efde

@ -38,7 +38,8 @@ import java.util.List;
* FeatureDAO implementation for DB engines with ANSI SQL support. * FeatureDAO implementation for DB engines with ANSI SQL support.
*/ */
public final class GenericFeatureDAOImpl extends AbstractFeatureDAO { public final class GenericFeatureDAOImpl extends AbstractFeatureDAO {
private static final int BATCH_SIZE = 10;
private static final Log log = LogFactory.getLog(GenericFeatureDAOImpl.class);
@Override @Override
public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
@ -54,35 +55,30 @@ public final class GenericFeatureDAOImpl extends AbstractFeatureDAO {
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE, CONTENT, " + String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE, CONTENT, " +
"TENANT_ID) VALUES (?, ?, ?, ?, ?)"; "TENANT_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, new String[] {"id"}); stmt = conn.prepareStatement(query, new String[] {"id"});
int noRecords = 0;
for (ProfileFeature feature : features) { for (ProfileFeature feature : features) {
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.setString(2, feature.getFeatureCode()); stmt.setString(2, feature.getFeatureCode());
stmt.setString(3, feature.getDeviceType()); stmt.setString(3, feature.getDeviceType());
// if (conn.getMetaData().getDriverName().contains("H2")) {
// stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent()));
// } else {
stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent())); stmt.setBytes(4, PolicyManagerUtil.getBytes(feature.getContent()));
//}
stmt.setInt(5, tenantId); stmt.setInt(5, tenantId);
stmt.addBatch(); stmt.addBatch();
noRecords++; //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
if (noRecords >= BATCH_SIZE && noRecords % BATCH_SIZE == 0) {
stmt.executeBatch();
generatedKeys = stmt.getGeneratedKeys();
int i = noRecords - BATCH_SIZE;
while (generatedKeys.next()) {
features.get(i).setId(generatedKeys.getInt(1));
i++;
}
}
} }
stmt.executeBatch(); stmt.executeBatch();
generatedKeys = stmt.getGeneratedKeys(); generatedKeys = stmt.getGeneratedKeys();
int i = 0; int i = 0;
if (noRecords > BATCH_SIZE) {
i = noRecords - BATCH_SIZE;
}
while (generatedKeys.next()) { while (generatedKeys.next()) {
features.get(i).setId(generatedKeys.getInt(1)); features.get(i).setId(generatedKeys.getInt(1));
i++; i++;
} }
} catch (SQLException | IOException e) { } catch (SQLException | IOException e) {
throw new FeatureManagerDAOException("Error occurred while adding the feature list to the database.", e); throw new FeatureManagerDAOException("Error occurred while adding the feature list to the database.", e);
} finally { } finally {
@ -94,5 +90,4 @@ public final class GenericFeatureDAOImpl extends AbstractFeatureDAO {
private Connection getConnection() throws FeatureManagerDAOException { private Connection getConnection() throws FeatureManagerDAOException {
return PolicyManagementDAOFactory.getConnection(); return PolicyManagementDAOFactory.getConnection();
} }
} }
Loading…
Cancel
Save