diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/GenericFeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/GenericFeatureDAOImpl.java index aa81dd75f05..bee766f16d4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/GenericFeatureDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/GenericFeatureDAOImpl.java @@ -38,7 +38,8 @@ import java.util.List; * FeatureDAO implementation for DB engines with ANSI SQL support. */ public final class GenericFeatureDAOImpl extends AbstractFeatureDAO { - private static final int BATCH_SIZE = 10; + + private static final Log log = LogFactory.getLog(GenericFeatureDAOImpl.class); @Override public List addProfileFeatures(List features, int profileId) throws @@ -53,36 +54,31 @@ public final class GenericFeatureDAOImpl extends AbstractFeatureDAO { conn = this.getConnection(); String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE, CONTENT, " + "TENANT_ID) VALUES (?, ?, ?, ?, ?)"; - stmt = conn.prepareStatement(query, new String[]{"id"}); - int noRecords = 0; + stmt = conn.prepareStatement(query, new String[] {"id"}); + for (ProfileFeature feature : features) { stmt.setInt(1, profileId); stmt.setString(2, feature.getFeatureCode()); 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.setInt(5, tenantId); stmt.addBatch(); - noRecords++; - 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++; - } - } + //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 } stmt.executeBatch(); + generatedKeys = stmt.getGeneratedKeys(); int i = 0; - if (noRecords > BATCH_SIZE) { - i = noRecords - BATCH_SIZE; - } + while (generatedKeys.next()) { features.get(i).setId(generatedKeys.getInt(1)); i++; } + } catch (SQLException | IOException e) { throw new FeatureManagerDAOException("Error occurred while adding the feature list to the database.", e); } finally { @@ -94,5 +90,4 @@ public final class GenericFeatureDAOImpl extends AbstractFeatureDAO { private Connection getConnection() throws FeatureManagerDAOException { return PolicyManagementDAOFactory.getConnection(); } - } \ No newline at end of file