private void initialize(String name, SqlSession session, SemaphoreMapper mapper) {
try {
- mapper.initialize(name, org.sonar.api.utils.DateUtils.parseDate("2001-01-01"));
+ SemaphoreDto semaphore = new SemaphoreDto()
+ .setName(name)
+ .setLockedAt(org.sonar.api.utils.DateUtils.parseDate("2001-01-01"));
+ mapper.initialize(semaphore);
session.commit();
} catch (Exception e) {
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.persistence;
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.util.Date;
+
+/**
+ * @since 3.4
+ */
+public class SemaphoreDto {
+ private String name;
+ private String checksum;
+ private Date lockedAt;
+
+ public String getName() {
+ return name;
+ }
+
+ public SemaphoreDto setName(String s) {
+ this.name = s;
+ this.checksum = DigestUtils.md5Hex(s);
+ return this;
+ }
+
+ public Date getLockedAt() {
+ return lockedAt;
+ }
+
+ public SemaphoreDto setLockedAt(Date d) {
+ this.lockedAt = d;
+ return this;
+ }
+}
public interface SemaphoreMapper {
- int initialize(@Param("name") String name, @Param("lockedAt") Date lockedAt);
+ int initialize(SemaphoreDto semaphore);
int acquire(@Param("name") String name, @Param("lockedBefore") Date lockedBefore);
<mapper namespace="org.sonar.core.persistence.SemaphoreMapper">
<insert id="initialize" parameterType="map" useGeneratedKeys="false">
- INSERT INTO semaphores (name, created_at, updated_at, locked_at)
- VALUES (#{name}, current_timestamp, current_timestamp, #{lockedAt})
+ INSERT INTO semaphores (name, checksum, created_at, updated_at, locked_at)
+ VALUES (#{name}, #{checksum}, current_timestamp, current_timestamp, #{lockedAt})
</insert>
<select id="now" resultType="Date">
CREATE TABLE "SEMAPHORES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(4000),
+ "CHECKSUM" VARCHAR(200),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"LOCKED_AT" TIMESTAMP
CREATE INDEX "REVIEWS_RID" ON "REVIEWS" ("RESOURCE_ID");
-CREATE UNIQUE INDEX "uniq_semaphore_names" ON "SEMAPHORES" ("NAME");
+CREATE UNIQUE INDEX "uniq_semaphore_names" ON "SEMAPHORES" ("CHECKSUM");
CREATE UNIQUE INDEX "uniq_author_logins" ON "AUTHORS" ("LOGIN");
<dataset>
- <semaphores id="1" name="foo" created_at="2010-01-25" updated_at="2010-01-25" locked_at="2010-01-25"/>
+ <semaphores id="1" name="foo" checksum="acbd18db4cc2f85cedef654fccc4a4d8" created_at="2010-01-25" updated_at="2010-01-25" locked_at="2010-01-25"/>
</dataset>
\ No newline at end of file
def self.up
create_table :semaphores do |t|
t.string :name, :limit => 4000, :null => false
+ t.string :checksum, :limit => 200, :null => false
t.datetime :locked_at
t.timestamps
end