mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Reverting the changes done to GenericFeatureDAOImpl.
This commit is contained in:
parent
ce5ca09e51
commit
f2ea96efde
@ -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<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, " +
|
||||
"TENANT_ID) VALUES (?, ?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, new String[] {"id"});
|
||||
int noRecords = 0;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user