Code, JavaEE

Conference Database – Part 3

We are now beginning to write code for this project. The next thing to do is create a conference and persist it somehow. I say somehow because data can be stored

  • In Memory
  • In a File (csv, xml, json, custom format)
  • In a Relational Database
  • In a Graph Database or NoSQL type database

We will incrementally create code by first defining the method and classes we want then creating them as needed as to evolve the code base based on what is really required and no more. The following code illustrates this by creating a Conference instance then using the Conference Service to do the actual creation.

Conference.java


package com.davidking;

import java.util.UUID;

/**
 * Conference
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:38 PM
 */
public class Conference {
 private String id;
 private String title;
 private String theme;
 private Integer contactId;

public Conference(String title, String theme) {
 setId(UUID.randomUUID().toString());
 this.title = title;
 this.theme = theme;
 }

public String getId() {
 return id;
 }

public void setId(String id) {
 this.id = id;
 }

public String getTitle() {
 return title;
 }

public void setTitle(String title) {
 this.title = title;
 }

public String getTheme() {
 return theme;
 }

public void setTheme(String theme) {
 this.theme = theme;
 }

public Integer getContactId() {
 return contactId;
 }

public void setContactId(Integer contactId) {
 this.contactId = contactId;
 }

@Override
 public String toString() {
 return title;
 }
}

ConferenceService.java


 

package com.davidking;

/**
 * ConferenceService
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:32 PM
 */
public class ConferenceService {

public String create(Conference conference) {
 return conference.getId();
 }
}

ConferenceTest.java


 

package com.davidking;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;

/**
 * ConferenceTest
 *
 * @author David King
 * Date: 6/15/13
 * Time: 5:23 PM
 */
public class ConferenceTest {
 private ConferenceService conferenceService;

@Test
 public void testCreateConference() {
 // A Conference requires a title and theme, let's create one
 Conference conference = new Conference("Tech Conference Expo 2013", "Expanding the mind");

String conferenceId = conferenceService.create(conference);

assertNotNull("Conference id was null.", conferenceId);

System.out.format("Conference id returned -> %s", conferenceId);
 }

@Before
 public void setUp() {
 conferenceService = new ConferenceService();
 }

@After
 public void tearDown() {
 conferenceService = null;
 }
}

 


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s