import org.sonar.core.persistence.DbSession;
import org.sonar.server.db.BaseDao;
+import java.util.Date;
+
/**
* @since 4.3
*/
}
@Override
- public void synchronizeAfter(DbSession session, long timestamp) {
+ public void synchronizeAfter(DbSession session, Date timestamp) {
throw notImplemented();
}
*/
package org.sonar.server.db.migrations.v44;
+import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.activity.Activity;
@Override
public void execute() {
- this.session = db.openSession(false);
- executeUpsert(ActiveRuleChange.Type.ACTIVATED, allActivation);
- executeUpsert(ActiveRuleChange.Type.UPDATED, allUpdates);
- executeUpsert(ActiveRuleChange.Type.DEACTIVATED, allDeactivation);
- session.commit();
- session.close();
+ try {
+ this.session = db.openSession(false);
+ executeUpsert(ActiveRuleChange.Type.ACTIVATED, allActivation);
+ executeUpsert(ActiveRuleChange.Type.UPDATED, allUpdates);
+ executeUpsert(ActiveRuleChange.Type.DEACTIVATED, allDeactivation);
+ session.commit();
+ } finally {
+ session.close();
+ }
}
private void executeUpsert(ActiveRuleChange.Type type, String sql) {
+ Connection connection = null;
try {
- Connection connection = db.database().getDataSource().getConnection();
+ connection = db.database().getDataSource().getConnection();
ResultSet result = connection.createStatement().executeQuery(sql);
//startCase
} catch (Exception e) {
e.printStackTrace();
+ } finally {
+ DbUtils.closeQuietly(connection);
}
}
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
+import java.util.Date;
+
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test(expected = IllegalStateException.class)
public void synchronize_after() {
- dao.synchronizeAfter(session, 1L);
+ dao.synchronizeAfter(session, new Date(0L));
}
}