Permalink
Browse files

new option --smartInheritance

This code has been funded by the Canton of Solothurn (Switzerland)
  • Loading branch information...
claeis committed Dec 23, 2015
1 parent eda9f9b commit 2cb22eb3fc4f719f27a94089694a5383017b46bb
@@ -10,16 +10,16 @@ ideas/open issues/questions
- support ili2 views
- --initNameMapping
- support geopackage
- smart inheritance mapping
- map simple unique constraints

ili2pg 2.5.0 (2015-12-xx)
ili2pg 2.5.0 (2015-12-23)
----------------------------
- ili-obj/sql-record conversion refactored
- new option --noSmartMapping
- new option --coalesceCatalogueRef
- new option --expandMultilingual
- new option --coalesceMultiSurface
- new option --smartInheritance

ili2pg 2.4.0 (2015-12-09)
----------------------------
BIN +257 Bytes (100%) docs/ili2pg.docx
Binary file not shown.
@@ -50,6 +50,7 @@ public void initConfig(Config config)
config.setDefaultSrsCode("21781");
config.setMaxSqlNameLength(Integer.toString(NameMapping.DEFAULT_NAME_LENGTH));
config.setIdGenerator(ch.ehi.ili2db.base.TableBasedIdGen.class.getName());
config.setInheritanceTrafo(config.INHERITANCE_TRAFO_SMART);
config.setCatalogueRefTrafo(Config.CATALOGUE_REF_TRAFO_COALESCE);
config.setMultiSurfaceTrafo(Config.MULTISURFACE_TRAFO_COALESCE);
config.setMultilingualTrafo(Config.MULTILINGUAL_TRAFO_EXPAND);
@@ -175,6 +176,10 @@ public void domain(String args[]){
config.setCatalogueRefTrafo(null);
config.setMultiSurfaceTrafo(null);
config.setMultilingualTrafo(null);
config.setInheritanceTrafo(null);
}else if(arg.equals("--smartInheritance")){
argi++;
config.setInheritanceTrafo(config.INHERITANCE_TRAFO_SMART);
}else if(arg.equals("--coalesceCatalogueRef")){
argi++;
config.setCatalogueRefTrafo(config.CATALOGUE_REF_TRAFO_COALESCE);
@@ -262,6 +267,7 @@ public void domain(String args[]){
System.err.println("--dropscript filename Generate a sql script that drops the generated db schema.");
System.err.println("--mapconfig filename Name of config file, that controls the schema mapping.");
System.err.println("--noSmartMapping disable all smart mappings");
System.err.println("--smartInheritance enable smart mapping of class/structure inheritance");
System.err.println("--coalesceCatalogueRef enable smart mapping of CHBase:CatalogueReference");
System.err.println("--coalesceMultiSurface enable smart mapping of CHBase:MultiSurface");
System.err.println("--expandMultilingual enable smart mapping of CHBase:MultilingualText");
@@ -360,7 +360,8 @@ public static void runUpdate(Config config,String appHome,boolean importOnly)
}
}
java.util.List<Element> eles=ms.getModelElements(modelNames,td, td.getIli1Format()!=null && config.getDoItfLineTables(),Config.CREATE_ENUM_DEFS_MULTI.equals(config.getCreateEnumDefs()));
optimizeSqlNames(config,mapping,eles);
optimizeSqlTableNames(config,mapping,eles);
Viewable2TableMapping class2wrapper=Viewable2TableMapper.getClass2TableMapping(config,trafoConfig,eles);

