View Javadoc
1   /**
2    * 
3    */
4   package com.gisgraphy.domain.repository;
5   
6   import org.slf4j.Logger;
7   import org.slf4j.LoggerFactory;
8   import org.springframework.beans.factory.InitializingBean;
9   import org.springframework.beans.factory.annotation.Autowired;
10  import org.springframework.stereotype.Component;
11  
12  /**
13   * Do some initializing stuff on the database (create normalize_text function)
14   * 
15   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
16   */
17  @Component
18  public class DatabaseInitializer implements InitializingBean {
19  
20  	protected static final Logger logger = LoggerFactory.getLogger(DatabaseInitializer.class);
21  	
22  	@Autowired
23  	private IDatabaseHelper databaseHelper;
24  	
25  	/* (non-Javadoc)
26  	 * @see com.gisgraphy.domain.repository.IDatabaseInitializer#init()
27  	 */
28  	public void afterPropertiesSet() throws Exception{
29  		if (!databaseHelper.isNormalize_textFunctionCreated()){
30      		logger.error("The "+DatabaseHelper.NORMALIZE_TEXT_FUNCTION_NAME+" does not exists, try to create it");
31      		try {
32  				databaseHelper.createNormalize_textFunction();
33  			} catch (RuntimeException e) {
34  				throw new RuntimeException("The "+DatabaseHelper.NORMALIZE_TEXT_FUNCTION_NAME+" is not created. This function is required for the streetsearch engine and We can not create it (maybe the SQL user haven't the rights to create the function) : "+e.getCause().getMessage(),e);
35  			}
36  			logger.info("The "+DatabaseHelper.NORMALIZE_TEXT_FUNCTION_NAME+" has been created");
37      	}
38  	}
39  	
40  }