View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.importer;
24  
25  import java.io.File;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  import com.gisgraphy.domain.valueobject.NameValueDTO;
33  
34  /**
35   * Import the Adm of level 1 file. It is the first step of the Adm1 import
36   * process, the import will be complete when all the datastore object will be
37   * updated by the {@link GeonamesFeatureSimpleImporter}
38   * 
39   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
40   */
41  public class GeonamesAdm1Importer extends GeonamesFeatureSimpleImporter {
42  
43  	
44  	protected static final Logger logger = LoggerFactory.getLogger(GeonamesAdm1Importer.class);
45  	
46  	 /*
47       * (non-Javadoc)
48       * 
49       * @see com.gisgraphy.domain.geoloc.importer.AbstractImporterProcessor#getFiles()
50       */
51      @Override
52      protected File[] getFiles() {
53  	File[] files = new File[1];
54  	files[0] = new File(importerConfig.getGeonamesDir()
55  		+ importerConfig.getAdm1FileName());
56  	return files;
57      }
58      
59      
60  	@Override
61  	protected boolean isAdmMode() {
62  		return true;
63  	}
64     
65  
66      /*
67       * (non-Javadoc)
68       * 
69       * @see com.gisgraphy.domain.geoloc.importer.AbstractImporterProcessor#getMaxInsertsBeforeFlush()
70       */
71      @Override
72      protected int getMaxInsertsBeforeFlush() {
73  	// we commit each times because we don't want duplicate adm and the
74  	// cache is NONSTRICT_READ_WRITE (assynchronous)
75  	return 1;
76      }
77  
78      /*
79       * (non-Javadoc)
80       * 
81       * @see com.gisgraphy.domain.geoloc.importer.IGeonamesProcessor#rollback()
82       */
83      public List<NameValueDTO<Integer>> rollback() {
84  	List<NameValueDTO<Integer>> deletedObjectInfo = new ArrayList<NameValueDTO<Integer>>();
85  	logger.info("deleting adm1...");
86  	int deletedadm = admDao.deleteAllByLevel(1);
87  	if (deletedadm != 0) {
88  	    deletedObjectInfo
89  		    .add(new NameValueDTO<Integer>("ADM1", deletedadm));
90  	}
91  	logger.info(deletedadm + " adm1s have been deleted");
92  	resetStatus();
93  	return deletedObjectInfo;
94      }
95  
96  }