Projects >> jtalks-common >>3706d7695b778ca73c7e4dd3fadb024c24297b0e

Chunk
Conflicting content
    }
    }

    /**
<<<<<<< HEAD
     * {@inheritDoc}
     * @deprecated This method is not needed any more. Use {@link get(id)} instead,
     * it returns Topic with User now.
     */
    @Override
    public Topic getTopicWithUser(Long id) {
        return get(id);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Topic getTopicWithPosts(Long id) {
        Query query = getSession().getNamedQuery("getTopicWithPosts");
=======
     * Load the Topic with userCreated field initialized. The method doesn't load related posts.
     * @param id Topic id
     * @return the Topic or null if the appropriate topic wasn't found
     */
    public Topic getTopicWithUser(Long id) {
        Query query = getSession().createQuery("from Topic as topic "
                + "join fetch topic.userCreated "
                + "WHERE topic.id = :topicId");
        query.setLong("topicId", id);
        return (Topic) query.uniqueResult();
    }

    /**
     * Load the Topic with userCreated and related posts.
     * @param id Topic id
     * @return loaded Topic or null if the appropriate topic wasn't found
     */
    public Topic getTopicWithPosts(Long id) {
        Query query = getSession().createQuery("from Topic as topic "
                + "join fetch topic.userCreated "
                + "join fetch topic.posts "
                + "WHERE topic.id = :topicId");
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
        query.setLong("topicId", id);
        return (Topic) query.uniqueResult();
Solution content
    /**
     * {@inheritDoc}

/* 
 * JTalks for uniting people
 * Copyright (C) 2011  JavaTalks Team
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * Also add information on how to contact you by electronic and paper mail.
 * 
 * This file creation date: Apr 12, 2011 / 8:05:19 PM
 * The JTalks Project
 * http://www.jtalks.org
 */
package org.jtalks.jcommune.model.dao.hibernate;

import org.jtalks.jcommune.model.dao.TopicDao;
import org.jtalks.jcommune.model.entity.Topic;
import java.util.List;
import org.hibernate.Query;

/**
 * Data Access Object for {@link Topic} instances.
 * 
 * @author Pavel Vervenko
 */
public class TopicHibernateDao extends AbstractHibernateDao implements TopicDao {

    /**
     * {@inheritDoc}
     */
    @Override
    public void saveOrUpdate(Topic topic) {
        getSession().save(topic);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void delete(Long id) {
        Query query = getSession().createQuery("delete Topic where id= :topicId");
        query.setLong("topicId", id);
        query.executeUpdate();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Topic get(Long id) {
        return (Topic) getSession().get(Topic.class, id);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List getAll() {
        return getSession().createQuery("from Topic").list();
    }
     * @deprecated This method is not needed any more. Use {@link get(id)} instead,
     * it returns Topic with User now.
     */
    @Override
    public Topic getTopicWithUser(Long id) {
        return get(id);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Topic getTopicWithPosts(Long id) {
        Query query = getSession().getNamedQuery("getTopicWithPosts");
        query.setLong("topicId", id);
        return (Topic) query.uniqueResult();
    }
}
File
TopicHibernateDao.java
Developer's decision
Manual
Kind of conflict
Annotation
Comment
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
    }
        this.id = id;

<<<<<<< HEAD
    /**
     * {@inheritDoc }
     */
=======
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
Solution content
/* 
 * JTalks for uniting people
 * Copyright (C) 2011  JavaTalks Team
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * Also add information on how to contact you by electronic and paper mail.
 * 
 * This file creation date: Apr 12, 2011 / 8:05:19 PM
 * The JTalks Project
 * http://www.jtalks.org
 */
package org.jtalks.jcommune.model.entity;

/**
 * Basic class for persistent objects.
 * 
 * @author Pavel Vervenko
 */
public abstract class Persistent {

    private long id;

    /**
     * Get the primary id of the persistent object.
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * Set the id for the persistent object.
     * @param id id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Persistent other = (Persistent) obj;
        return id == other.id;
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
}
File
Persistent.java
Developer's decision
Manual
Kind of conflict
Comment
Chunk
Conflicting content
        return id == other.id;
    }

<<<<<<< HEAD
    /**
     * {@inheritDoc }
     */
=======
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
    @Override
    public int hashCode() {
        int hash = 5;
Solution content
/* 
 * JTalks for uniting people
 * Copyright (C) 2011  JavaTalks Team
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * Also add information on how to contact you by electronic and paper mail.
 * 
 * This file creation date: Apr 12, 2011 / 8:05:19 PM
 * The JTalks Project
 * http://www.jtalks.org
 */
package org.jtalks.jcommune.model.entity;

/**
 * Basic class for persistent objects.
 * 
 * @author Pavel Vervenko
 */
public abstract class Persistent {

    private long id;

    /**
     * Get the primary id of the persistent object.
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * Set the id for the persistent object.
     * @param id id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Persistent other = (Persistent) obj;
        return id == other.id;
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
}
File
Persistent.java
Developer's decision
Manual
Kind of conflict
Comment
Chunk
Conflicting content
    private User userCreated;
    private String postContent;
    private Topic topic;
<<<<<<< HEAD

    public Post() {
    }

    public Post(DateTime creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * Creates the new instance with the creationDate initialized with current time.
     * @return 
     */
    public static Post createNewPost() {
        return new Post(new DateTime());
    }
=======
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5

    public Post() {
        postDate = new Date();
Solution content
    public Post() {
    }
/* 
 * JTalks for uniting people
 * Copyright (C) 2011  JavaTalks Team
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * Also add information on how to contact you by electronic and paper mail.
 * 
 * This file creation date: Apr 12, 2011 / 8:05:19 PM
 * The JTalks Project
 * http://www.jtalks.org
 */
package org.jtalks.jcommune.model.entity;

import org.joda.time.DateTime;

/**
 * Represents the simple version of post of the forum
 * with String content.
 * Contains in some {@link Topic}.
 * 
 * @author Pavel Vervenko
 */
public class Post extends Persistent {

    private DateTime creationDate;
    private User userCreated;
    private String postContent;
    private Topic topic;


    public Post(DateTime creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * Creates the new instance with the creationDate initialized with current time.
     * @return 
     */
    public static Post createNewPost() {
        return new Post(new DateTime());
    }

    /**
     * @return the postDate
     */
    public DateTime getCreationDate() {
        return creationDate;
    }

    /**
     * @param postDate the postDate to set
     */
    public void setCreationDate(DateTime postDate) {
        this.creationDate = postDate;
    }

    /**
     * @return the userCreated
     */
    public User getUserCreated() {
        return userCreated;
    }

    /**
     * @param userCreated the userCreated to set
     */
    public void setUserCreated(User userCreated) {
        this.userCreated = userCreated;
    }

    /**
     * @return the postContent
     */
    public String getPostContent() {
        return postContent;
    }

    /**
     * @param postContent the postContent to set
     */
    public void setPostContent(String postContent) {
        this.postContent = postContent;
    }

    /**
     * @return the post
     */
    public Topic getTopic() {
        return topic;
    }

    /**
     * @param post the post to set
     */
    public void setTopic(Topic topic) {
        this.topic = topic;
    }
}
File
Post.java
Developer's decision
Manual
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
    /**
     * The list of topic's posts
     */
<<<<<<< HEAD
    private List posts = new ArrayList();
    
    public Topic() {
    }
    
    public Topic(DateTime creationDate) {
        this.creationDate = creationDate;
    }
    
    /**
     * Creates a new Topic with the creationDate initialized with current time.
     * @return 
     */
    public static Topic createNewTopic() {
        return new Topic(new DateTime());
    }
=======
    private List posts;
    
    public Topic() {
        posts = new ArrayList();
        creationDate = new Date();
    }

>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
    /**
     * Add new {@link Post} to the topic.
     * The method sets Posts.topic field to this Topic.
Solution content
    }
/* 
 * JTalks for uniting people
 * Copyright (C) 2011  JavaTalks Team
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * Also add information on how to contact you by electronic and paper mail.
 * 
 * This file creation date: Apr 12, 2011 / 8:05:19 PM
 * The JTalks Project
 * http://www.jtalks.org
 */
package org.jtalks.jcommune.model.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.joda.time.DateTime;

/**
 * Represents the topic of the forum.
 * Contains the list of related {@link Post}.
 * @author Pavel Vervenko
 */
public class Topic extends Persistent {

    /**
     * The creation date of the topic. 
     */
    private DateTime creationDate;
    /**
     * The user who create the topic
     */
    private User topicStarter;
    private String title;
    /**
     * The list of topic's posts
     */
    private List posts = new ArrayList();
    
    public Topic() {
    }
    
    public Topic(DateTime creationDate) {
        this.creationDate = creationDate;
    }
    
    /**
     * Creates a new Topic with the creationDate initialized with current time.
     * @return 
     */
    public static Topic createNewTopic() {
        return new Topic(new DateTime());
    /**
     * Add new {@link Post} to the topic.
     * The method sets Posts.topic field to this Topic.
     * @param newPost 
     */
    public void addPost(Post newPost) {
        posts.add(newPost);
        newPost.setTopic(this);
    }

    /**
     * Remove the post from the topic.
     * @param postToRemove 
     */
    public void removePost(Post postToRemove) {
        posts.remove(postToRemove);
    }

    /**
     * Get the post creation date.
     * @return the creationDate
     */
    public DateTime getCreationDate() {
        return creationDate;
    }

    /**
     * Set the post creation date.
     * @param creationDate the creationDate to set
     */
    public void setCreationDate(DateTime creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * Get the user who created the post.
     * @return the userCreated
     */
    public User getTopicStarter() {
        return topicStarter;
    }

    /**
     * The the author of the post.
     * @param userCreated the user who create the post
     */
    public void setTopicStarter(User userCreated) {
        this.topicStarter = userCreated;
    }

    /**
     * Gets the topic name.
     * @return the topicName
     */
    public String getTitle() {
        return title;
    }

    /**
     * Sets the topic title.
     * @param newTitle the title to set
     */
    public void setTitle(String newTitle) {
        this.title = newTitle;
    }

    /**
     * Get the list of the posts.
     * @return the list of posts
     */
    public List getPosts() {
        return posts;
    }

    /**
     * Set the list of posts
     * @param posts the posts to set
     */
    public void setPosts(List posts) {
        this.posts = posts;
    }
 }
File
Topic.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Method declaration
Method invocation
Chunk
Conflicting content
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

<<<<<<< HEAD
=======
import javax.annotation.Resource;
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
import java.util.List;
import org.jtalks.jcommune.model.dao.PostDao;
import org.jtalks.jcommune.model.dao.UserDao;
Solution content
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.List;
import org.jtalks.jcommune.model.dao.PostDao;
import org.jtalks.jcommune.model.dao.UserDao;
File
PostHibernateDaoTest.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
    @BeforeMethod
    public void setUp() throws Exception {
<<<<<<< HEAD
        User user = new User();
        userDao.saveOrUpdate(user);
        entity = Post.createNewPost();
        entity.setPostContent("PostContent");
        entity.setUserCreated(user);
=======
        dao = new PostHibernateDao();
        dao.setSessionFactory(sessionFactory);
        Assert.assertNotNull(sessionFactory, SESSION_FACTORY_IS_NULL);
        entity = new Post();
        entity.setPostContent("PostContent");
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
        clearDbTable(entity, sessionFactory);
    }
Solution content
    @BeforeMethod
    public void setUp() throws Exception {
        User user = new User();
        userDao.saveOrUpdate(user);
        entity = Post.createNewPost();
        entity.setPostContent("PostContent");
        entity.setUserCreated(user);
        clearDbTable(entity, sessionFactory);
    }
File
PostHibernateDaoTest.java
Developer's decision
Version 1
Kind of conflict
Attribute
Method invocation
Variable
Chunk
Conflicting content
        dao.setSessionFactory(sessionFactory);
        Assert.assertNotNull(sessionFactory, SESSION_FACTORY_IS_NULL);
        entity = new Topic();
<<<<<<< HEAD
        entity.setTitle("TopicName");
        entity.setTopicStarter(null);
=======
        entity.setTopicName("TopicName");
        entity.setUserCreated(null);
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5

        clearDbTable(entity, sessionFactory);
    }
Solution content
        dao.setSessionFactory(sessionFactory);
        Assert.assertNotNull(sessionFactory, SESSION_FACTORY_IS_NULL);
        entity = new Topic();
        entity.setTitle("TopicName");
        entity.setTopicStarter(null);

        clearDbTable(entity, sessionFactory);
    }
File
TopicHibernateDaoTest.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Chunk
Conflicting content
        User user = new User();
        user.setNickName("NickName");
        getUserDao().saveOrUpdate(user);
<<<<<<< HEAD
        entity.setTopicStarter(user);
        dao.saveOrUpdate(entity);
        Long topicId = entity.getId();
        Topic loadedTopic = dao.getTopicWithUser(topicId);
        Assert.assertNotNull(loadedTopic.getTopicStarter(), USER_IS_NULL);
        Assert.assertEquals(user, loadedTopic.getTopicStarter(), LOADED_USER_ERROR);
=======
        entity.setUserCreated(user);
        dao.saveOrUpdate(entity);
        Long topicId = entity.getId();
        Topic loadedTopic = dao.getTopicWithUser(topicId);
        Assert.assertNotNull(loadedTopic.getUserCreated(), USER_IS_NULL);
        Assert.assertEquals(user, loadedTopic.getUserCreated(), LOADED_USER_ERROR);
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
    }

    @Test
Solution content
        User user = new User();
        user.setNickName("NickName");
        getUserDao().saveOrUpdate(user);
        entity.setTopicStarter(user);
        dao.saveOrUpdate(entity);
        Long topicId = entity.getId();
        Topic loadedTopic = dao.getTopicWithUser(topicId);
        Assert.assertNotNull(loadedTopic.getTopicStarter(), USER_IS_NULL);
        Assert.assertEquals(user, loadedTopic.getTopicStarter(), LOADED_USER_ERROR);
    }

    @Test
File
TopicHibernateDaoTest.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
        entity.addPost(post1);
        entity.addPost(post2);
        Collection allPosts = entity.getPosts();
<<<<<<< HEAD
        entity.setTopicStarter(user);
=======
        entity.setUserCreated(user);
>>>>>>> 139fda9e526d1ee93fbd72c2fdbf1ab152782ec5
        dao.saveOrUpdate(entity);
        Long topicId = entity.getId();
        Topic loadedTopic = dao.getTopicWithPosts(topicId);
Solution content
        entity.addPost(post1);
        entity.addPost(post2);
        Collection allPosts = entity.getPosts();
        entity.setTopicStarter(user);
        dao.saveOrUpdate(entity);
        Long topicId = entity.getId();
        Topic loadedTopic = dao.getTopicWithPosts(topicId);
File
TopicHibernateDaoTest.java
Developer's decision
Version 1
Kind of conflict
Method invocation