Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help in apache Tapestry(code in Java): I have partial code You will also wa

ID: 3743394 • Letter: N

Question

Need help in apache Tapestry(code in Java):

I have partial code

You will also want to create a Service the mimics a database. For this assignment, you will not be connecting to a real database, and instead creating a fake, mock database that can be used instead. This isn't strictly necessary, but it will allow us to practice building pages that operate like those in a real application.

In the Services package for your Tapestry project, create an interface with the name DatabaseService. You should add the following methods (you can substitute CustomEntity with the actual name of the class you created) at a minimum, though you may wish to add others:

List getAllEntities()

CustomEntity getEntity(int PK)

updateEntity(CustomEntity entity)

deleteEntity(int PK)

addEntity(CustomEntity entity)

Next you will need to create a different class in the Services package that implements the DatabaseService interface you just created. You can simulate a database by using a HashMap (you can use Java's built-in HashMap class) that uses int and CustomEntity types as the key and value pair. Inside the default constructor for this class, you should populate the HashMap with at least 10 instances of your CustomEntity class. You can hard-code the values for these or you can create a method to generate instances of your class with random data values. It is also recommended that you have a field in this class that keeps track of the next PK value, so that when you add new records to your database you can generate PK values in a procedural way.

Once you have created both of these classes, you will need to bind your implementation to the interface, so that Tapestry knows to use the fake database class that you've created whenever any of the Page classes you create reference and use DatabaseService. To do this, you will need to make changes to the AppModule class (located in the services package) and add the following line of code to the bind method:

binder.bind(DatabaseService.class, FakeDatabaseImplementation.class);

Note that when you run your project and Tapestry is launched, the default constructor for your implementation class is automatically called when it is bound to the interface, so that method should be responsible for populating the underlying data structure with instances of your custom entity.

Additionally, all of the code to interact with the database should be contained in your mock database class. Essentially, the Tapestry pages you create will only call methods on your DatabaseService class. This has the added effect of separating the persistence layer of your application from the control layer, which is highly desirable from a design perspective.

code:

The EntityLocator interface provides entity definitions.

A simple implementation of EntityLocator would be :-

The service definition is

The service definition does everything except for actually creating the service, which is delegated to EntityDAOSource.

As an example, let us consider a generic DAO implemented in Hibernate

For this implementation, EntityDAOSource can be implemented like

Finally this module definition can be contributed by overriding provideExtraModuleDefs() method in TapestryFilter.

Explanation / Answer

Tapestry project :

Module definition :

The EntityLocator interface provides entity definitions.

A simple implementation of EntityLocator would be :-

The service definition is

The service definition does everything except for actually creating the service, which is delegated to EntityDAOSource.

As an example, let us consider a generic DAO implemented in Hibernate

For this implementation, EntityDAOSource can be implemented like

Finally this module definition can be contributed by overriding provideExtraModuleDefs() method in TapestryFilter.

please upvote

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote