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 3 file. It is the first step of the adm3 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 GeonamesAdm3Importer extends GeonamesFeatureSimpleImporter {
42  
43  
44  	protected static final Logger logger = LoggerFactory.getLogger(GeonamesAdm3Importer.class);
45      
46  	@Override
47  	protected boolean isAdmMode() {
48  		return true;
49  	}
50  
51      /*
52       * (non-Javadoc)
53       * 
54       * @see com.gisgraphy.domain.geoloc.importer.AbstractImporterProcessor#getFiles()
55       */
56      @Override
57      protected File[] getFiles() {
58  	File[] files = new File[1];
59  	files[0] = new File(importerConfig.getGeonamesDir()
60  		+ importerConfig.getAdm3FileName());
61  	return files;
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see com.gisgraphy.domain.geoloc.importer.AbstractImporterProcessor#getMaxInsertsBeforeFlush()
68       */
69      @Override
70      protected int getMaxInsertsBeforeFlush() {
71  	// we commit each times because we don't want duplicate adm and the
72  	// cache is NONSTRICT_READ_WRITE (assynchronous)
73  	return 1;
74      }
75  
76      /*
77       * (non-Javadoc)
78       * 
79       * @see com.gisgraphy.domain.geoloc.importer.IGeonamesProcessor#rollback()
80       */
81      public List<NameValueDTO<Integer>> rollback() {
82  	List<NameValueDTO<Integer>> deletedObjectInfo = new ArrayList<NameValueDTO<Integer>>();
83  	logger.info("deleting adm3...");
84  	int deletedadm = admDao.deleteAllByLevel(3);
85  	if (deletedadm != 0) {
86  	    deletedObjectInfo
87  		    .add(new NameValueDTO<Integer>("ADM3", deletedadm));
88  	}
89  	logger.info(deletedadm + " adm3s have been deleted");
90  	resetStatus();
91  	return deletedObjectInfo;
92      }
93  
94  }