]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5918 Convert USERS.UPDATED_AT and USERS.CREATED_AT in long
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 10 Dec 2014 12:44:18 +0000 (13:44 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 10 Dec 2014 13:40:23 +0000 (14:40 +0100)
27 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedUsersLongDates.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileProjectOperationsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/before.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/schema.sql [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/user/db/GroupDaoTest/find_by_user_login.xml
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/752_add_users_long_dates.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/753_feed_users_long_dates.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/754_rename_users_long_dates.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/lib/need_authentication.rb
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/user/UserDto.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/test/java/org/sonar/core/user/UserDaoTest.java
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/deactivate_user-result.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/deactivate_user.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/insert-result.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/selectActiveUserByLogin.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/selectGroupByName.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/selectUsersByLogins.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/selectUsersByQuery.xml
sonar-core/src/test/resources/org/sonar/core/user/UserDaoTest/selectUsersByText.xml

index 10044861b2bd308eb8eb965defa7a3faf43d1dd7..9bf8e7ce1897422bf8d36896ed3729160ffe4f57 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigrati
 import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities;
 import org.sonar.server.db.migrations.v50.*;
 import org.sonar.server.db.migrations.v51.FeedIssueTags;
+import org.sonar.server.db.migrations.v51.FeedUsersLongDates;
 
 import java.util.List;
 
@@ -76,7 +77,8 @@ public interface DatabaseMigrations {
     FeedIssueLongDates.class,
 
     // 5.1
-    FeedIssueTags.class
+    FeedIssueTags.class,
+    FeedUsersLongDates.class
   );
 
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedUsersLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedUsersLongDates.java
new file mode 100644 (file)
index 0000000..5311c42
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.db.migrations.v51;
+
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.Select;
+import org.sonar.server.db.migrations.SqlStatement;
+
+import java.sql.SQLException;
+import java.util.Date;
+
+public class FeedUsersLongDates extends BaseDataChange {
+
+  private final System2 system;
+
+  public FeedUsersLongDates(Database db, System2 system) {
+    super(db);
+    this.system = system;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    final long now = system.now();
+
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("SELECT u.id, u.created_at, u.updated_at FROM users u WHERE created_at_ms IS NULL");
+    massUpdate.update("UPDATE users SET created_at_ms=?, updated_at_ms=? WHERE id=?");
+    massUpdate.rowPluralName("users");
+    massUpdate.execute(new MassUpdate.Handler() {
+      @Override
+      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+        Long id = row.getLong(1);
+        Date createdAt = row.getDate(2);
+        Date updatedAt = row.getDate(3);
+
+        if (createdAt == null) {
+          update.setLong(1, now);
+        } else {
+          update.setLong(1, Math.min(now, createdAt.getTime()));
+        }
+        if (updatedAt == null) {
+          update.setLong(2, now);
+        } else {
+          update.setLong(2, Math.min(now, updatedAt.getTime()));
+        }
+        update.setLong(3, id);
+        return true;
+      }
+    });
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest.java
new file mode 100644 (file)
index 0000000..77fc84f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FeedUsersLongDatesTest {
+
+  @ClassRule
+  public static TestDatabase db = new TestDatabase().schema(FeedUsersLongDatesTest.class, "schema.sql");
+
+  @Test
+  public void execute() throws Exception {
+    db.prepareDbUnit(getClass(), "before.xml");
+
+    System2 system = mock(System2.class);
+    when(system.now()).thenReturn(1500000000000L);
+    DatabaseMigration migration = new FeedUsersLongDates(db.database(), system);
+    migration.execute();
+
+    int count = db.count("select count(*) from users where created_at_ms is not null and updated_at_ms is not null");
+    assertThat(count).isEqualTo(3);
+  }
+
+}
index 567245d08af2c6716fb8169e015ee247256d4b0b..1e3104f30691229fe53b2c82a24e8e8b21f08d54 100644 (file)
@@ -36,8 +36,6 @@ import org.sonar.server.tester.ServerTester;
 import org.sonar.server.user.MockUserSession;
 import org.sonar.server.user.UserSession;
 
-import java.util.Date;
-
 import static org.fest.assertions.Assertions.assertThat;
 
 public class QProfileProjectOperationsMediumTest {
@@ -136,7 +134,7 @@ public class QProfileProjectOperationsMediumTest {
     db.componentDao().insert(dbSession, project2);
 
     // Create a user having user permission on the two projects and the global quality profile admin permission
-    UserDto user = new UserDto().setLogin("john").setName("John").setEmail("jo@hn.com").setCreatedAt(new Date()).setUpdatedAt(new Date());
+    UserDto user = new UserDto().setLogin("john").setName("John").setEmail("jo@hn.com").setCreatedAt(System.currentTimeMillis()).setUpdatedAt(System.currentTimeMillis());
     db.userDao().insert(dbSession, user);
     tester.get(PermissionFacade.class).insertUserPermission(project1.getId(), user.getId(), UserRole.USER, dbSession);
     tester.get(PermissionFacade.class).insertUserPermission(project2.getId(), user.getId(), UserRole.USER, dbSession);
index 73387e8481af57db15c44ab918f761e789c347ba..ba027b787d28954f00226b55326d5cf7e670eb14 100644 (file)
@@ -55,7 +55,6 @@ import org.sonar.server.user.MockUserSession;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -181,7 +180,7 @@ public class QProfileServiceMediumTest {
   public void search_qprofile_activity() throws InterruptedException {
     MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN).setLogin("david");
 
-    UserDto user = new UserDto().setLogin("david").setName("David").setEmail("dav@id.com").setCreatedAt(new Date()).setUpdatedAt(new Date());
+    UserDto user = new UserDto().setLogin("david").setName("David").setEmail("dav@id.com").setCreatedAt(System.currentTimeMillis()).setUpdatedAt(System.currentTimeMillis());
     db.userDao().insert(dbSession, user);
 
     // We need an actual rule in DB to test RuleName in Activity
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/before.xml
new file mode 100644 (file)
index 0000000..27a6435
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+
+  <users id="1" login="user1" name="User1" active="[true]"
+          created_at="2014-05-12"
+          updated_at="2014-05-13"
+          CREATED_AT_MS="[null]"
+          UPDATED_AT_MS="[null]"
+    />
+
+  <!-- re-entrant migration - ignore the issues that are already fed with new dates -->
+  <users id="2" login="user2" name="User2" active="[true]"
+          created_at="2014-05-12"
+          updated_at="2014-05-13"
+          CREATED_AT_MS="1500000000000"
+          UPDATED_AT_MS="1500000000000"
+    />
+
+  <!-- NULL dates -->
+  <users id="3" login="user3" name="User3" active="[true]"
+          created_at="[null]"
+          updated_at="[null]"
+          CREATED_AT_MS="[null]"
+          UPDATED_AT_MS="[null]"
+    />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedUsersLongDatesTest/schema.sql
new file mode 100644 (file)
index 0000000..ba24adf
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "USERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOGIN" VARCHAR(255),
+  "NAME" VARCHAR(200),
+  "EMAIL" VARCHAR(100),
+  "CRYPTED_PASSWORD" VARCHAR(40),
+  "SALT" VARCHAR(40),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "CREATED_AT_MS" BIGINT,
+  "UPDATED_AT_MS" BIGINT,
+  "REMEMBER_TOKEN" VARCHAR(500),
+  "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP,
+  "ACTIVE" BOOLEAN DEFAULT TRUE
+);
index ea360dd7af1315cbfb68e29e3daf830e6c57a8a4..da498e192bd0b47b18f75d1b980e6a338045a0d4 100644 (file)
@@ -1,23 +1,3 @@
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2014 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube 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.
-  ~
-  ~ SonarQube 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 this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
-
 <dataset>
 
   <groups id="1" name="sonar-users" description="Sonar Users" created_at="2014-09-07" updated_at="2014-09-08"/>
@@ -27,6 +7,6 @@
   <groups_users user_id="100" group_id="1"/>
   <groups_users user_id="100" group_id="2"/>
 
-  <users id="100" login="john" name="John" email="jo@hn.com" created_at="2014-06-20" updated_at="2014-06-20" active="[true]"/>
+  <users id="100" login="john" name="John" email="jo@hn.com" created_at="1418215735482" updated_at="1418215735482" active="[true]"/>
 
 </dataset>
index ba549b36f7b07bc21143db6bbbcc25882f604567..4f3495d7a3e5bc997a24d5a57ab14ab7cc6030d8 100644 (file)
@@ -30,6 +30,7 @@ class UsersController < ApplicationController
     @errors = []
     user = User.find_by_login(params[:user][:login])
     if user && !user.active
+      user.updated_at = Java::JavaLang::System.java_class.currentTimeMillis()
       if user.update_attributes(params[:user])
         # case user: exist,inactive,no errors when update BUT TO REACTIVATE
         @user = user
index 39325bd9b1318e3ae5ff11e31f07d7f2af820e66..001521734bddab3e91df5a78fbfca2bb2b260e3d 100644 (file)
@@ -63,6 +63,22 @@ class User < ActiveRecord::Base
   # anything else you want your user to change should be added here.
   attr_accessible :login, :email, :name, :password, :password_confirmation
 
+  ####
+  # As now dates are saved in long they should be no more automatically managed by Rails
+  ###
+
+  def record_timestamps
+    false
+  end
+
+  def before_create
+    self.created_at = java.lang.System.currentTimeMillis
+    self.updated_at = java.lang.System.currentTimeMillis
+  end
+
+  def before_save
+    self.updated_at = java.lang.System.currentTimeMillis
+  end
 
   def email=(value)
     write_attribute :email, (value && value.downcase)
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/752_add_users_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/752_add_users_long_dates.rb
new file mode 100644 (file)
index 0000000..5c7dce4
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+# SONAR-5918
+#
+class AddUsersLongDates < ActiveRecord::Migration
+
+  def self.up
+    add_column 'users', :created_at_ms, :big_integer, :null => true
+    add_column 'users', :updated_at_ms, :big_integer, :null => true
+  end
+end
+
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/753_feed_users_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/753_feed_users_long_dates.rb
new file mode 100644 (file)
index 0000000..1a83d49
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+# SONAR-5918
+#
+class FeedUsersLongDates < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v51.FeedUsersLongDates')
+  end
+
+end
+
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/754_rename_users_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/754_rename_users_long_dates.rb
new file mode 100644 (file)
index 0000000..57ebabf
--- /dev/null
@@ -0,0 +1,36 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+# SONAR-5918
+#
+class RenameUsersLongDates < ActiveRecord::Migration
+
+  def self.up
+    remove_column 'users', 'created_at'
+    remove_column 'users', 'updated_at'
+    rename_column 'users', 'created_at_ms', 'created_at'
+    rename_column 'users', 'updated_at_ms', 'updated_at'
+    add_index 'users', 'updated_at', :name => 'users_updated_at'
+  end
+
+end
+
index 3e49975583adf7bfb802b9e28139c4b5a7d15c6e..22da5fdba07552aa79d3b9fd2772284cd264902e 100644 (file)
@@ -66,6 +66,7 @@ class PluginRealm
       user = User.find_active_by_login(username)
       # SONAR-4950 Use a transaction to prevent multiple insertion of same groups
       User.transaction do
+        user.updated_at = Java::JavaLang::System.java_class.currentTimeMillis()
         user.save(false)
       end
       result = user if user && user.authenticated?(password)
@@ -122,13 +123,16 @@ class PluginRealm
     username=details.getName() if username.blank? && details
     user = User.find_by_login(username)
 
+    now = java.lang.System.currentTimeMillis
+
     # SONAR-4950 Use a transaction to prevent multiple insertion of same groups
     User.transaction do
       if !user
         # No such user in Sonar database
         return nil if !Api::Utils.java_facade.getSettings().getBoolean('sonar.authenticator.createUsers')
         # Automatically create a user in the sonar db if authentication has been successfully done
-        user = User.new(:login => username, :name => username, :email => '')
+        user = User.new(:login => username, :name => username, :email => '', :created_at => now, :updated_at => now)
+
         if details
           user.name = details.getName()
           user.email = details.getEmail()
@@ -147,8 +151,8 @@ class PluginRealm
           user.email = details.getEmail()
         end
 
-        # Force the update of updated_ad in order to execute an SQL update to block other session
-        user.updated_at = Time.now
+        # Force the update of updated_at in order to execute an SQL update to block other session
+        user.updated_at = now
       end
       if @save_password
         user.password = password
index 4a103c025900561b627fbce3eb75578efe827bbc..e4de173996f1251921af437b713bb9ee10dc511a 100644 (file)
@@ -33,10 +33,10 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 751;
+  public static final int LAST_VERSION = 754;
 
   /**
-   * List of all the tables.
+   * List of all the tables.n
    * This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way
    * for all the supported databases, particularly due to Oracle results.
    */
index 585299a67133974411bc29355e9002505ac5b7e1..4fc269fc0fa41cac464a1dba5e66deefd3e43fe6 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.core.user;
 
 import javax.annotation.Nullable;
-import java.util.Date;
 
 /**
  * @since 3.2
@@ -30,8 +29,8 @@ public class UserDto {
   private String login;
   private String name;
   private String email;
-  private Date createdAt;
-  private Date updatedAt;
+  private Long createdAt;
+  private Long updatedAt;
   private boolean active = true;
 
   public Long getId() {
@@ -70,20 +69,20 @@ public class UserDto {
     return this;
   }
 
-  public Date getCreatedAt() {
+  public Long getCreatedAt() {
     return createdAt;
   }
 
-  public UserDto setCreatedAt(Date createdAt) {
+  public UserDto setCreatedAt(Long createdAt) {
     this.createdAt = createdAt;
     return this;
   }
 
-  public Date getUpdatedAt() {
+  public Long getUpdatedAt() {
     return updatedAt;
   }
 
-  public UserDto setUpdatedAt(Date updatedAt) {
+  public UserDto setUpdatedAt(Long updatedAt) {
     this.updatedAt = updatedAt;
     return this;
   }
index 6e9e8f5c12a1066225de5befbbded828eb7395bf..44722fe3358721a41e95e31429449f748616a4d6 100644 (file)
@@ -280,6 +280,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('719');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('720');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('750');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('751');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('752');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('753');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('754');
 
-INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
+INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 7e26868aaab2a347f28060800a0de84020f6ba95..9b434e00a202e28020d24441f00fa9cd301cbd18 100644 (file)
@@ -323,8 +323,8 @@ CREATE TABLE "USERS" (
   "EMAIL" VARCHAR(100),
   "CRYPTED_PASSWORD" VARCHAR(40),
   "SALT" VARCHAR(40),
-  "CREATED_AT" TIMESTAMP,
-  "UPDATED_AT" TIMESTAMP,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT,
   "REMEMBER_TOKEN" VARCHAR(500),
   "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP,
   "ACTIVE" BOOLEAN DEFAULT TRUE
@@ -694,6 +694,8 @@ CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER_LOGIN"
 
 CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
 
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT");
+
 CREATE INDEX "SNAPSHOTS_ROOT_PROJECT_ID" ON "SNAPSHOTS" ("ROOT_PROJECT_ID");
 
 CREATE INDEX "GROUP_ROLES_ROLE" ON "GROUP_ROLES" ("ROLE");
index 981695b23c93c26d05694a6842c0f84112a9d5bb..0781d960195858118f171e42cfbc9f57e7232dcc 100644 (file)
@@ -27,7 +27,10 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.DbSession;
 
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -166,12 +169,22 @@ public class UserDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void insert_user() {
-    Date date = DateUtils.parseDate("2014-06-20");
+    Long date = DateUtils.parseDate("2014-06-20").getTime();
 
     UserDto userDto = new UserDto().setId(1L).setLogin("john").setName("John").setEmail("jo@hn.com").setCreatedAt(date).setUpdatedAt(date);
     dao.insert(session, userDto);
-
-    checkTables("insert");
+    session.commit();
+
+    UserDto user = dao.selectActiveUserByLogin("john");
+    assertThat(user).isNotNull();
+    assertThat(user.getId()).isNotNull();
+    assertThat(user.getLogin()).isEqualTo("john");
+    assertThat(user.getName()).isEqualTo("John");
+    assertThat(user.getEmail()).isEqualTo("jo@hn.com");
+    assertThat(user.getCreatedAt()).isEqualTo(date);
+    assertThat(user.getUpdatedAt()).isEqualTo(date);
+
+    // checkTables("insert", new String[] {"id"}, "users");
   }
 
   @Test
index ff45e5df1abaf9706c5e95ace0fe576c91e60869..0de00c6c0047ac7fe955c7719553fa7ee6ff01d2 100644 (file)
@@ -1,25 +1,6 @@
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2014 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube 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.
-  ~
-  ~ SonarQube 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 this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
 <dataset>
   <!-- deactivated -->
-  <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[false]"/>
+  <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[false]"/>
 
   <!-- deleted
   <dashboards id="1" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
@@ -33,7 +14,7 @@
   <user_roles id="1" user_id="100" role="admin" RESOURCE_ID="[null]"/>
   -->
 
-  <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
   <dashboards id="2" user_id="101" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
   <active_dashboards id="2" user_id="101" dashboard_id="2" ORDER_INDEX="[null]"/>
   <active_dashboards id="4" user_id="101" dashboard_id="3" ORDER_INDEX="[null]"/>
   <measure_filters id="2" user_id="101" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
   <measure_filter_favourites id="2" user_id="101" measure_filter_id="2" CREATED_AT="[null]"/>
   <measure_filter_favourites id="4" user_id="101" measure_filter_id="3" CREATED_AT="[null]"/>
-  <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]" />
+  <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
   <groups_users user_id="101" group_id="200"/>
   <user_roles id="2" user_id="101" role="admin" RESOURCE_ID="[null]"/>
 
   <!-- Not deleted because shared -->
   <dashboards id="3" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[true]" UPDATED_AT="[null]"/>
-  <issue_filters id="3" user_login="marius" name="My shared issues"  CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
+  <issue_filters id="3" user_login="marius" name="My shared issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
   <measure_filters id="3" user_id="100" name="My shared measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
 
 
index 2cd2c16822dd23b4e47548fb1d246e48616fd8ea..285b4f3c7edd24dbf3fb9ca75db3851c9afa7f57 100644 (file)
@@ -1,41 +1,22 @@
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2014 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube 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.
-  ~
-  ~ SonarQube 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 this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
 <dataset>
-  <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="100" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
   <dashboards id="1" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
   <dashboards id="3" user_id="100" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[true]" UPDATED_AT="[null]"/>
   <active_dashboards id="1" user_id="100" dashboard_id="1" ORDER_INDEX="[null]"/>
   <active_dashboards id="3" user_id="100" dashboard_id="3" ORDER_INDEX="[null]"/>
-  <issue_filters id="1" user_login="marius" name="My issues"  CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
-  <issue_filters id="3" user_login="marius" name="My shared issues"  CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
+  <issue_filters id="1" user_login="marius" name="My issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
+  <issue_filters id="3" user_login="marius" name="My shared issues" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
   <issue_filter_favourites id="1" user_login="marius" issue_filter_id="1" CREATED_AT="[null]"/>
   <issue_filter_favourites id="3" user_login="marius" issue_filter_id="3" CREATED_AT="[null]"/>
   <measure_filters id="1" user_id="100" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
   <measure_filters id="3" user_id="100" name="My shared measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[true]" UPDATED_AT="[null]"/>
   <measure_filter_favourites id="1" user_id="100" measure_filter_id="1" CREATED_AT="[null]"/>
   <measure_filter_favourites id="3" user_id="100" measure_filter_id="3" CREATED_AT="[null]"/>
-  <properties id="1" user_id="100" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]" />
+  <properties id="1" user_id="100" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
   <groups_users user_id="100" group_id="200"/>
   <user_roles id="1" user_id="100" role="admin" RESOURCE_ID="[null]"/>
 
-  <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="101" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
   <dashboards id="2" user_id="101" NAME="[null]" COLUMN_LAYOUT="[null]" CREATED_AT="[null]" DESCRIPTION="[null]" IS_GLOBAL="[false]" SHARED="[false]" UPDATED_AT="[null]"/>
   <active_dashboards id="2" user_id="101" dashboard_id="2" ORDER_INDEX="[null]"/>
   <active_dashboards id="4" user_id="101" dashboard_id="3" ORDER_INDEX="[null]"/>
@@ -45,7 +26,7 @@
   <measure_filters id="2" user_id="101" name="My measures" CREATED_AT="[null]" DATA="[null]" DESCRIPTION="[null]" SHARED="[false]" UPDATED_AT="[null]"/>
   <measure_filter_favourites id="2" user_id="101" measure_filter_id="2" CREATED_AT="[null]"/>
   <measure_filter_favourites id="4" user_id="101" measure_filter_id="3" CREATED_AT="[null]"/>
-  <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]" />
+  <properties id="2" user_id="101" PROP_KEY="[null]" RESOURCE_ID="[null]" TEXT_VALUE="[null]"/>
   <groups_users user_id="101" group_id="200"/>
   <user_roles id="2" user_id="101" role="admin" RESOURCE_ID="[null]"/>
 </dataset>
index 374d956745d104d1d69c4bc1c5beb232a3d22780..f5b642f4fed4218771c6154163eb4c37c19ead3b 100644 (file)
@@ -1,3 +1,3 @@
 <dataset>
-  <users id="1" login="john" name="John" email="jo@hn.com" created_at="2014-06-20" updated_at="2014-06-20" active="[true]"/>
+  <users id="1" login="john" name="John" email="jo@hn.com" created_at="1418215735482" updated_at="1418215735482" active="[true]"/>
 </dataset>
index 0052e0c54daf10081309148b14129fba66dac0ae..1927eda7d63f8be0d798a63ee40b5b02b5fa05c2 100644 (file)
@@ -1,11 +1,11 @@
 <dataset>
   <!-- inactive -->
-  <users id="50" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[false]"/>
+  <users id="50" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[false]"/>
 
   <!-- active -->
-  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
 
-  <users id="102" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="102" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
 
 
 </dataset>
index 9434d78f050c5b552e5f060eba3033b92f611027..01755d808c0bb472bd8cb153bbf787550cf85a7c 100644 (file)
@@ -1,4 +1,4 @@
 <dataset>
   <groups id="1" name="sonar-users" description="Sonar Users" created_at="2011-05-18" updated_at="2012-07-21"/>
   <groups id="2" name="sonar-administrators" description="Sonar Administrators" created_at="2011-05-18" updated_at="2012-07-21"/>
-</dataset>
\ No newline at end of file
+</dataset>
index c192749b43a21732acaf7faa7cb7f5a18833b865..3e671162c5839318e49ba889d12b173556a80eb4 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
-  <users id="100" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[false]"/>
-  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
-  <users id="102" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="100" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[false]"/>
+  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
+  <users id="102" login="jcdus" name="Jean-Claude Dus" email="jcdus@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
 
 </dataset>
index 9614d25eb152db8d4aa180d37cbcc82d9157ed31..52a2421ea31fcd10abd04ca5f1191d1e4a7a1eb1 100644 (file)
@@ -1,24 +1,5 @@
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2014 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube 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.
-  ~
-  ~ SonarQube 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 this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
 <dataset>
-  <users id="100" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[false]"/>
-  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="100" login="inactive_user" name="Disabled" email="inactive@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[false]"/>
+  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
 
 </dataset>
index 09a42cde6f86c16393cff9a808ec0d143c8c3ae5..6f5237422f9ea59d3c23f1473bbfb68db96ce0ba 100644 (file)
@@ -1,24 +1,5 @@
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2014 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube 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.
-  ~
-  ~ SonarQube 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 this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
 <dataset>
-  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
-  <users id="102" login="sbrandhof" name="Simon Brandhof" email="marius@lesbronzes.fr" created_at="2011-05-18" updated_at="2012-07-21" active="[true]"/>
+  <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
+  <users id="102" login="sbrandhof" name="Simon Brandhof" email="marius@lesbronzes.fr" created_at="1418215735482" updated_at="1418215735485" active="[true]"/>
 
 </dataset>