com.wallmart.calculateroute.ApplicationStartup.java Source code

Java tutorial

Introduction

Here is the source code for com.wallmart.calculateroute.ApplicationStartup.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wallmart.calculateroute;

import com.wallmart.calculateroute.domain.CalculateRoute;
import com.wallmart.calculateroute.domain.Route;
import com.wallmart.calculateroute.service.dao.CalculateRouteService;
import com.wallmart.calculateroute.service.dao.GraphDatabase;
import com.wallmart.calculateroute.singleton.GraphDatabaseServiceSingleton;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 *
 * @author Thomas Daniel Kaneko Teixeira(TDKT)
 */
@Component
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {

    /*
     * This method is called during Spring's startup.
     * 
     * @param event Event raised when an ApplicationContext gets initialized or
     * refreshed.
     */

    final static Logger logger = Logger.getLogger(ApplicationStartup.class);

    @Override
    public void onApplicationEvent(final ContextRefreshedEvent event) {

        //    GraphDatabaseService instance = GraphDatabaseServiceSingleton.getInstance();
        logger.info("###Startup DB");
        GraphDatabaseServiceSingleton.getInstance();
        logger.info("###Started DB");

        logger.info("###insert and get some info");

        GraphDatabase graphdb = new GraphDatabase();
        Route r = new Route("test", "A", "B", 10L);
        graphdb.insertRoute(r);

        CalculateRoute cr = graphdb
                .shortestRouteDistance(new CalculateRoute("test", "A", "B", 10l, BigDecimal.ZERO));

        logger.info("###DB working fine");
    }

}