Generator gen=null;
try{
@@ -396,7 +397,7 @@ public static void runUpdate(Config config,String appHome,boolean importOnly)
// map ili-classes to sql-tables
DbSchema schema;
try {
schema = trsfFromIli.doit(td,eles,mapping,config,idGen,trafoConfig);
schema = trsfFromIli.doit(td,eles,mapping,config,idGen,trafoConfig,class2wrapper);
} catch (Ili2dbException e) {
throw new Ili2dbException("mapping of ili-classes to sql-tables failed",e);
}
@@ -467,7 +468,7 @@ public static void runUpdate(Config config,String appHome,boolean importOnly)
}else{
ioxReader=new XtfReader(in);
}
transferFromXtf(conn,ioxReader,importOnly,mapping,td,dbusr,geomConverter,idGen,config,stat,trafoConfig);
transferFromXtf(conn,ioxReader,importOnly,mapping,td,dbusr,geomConverter,idGen,config,stat,trafoConfig,class2wrapper);
} catch (IOException ex) {
throw new Ili2dbException(ex);
} catch (IoxException ex) {
@@ -531,7 +532,7 @@ public static void runUpdate(Config config,String appHome,boolean importOnly)
}else{
ioxReader=new XtfReader(new java.io.File(inputFilename));
}
transferFromXtf(conn,ioxReader,importOnly,mapping,td,dbusr,geomConverter,idGen,config,stat,trafoConfig);
transferFromXtf(conn,ioxReader,importOnly,mapping,td,dbusr,geomConverter,idGen,config,stat,trafoConfig,class2wrapper);
} catch (IoxException e) {
throw new Ili2dbException(e);
}finally{
@@ -841,7 +842,8 @@ public static void runSchemaImport(Config config,String appHome)
}
}
java.util.List<Element> eles=ms.getModelElements(modelNames,td, td.getIli1Format()!=null && config.getDoItfLineTables(),Config.CREATE_ENUM_DEFS_MULTI.equals(config.getCreateEnumDefs()));
optimizeSqlNames(config,mapping,eles);
optimizeSqlTableNames(config,mapping,eles);
Viewable2TableMapping class2wrapper=Viewable2TableMapper.getClass2TableMapping(config,trafoConfig,eles);

SqlColumnConverter geomConverter=null;
try{
@@ -860,7 +862,7 @@ public static void runSchemaImport(Config config,String appHome)
// TODO move default SRS to config
DbSchema schema;
try {
schema = trsfFromIli.doit(td,eles,mapping,config,idGen,trafoConfig);
schema = trsfFromIli.doit(td,eles,mapping,config,idGen,trafoConfig,class2wrapper);
} catch (Ili2dbException e) {
throw new Ili2dbException("mapping of ili-classes to sql-tables failed",e);
}
@@ -1172,14 +1174,30 @@ public static void runExport(Config config,String appHome)
}
TrafoConfig trafoConfig=new TrafoConfig();
trafoConfig.readTrafoConfig(conn, config.getDbschema());


ModelElementSelector ms=new ModelElementSelector();
ArrayList<String> modelNames=new ArrayList<String>();
{
Iterator<ch.interlis.ili2c.config.FileEntry> modi=modelv.iteratorFileEntry();
while(modi.hasNext()){
ch.interlis.ili2c.config.FileEntry mod=modi.next();
if(mod.getKind()==ch.interlis.ili2c.config.FileEntryKind.ILIMODELFILE){
modelNames.add(mod.getFilename());
EhiLogger.traceState("modelname <"+mod.getFilename()+">");
}
}
}

java.util.List<Element> eles=ms.getModelElements(modelNames,td, td.getIli1Format()!=null && config.getDoItfLineTables(),Config.CREATE_ENUM_DEFS_MULTI.equals(config.getCreateEnumDefs()));
Viewable2TableMapping class2wrapper=Viewable2TableMapper.getClass2TableMapping(config,trafoConfig,eles);

