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