48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package com.covas.ApplicationScoped;
|
|
|
|
|
|
import org.jboss.logging.Logger;
|
|
|
|
import io.quarkus.runtime.ShutdownEvent;
|
|
import io.quarkus.runtime.StartupEvent;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.Month;
|
|
|
|
import javax.enterprise.context.ApplicationScoped;
|
|
import javax.enterprise.event.Observes;
|
|
import javax.inject.Inject;
|
|
import javax.transaction.Transactional;
|
|
|
|
import com.covas.Entity.UsersEntity;
|
|
|
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
|
|
|
|
|
@ApplicationScoped
|
|
public class ApplicationLifeCycle {
|
|
@Inject
|
|
@ConfigProperty(name = "covas.schema.create", defaultValue = "true")
|
|
boolean schemaCreate;
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(ApplicationLifeCycle.class);
|
|
|
|
@Transactional
|
|
void onStart(@Observes StartupEvent ev) {
|
|
LOGGER.info("The application has started");
|
|
if (schemaCreate){
|
|
UsersEntity.deleteAll();
|
|
LOGGER.info("Robert80 user is created");
|
|
UsersEntity.add("robert80", "robert80@gmail.com", "titi", "robert", LocalDate.of(1990, Month.JANUARY, 23), "toto", "User");
|
|
LOGGER.info("Peter93 user is created");
|
|
UsersEntity.add("peter93", "peter93gmail.com", "yollo", "peter", LocalDate.of(1993, Month.FEBRUARY, 26), "toto", "Admin");
|
|
} else {
|
|
LOGGER.info("DB init wassn't created");
|
|
}
|
|
}
|
|
void onStop(@Observes ShutdownEvent ev) {
|
|
LOGGER.info("The application is stopping...");
|
|
}
|
|
|
|
}
|