// process xtf files
EhiLogger.logState("process data...");
EhiLogger.logState("data <"+xtffile+">");
HashSet<BasketStat> stat=new HashSet<BasketStat>();
ch.ehi.basics.logging.ErrorTracker errs=new ch.ehi.basics.logging.ErrorTracker();
EhiLogger.getInstance().addListener(errs);
transferToXtf(conn,xtffile,mapping,td,geomConverter,config.getSender(),config,basketSqlIds,stat,trafoConfig);
transferToXtf(conn,xtffile,mapping,td,geomConverter,config.getSender(),config,basketSqlIds,stat,trafoConfig,class2wrapper);
if (errs.hasSeenErrors()) {
throw new Ili2dbException("...export failed");
} else {
@@ -1541,9 +1559,9 @@ static private void transferFromXtf(Connection conn,IoxReader reader,boolean imp
DbIdGen idGen,
Config config,
HashSet<BasketStat> stat,
TrafoConfig trafoConfig){
TrafoConfig trafoConfig,Viewable2TableMapping class2wrapper){
try{
TransferFromXtf trsfr=new TransferFromXtf(importOnly,ili2sqlName,td,conn,dbusr,geomConv,idGen,config,trafoConfig);
TransferFromXtf trsfr=new TransferFromXtf(importOnly,ili2sqlName,td,conn,dbusr,geomConv,idGen,config,trafoConfig,class2wrapper);
trsfr.doit(reader,config,stat);
}catch(ch.interlis.iox.IoxException ex){
EhiLogger.logError("failed to read data file",ex);
@@ -1559,7 +1577,8 @@ static private void transferToXtf(Connection conn,String xtffile,NameMapping ili
,Config config
,int basketSqlIds[]
,HashSet<BasketStat> stat
,TrafoConfig trafoConfig){
,TrafoConfig trafoConfig
,Viewable2TableMapping class2wrapper){

java.io.File outfile=new java.io.File(xtffile);
IoxWriter ioxWriter=null;
@@ -1576,7 +1595,7 @@ static private void transferToXtf(Connection conn,String xtffile,NameMapping ili
}else{
ioxWriter=new XtfWriter(outfile,td);
}
TransferToXtf trsfr=new TransferToXtf(ili2sqlName,td,conn,geomConv,config,trafoConfig);
TransferToXtf trsfr=new TransferToXtf(ili2sqlName,td,conn,geomConv,config,trafoConfig,class2wrapper);
trsfr.doit(outfile.getName(),ioxWriter,sender,basketSqlIds,stat);
//trsfr.doitJava();
ioxWriter.flush();
@@ -1593,7 +1612,7 @@ static private void transferToXtf(Connection conn,String xtffile,NameMapping ili
ioxWriter=null;
}
}
static public void optimizeSqlNames(Config config,NameMapping mapping,java.util.List<Element> eles)
static public void optimizeSqlTableNames(Config config,NameMapping mapping,java.util.List<Element> eles)
{
if(config.NAME_OPTIMIZATION_DISABLE.equals(config.getNameOptimization())){
return;
@@ -146,8 +146,8 @@ public DbColId addKeyCol(DbTable table) {
table.addColumn(dbColId);
return dbColId;
}
public void addIliTidCol(DbTable dbTable,Viewable aclass) {
if(isUuidOid(td,aclass)){
public void addIliTidCol(DbTable dbTable,Domain oidDomain) {
if(isUuidOid(td,oidDomain)){
DbColUuid dbColIliTid= new DbColUuid();
dbColIliTid.setName(DbNames.T_ILI_TID_COL);
// CREATE EXTENSION "uuid-ossp";
@@ -171,15 +171,17 @@ public DbTableName getSqlTableName(Viewable def){
String sqlname=ili2sqlName.mapIliClassDef(def);
return new DbTableName(schemaName,sqlname);
}
public static boolean isUuidOid(TransferDescription td,Viewable aclass) {
if(aclass instanceof AbstractClassDef){
Domain oid=((AbstractClassDef<AbstractLeafElement>) aclass).getOid();
public static boolean isUuidOid(TransferDescription td,Domain oid) {
if(oid!=null){
if(oid==td.INTERLIS.UUIDOID){
return true;
}
}
return false;
}
public static boolean isUuidOid(TransferDescription td,Viewable aclass) {
throw new IllegalArgumentException("to be removed");
}
public static void addStdCol(DbTable table) {
DbColumn dbCol=new DbColDateTime();
dbCol.setName(DbNames.T_LAST_CHANGE_COL);
Oops, something went wrong.

0 comments on commit 2cb22eb

Please sign in to comment.