001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.example;
028:
029: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
030: import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
031: import fr.ign.cogit.geoxygene.feature.FT_FeatureCollection;
032: import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_Aggregate;
033: import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
034:
035: /**
036: * Federation de donnees.
037: * Exemple d'utilisation de plusieurs "Geodatabase" simultanees.
038: *
039: * Remarque : l'utilisation de plusieurs transactions simultanees plante,
040: * a etudier.
041: *
042: * @author Thierry Badard & Arnaud Braun
043: * @version 1.1
044: *
045: */
046:
047: public class TestFederation {
048:
049: public static void main(String args[]) {
050:
051: Geodatabase db1, db2, db3;
052: Class featureClass1 = null;
053: Class featureClass2 = null;
054: long t1, t2;
055:
056: System.out.println("coucou");
057:
058: db1 = GeodatabaseOjbFactory.newInstance();
059: db2 = GeodatabaseOjbFactory.newInstance("ORACLE_ALIAS_NCDB");
060: db3 = GeodatabaseOjbFactory.newInstance("POSTGRES_ALIAS");
061:
062: System.out.println(db1);
063: System.out.println(db2);
064: System.out.println(db3);
065:
066: try {
067: featureClass1 = Class
068: .forName("geoxygene.geodata.Troncon_voie_ferree");
069: featureClass2 = Class
070: .forName("geoxygene.geodata.Troncon_voie_ferree_50");
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074:
075: System.out.println("nombre d'objets : "
076: + db1.countObjects(featureClass1));
077: System.out.println("nombre d'objets : "
078: + db2.countObjects(featureClass2));
079:
080: System.out.print("chargement ... " + featureClass1.getName()
081: + " ");
082: t1 = System.currentTimeMillis();
083: FT_FeatureCollection coll1 = db1.loadAllFeatures(featureClass1);
084: t2 = System.currentTimeMillis();
085: System.out.println((t2 - t1) / 1000.);
086:
087: System.out.print("chargement ... " + featureClass2.getName()
088: + " ");
089: t1 = System.currentTimeMillis();
090: FT_FeatureCollection coll2 = db2.loadAllFeatures(featureClass2);
091: t2 = System.currentTimeMillis();
092: System.out.println((t2 - t1) / 1000.);
093:
094: System.out.println("Calcul buffer 1 ...");
095: int i = 0;
096: GM_Aggregate aggr = new GM_Aggregate();
097: coll1.initIterator();
098: while (coll1.hasNext()) {
099: i++;
100: GM_Object geom = coll1.next().getGeom();
101: geom = geom.buffer(100.);
102: aggr.add(geom);
103: if (i > 1000)
104: break;
105: }
106:
107: System.out.println("Calcul buffer 2 ...");
108: i = 0;
109: coll2.initIterator();
110: while (coll2.hasNext()) {
111: i++;
112: GM_Object geom = coll2.next().getGeom();
113: geom = geom.buffer(50.);
114: aggr.add(geom);
115: if (i > 1000)
116: break;
117: }
118:
119: db3.begin();
120: System.out.println("begin db3");
121:
122: System.out.print("ecriture ... ");
123: t1 = System.currentTimeMillis();
124: aggr.initIterator();
125: while (aggr.hasNext()) {
126: Resultat res = new Resultat();
127: db3.makePersistent(res);
128: res.setGeom(aggr.next());
129: }
130: t2 = System.currentTimeMillis();
131: System.out.println((t2 - t1) / 1000.);
132:
133: System.out.print("commit db3... ");
134: t1 = System.currentTimeMillis();
135: db3.commit();
136: t2 = System.currentTimeMillis();
137: System.out.println((t2 - t1) / 1000.);
138: System.out.println("OK");
139:
140: }
141:
142: }
|