November 2017
Intermediate to advanced
542 pages
14h 24m
English
In our EventDao interface, we are required to create a new Event object. With JPA, we can have our object ID automatically generated. With MongoDB, there are several ways to assign primary key identifiers, but for the sake of this demonstration, we are just going to use an atomic counter, as follows:
//src/main/java/com/packtpub/springsecurity/dataaccess/MongoEventDao.java ... import java.util.concurrent.atomic.AtomicInteger; @Repository public class MongoEventDao implements EventDao { // Simple Primary Key Generator private AtomicInteger eventPK = new AtomicInteger(102); ... @Override public int createEvent(Event event) { ... // Get the next PK instance event.setId(eventPK.incrementAndGet()); Event newEvent ...Read now
Unlock full access