import org.sonar.core.review.ReviewDao;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.template.LoadedTemplateDao;
+import org.sonar.core.user.AuthorDao;
import java.util.Arrays;
import java.util.Collections;
public static List<Class<?>> getDaoClasses() {
return Collections.unmodifiableList(Arrays.asList(
ActiveDashboardDao.class,
+ AuthorDao.class,
DashboardDao.class,
DuplicationDao.class,
LoadedTemplateDao.class,
import org.sonar.core.rule.RuleMapper;
import org.sonar.core.template.LoadedTemplateDto;
import org.sonar.core.template.LoadedTemplateMapper;
+import org.sonar.core.user.AuthorDto;
+import org.sonar.core.user.AuthorMapper;
import java.io.IOException;
import java.io.InputStream;
conf.getVariables().setProperty("_false", database.getDialect().getFalseSqlValue());
loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
+ loadAlias(conf, "Author", AuthorDto.class);
loadAlias(conf, "Dashboard", DashboardDto.class);
loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
loadMapper(conf, ActiveDashboardMapper.class);
+ loadMapper(conf, AuthorMapper.class);
loadMapper(conf, DashboardMapper.class);
loadMapper(conf, DuplicationMapper.class);
loadMapper(conf, LoadedTemplateMapper.class);
--- /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.user;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+/**
+ * @since 2.15
+ */
+public class AuthorDao implements BatchComponent, ServerComponent {
+
+ private final MyBatis mybatis;
+
+ public AuthorDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public AuthorDto select(String login) {
+ SqlSession session = mybatis.openSession();
+ try {
+ AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+ return mapper.select(login);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(AuthorDto authorDto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+ mapper.insert(authorDto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+}
--- /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.user;
+
+import java.util.Date;
+
+/**
+ * @since 2.15
+ */
+public class AuthorDto {
+
+ private Integer id;
+ private Integer personId;
+ private String login;
+ private Date createdAt;
+ private Date updatedAt;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public AuthorDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public Integer getPersonId() {
+ return personId;
+ }
+
+ public AuthorDto setPersonId(Integer personId) {
+ this.personId = personId;
+ return this;
+ }
+
+ public String getLogin() {
+ return login;
+ }
+
+ public AuthorDto setLogin(String login) {
+ this.login = login;
+ return this;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public AuthorDto setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public AuthorDto setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
+}
--- /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.user;
+
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @since 2.15
+ */
+public interface AuthorMapper {
+
+ AuthorDto select(@Param("login") String login);
+
+ void insert(AuthorDto authorDto);
+
+}
--- /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
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.core.user;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.user.AuthorMapper">
+
+ <select id="select" parameterType="string" resultType="Author">
+ SELECT id, person_id AS "personId", login, created_at AS "createdAt", updated_at AS "updatedAt"
+ FROM authors WHERE login=#{login}
+ </select>
+
+ <insert id="insert" parameterType="Author" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+ select dashboards_seq.NEXTVAL from DUAL
+ </selectKey>
+ INSERT INTO authors (id, person_id, login, created_at, updated_at)
+ VALUES (#{id}, #{personId, jdbcType=INTEGER}, #{login, jdbcType=VARCHAR},
+ #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
+ </insert>
+
+</mapper>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.user.AuthorMapper">
+
+ <select id="select" parameterType="string" resultType="Author">
+ SELECT id, person_id AS "personId", login, created_at AS "createdAt", updated_at AS "updatedAt"
+ FROM authors WHERE login=#{login}
+ </select>
+
+ <insert id="insert" parameterType="Author" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO authors (person_id, login, created_at, updated_at)
+ VALUES (#{personId, jdbcType=INTEGER}, #{login, jdbcType=VARCHAR},
+ #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
+ </insert>
+
+</mapper>
--- /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.user;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.DaoTestCase;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class AuthorDaoTest extends DaoTestCase {
+
+ private AuthorDao dao;
+
+ @Before
+ public void setUp() {
+ dao = new AuthorDao(getMyBatis());
+ }
+
+ @Test
+ public void shouldSelect() {
+ setupData("shouldSelect");
+
+ AuthorDto authorDto = dao.select("godin");
+ assertThat(authorDto.getId(), is(1));
+ assertThat(authorDto.getPersonId(), is(13));
+ assertThat(authorDto.getLogin(), is("godin"));
+
+ assertThat(dao.select("simon"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldInsert() {
+ setupData("shouldInsert");
+
+ AuthorDto authorDto = new AuthorDto()
+ .setLogin("godin")
+ .setPersonId(13);
+
+ dao.insert(authorDto);
+
+ checkTables("shouldInsert", new String[] {"created_at", "updated_at"}, "authors");
+ }
+}
--- /dev/null
+<dataset>
+
+ <authors
+ id="1"
+ person_id="13"
+ login="godin" />
+
+</dataset>
--- /dev/null
+<dataset>
+</dataset>
--- /dev/null
+<dataset>
+
+ <authors
+ id="1"
+ person_id="13"
+ login="godin" />
+
+</dataset>