Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create DataAccess Objects which will hold the listing data structures Singleton DTO DAO DAO file DataAccesObject.java package dao; import dto.BaseDto; import java.util.List; public interface DataAccessObject

Create DataAccess Objects which will hold the listing data structures

  • Singleton

  • DTO

  • DAO

DAO file

DataAccesObject.java

package dao; import dto.BaseDto; import java.util.List; public interface DataAccessObject { static DataAccessObject getInstance(){ throw new RuntimeException("not implemented"); } T put(T item); List getItems(); void delete(String id); }

ItemDao.java

package dao; import dto.ItemDto; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class ItemDao implements DataAccessObject { public static ItemDao getInstance(){ return null; } private ItemDao(){ } @Override public ItemDto put(ItemDto item) { return null; } @Override public List getItems() { return null; } @Override public void delete(String id) { } }

DTO file

BaseDto.java

package dto; public class BaseDto { public final String entity_id; public BaseDto(String entity_id) { this.entity_id = entity_id; } }

ItemDto.java

package dto; public class ItemDto extends BaseDto { public String description; public String type; public Integer price; public String title; public ItemDto(String id, String description, String type, Integer price, String title) { super(id); this.description = description; this.type = type; this.price = price; this.title = title; } public ItemDto(String description, String type, Integer price, String title) { super(null); this.description = description; this.type = type; this.price = price; this.title = title; } }

ResonseDto.java

package dto; import java.util.Date; import java.util.List; public class ResponseDto{ public final Date date; public final List items; public final Boolean success; public ResponseDto(Date date, List items, Boolean success) { this.date = date; this.items = items; this.success = success; } } 

Test

DaoTests.java

package dao; import dto.ItemDto; import org.testng.Assert; import org.testng.annotations.Test; public class DaoTests { @Test public void testDaos(){ ItemDao itemDao = ItemDao.getInstance(); Assert.assertTrue(DataAccessObject.class.isAssignableFrom(itemDao.getClass())); ItemDto itemDto = new ItemDto(null, null, null, null); itemDao.put(itemDto); Assert.assertEquals(itemDao.getItems().size(), 1); Assert.assertNotNull(itemDao.getItems().get(0).entity_id); String id = itemDao.getItems().get(0).entity_id; itemDao.delete(id); Assert.assertEquals(itemDao.getItems().size(), 0); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Describe the economic model that is proposed for the operation.

Answered: 1 week ago