GeodataServer object


In this topic


Geodatabase objects and interfaces

The geodatabase query and management objects are located in the com.esri.arcgis.geodatabase and com.esri.arcgis.geodatabasedistributed packages in the arcobjects.jar. The GeodataServer object is in the geodatabasedistributed package; however, in your application, you'll typically work with objects from these packages and objects from a number of other packages.
GeodataServer is a server object served by an ArcGIS Server that can be used to discover the datasets, versions, and replicas in a geodatabase and to query, extract, and replicate data between geodatabases. Internally, GeodataServer is a connection to a geodatabase and exposes the high-level functionality of the geodatabase using the IGeoDataServer interface. All the coarse-grained functionality of GeodataServer can be accessed through the IGeodataServer interface. The following sample code shows how to get a reference to a geodata server called brazil.
[Java]
IServerObjectManager som = con.getServerObjectManager();
IServerContext ctx = som.createServerContext("brazil", "GeoDataServer");
IGeoDataServer gs = (IGeoDataServer)ctx.getServerObject();
The GeodataServer object implements the IGeodataServerObjects interface. This interface can be used by applications accessing a geodata server over a Distributed Component Object Model (DCOM) to get a reference to its geodatabase connection as a workspace object. Using this workspace object, applications can make fine-grained ArcObjects calls against the workspace. This also allows the geodata server to be used to pool and serve geodatabase connections. The following sample code shows how GeodataServer can be used to get a reference to the workspace and compress it.
[Java]
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();
IVersionedWorkspace ws = new IVersionedWorkspaceProxy(gs.getDefaultWorkingWorkspace()
    );
ws.compress();
GeodataServer can be used in either a stateless (pooled) or stateful (non-pooled) manner. When used in a pooled manner, the current database state of the working version is automatically refreshed by ArcGIS Server each time an instance of GeodataServer in the pool is handed out to an application through a call to createServerContext. When used in a non-pooled manner, the application is responsible for refreshing the database state associated with the working version as needed. The following sample code shows how to get a reference to the geodata server's workspace and refresh its version.
[Java]
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();
IVersion ws = new IVersionProxy(gs.getDefaultWorkingWorkspace());
ws.refreshVersion();
Server applications can run geoprocessing tools in ServerContext holding a GeodataServer object and use the GeodataServer object to get input data elements from the workspace.

GeodataServer functions 

GeodataServer functions that are accessible by the IGeodataServer interface are summarized here.

Listing datasets

The getDataElements method returns information about the data elements for all datasets in the workspace. DataElements are lightweight objects that describe datasets that can be used in geoprocessing functions. Examples of such classes are DEFolder, DETable, and DEShapeFile. These objects are simple structures whose properties describe the actual dataset. For example, DEShapeFile has properties such as Extent and SpatialReference. A subset of the data elements describes geodatabase datasets. The classes DEFeatureClass, DEFeatureDataset, and others can be used to describe actual geodatabase datasets.
Every DataElement supports the IGPValue interface; this allows DataElements to be used directly as inputs to both the Validate and Execute methods of the function.
Applications can request full or partial information (name and type only). Information on the set of DataElements in the workspace is cached by GeodataServer on start up. Administrators can control the frequency with which this information is refreshed. The CatalogPath for a data element in GeodataServer is based on the concatenation of the CatalogPath of GeodataServer with the path of the dataset within the database. DataElements retrieved from GeodataServer can be used as arguments to geoprocessing tools running in the same Server Context as GeodataServer.
The following sample code shows how to get all the data elements for a geodata server and print their names and types.
[Java]
IServerContext ctx = som.createServerContext("brazil", "GeoDataServer");
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();

IDEBrowseOptions deb = (IDEBrowseOptions)ctx.createObject(DEBrowseOptions.getClsid())
    ;
deb.setExpandType(esriDEExpandType.esriDEExpandChildren);
deb.setRetrieveFullProperties(true);
deb.setRetrieveMetadata(false);
IDataElements des = gs.getDataElements(deb);
IDataElement de = null;
for (int i = 0; i < des.getCount(); i++){
    de = des.getElement(i);
    System.out.println(de.getName() + " (" + de.getType() + ")");
}

Listing versions

The getVersions method returns information about the versions in the geodatabase. This method returns an array of GPVersionInfos. Each GPVersionInfo object includes its name, its parent version name, its ancestor and child versions' names, dates when it was created and last modified, and its access permissions.
The following sample code shows how to get all the versions for a geodata server and print their names.
[Java]
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();
IGPVersionInfos vinfos = gs.getVersions();
IGPVersionInfo info = null;
for (int i = 0; i < vinfos.getCount(); i++){
    info = vinfos.getElement(i);
    System.out.println(info.getVersionName());
}

Listing replicas

The getReplicas method returns information about the replicas in a geodatabase. This method returns an array of GPReplicas objects. A GPReplica object includes information such as the replicated datasets, the date it was created, information about when it was last synchronized, and information about the sibling geodatabase.
The following sample code shows how to get all the replicas for a geodata server and print their names.
[Java]
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();
IGPReplicas reps = gs.getReplicas();
IGPReplica rep = null;
for (int i = 0; i < reps.getCount(); i++){
    rep = reps.getElement(i);
    System.out.println(rep.getName());
}

Querying data

Applications can use the tableSearch method to query tables and feature classes that are being served as shown in the following sample code. Both attribute and spatial queries can be performed. The results of a query are returned in user specified chunks. Applications can control the size of the chunk. The results for each chunk are returned as a record set containing chunk size records. Only datasets that are accessible by the database user associated with the geodata server's connection can be queried.
[Java]
GeoDataServer gs = (GeoDataServer)ctx.getServerObject();

IQueryFilter qf = (IQueryFilter)ctx.createObject(QueryFilter.getClsid());
qf.setWhereClause("States.AREA > 10000");
ResultPortionInfo rpi = (ResultPortionInfo)ctx.createObject
    (ResultPortionInfo.getClsid());
rpi.setCount(100);
rpi.setStartIndex(0);
IGDSQueryResultPortion resPortion = gs.tableSearch(gs.getDefaultWorkingVersion(), 
    "States", qf, rpi);
IRecordSet recs = resPortion.getRecords();
ICursor cursor = recs.getCursor(true);
IRow row;

while ((row = cursor.nextRow()) != null){
    // Do something with the row.
}

Importing and uploading data

The importData method can be used to upload data to the geodata server as shown in the following sample code. An application can perform local data extraction to Extensible Markup Language (XML), then upload the resulting document to the server. All data element types are supported. The result of the import is that new datasets are created. The datasets created are owned by the database user associated with the geodata server.
[Java]
// Workspace XML file...
String sInputFile = sFilename;

//Embed the GDSData object.
GDSData pGDSdata = (GDSData)gdbCtx.createObject(GDSData.getClsid());
pGDSdata.setTransportType(esriGDSTransportType.esriGDSTransportTypeUrl);
pGDSdata.setCompressed(true);
pGDSdata.setURL(sInputFile);
// Import the replica workspace document to create the replica.
pGDSchild.importData(pGDSdata, esriGDSImportFormat.esriGDSImportFormatXmlWorkspace);

Extracting and downloading data

The extractData method can be used to extract and download a spatial subset of data from a specified set of datasets. The data to be extracted is specified by a GPReplica object. Both vector and raster data can be extracted. A separate attribute query can be applied to each table or feature class. Related records can be fetched as part of the extract. Only datasets that are accessible by the database user associated with the geodata server's connection can be extracted.

Creating replicas

The createReplica method can be used to create and download a child replica containing a spatial subset of data from a specified set of datasets on GeodataServer. The data to be extracted is specified by a GPReplica object. A separate attribute query can be applied to each table or feature class. Related records can be fetched. The createReplica method can be used to create CheckOut, OneWay, or TwoWay replicas. Only datasets that are accessible by the database user associated with the geodata server can be replicated.
The following sample code shows how to use GeodataServer and a MapServer context together to create a single-generation replica of all the layers in the map in a geodatabase.
[Java]
GPReplicaDescription gpRepDesc = (GPReplicaDescription)gdbCtx.createObject
    (GPReplicaDescription.getClsid());
gpRepDesc.setModelType(esriReplicaModelType.esriModelTypeFullGeodatabase);
gpRepDesc.setSingleGeneration(true);
gpRepDesc.setTransferRelatedObjects(true);
mapCtx = som.createServerContext("usa_gdb", "MapServer");
MapServer ms = (MapServer)mapCtx.getServerObject();

IMapDescription mapDesc = ms.getServerInfo(ms.getDefaultMapName())
    .getDefaultMapDescription();
gpRepDesc.setQueryGeometryByRef((IGeometry)mapDesc.getMapArea().getExtent());
gpRepDesc.setSpatialRelation(esriSpatialRelEnum.esriSpatialRelIntersects);
GPReplicaDatasets resds = (GPReplicaDatasets)gdbCtx.createObject
    (GPReplicaDatasets.getClsid());
IMap map = ms.getMap(ms.getDefaultMapName());
UID ltype = (UID)mapCtx.createObject(UID.getClsid());
ltype.setValue("{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}");
IEnumLayer el = map.getLayers(ltype, true);
el.reset();
ILayer l = null;
IFeatureLayer fl = null;
IDataset ds = null;
while ((l = el.next()) != null){
    if (l instanceof IFeatureLayer){
        fl = (IFeatureLayer)l;
        GPReplicaDataset rd = (GPReplicaDataset)gdbCtx.createObject
            (GPReplicaDataset.getClsid());
        ds = new IDatasetProxy(fl.getFeatureClass());
        rd.setName(ds.getName());
        rd.setDatasetType(esriDatasetType.esriDTFeatureClass);
        rd.setRowsType(esriRowsType.esriRowsTypeFilter);
        rd.setUseGeometry(true);
        resds.add(rd);
    }
}

gpRepDesc.setReplicaDatasetsByRef(resds);
// Options...
IGDSExportOptions exo = (GDSExportOptions)gdbCtx.createObject
    (GDSExportOptions.getClsid());
exo.setExportFormat(esriGDSExportFormat.esriGDSExportFormatPersonalGdb);
IGDSData gsdata = gs.createReplica(gs.getDefaultWorkingVersion(), "MyReplica",
    gpRepDesc, null, exo, esriGDSTransportType.esriGDSTransportTypeUrl);

Synchronizing replicas 

The exportReplicaDataChanges, importReplicaDataChanges, and exportAcknowledgement methods can be used to synchronize replicas. The process of synchronizing two replicas, each of which is managed by a geodata server, involves exporting changes from one replica and importing changes into the other replica. The Replica Synchronization tools in ArcGIS Desktop can be used to perform these operations. Only replicas that are owned by the database user associated with the geodata server can be synchronized.
These methods make it possible to synchronize replicas over standard Web services and allow you to create applications that synchronize replicas on a regularly scheduled basis.
The following sample code shows how to use GeodataServer to check in replica changes that have been exported to a delta XML document.
[Java]
String sInputFile = sInputDirectory + File.separator + sFilename;
File fi = new File(sInputFile);
int len = (int)fi.length();
byte[] bytes = new byte[len];
FileInputStream f = new FileInputStream(fi);
f.read(bytes, 0, len);
f.close();
//Embed the GDSData object.
IGDSData pGDSdata = new GDSData();
pGDSdata.setTransportType(esriGDSTransportType.esriGDSTransportTypeEmbedded);
pGDSdata.setCompressed(true);
pGDSdata.setEmbeddedData(bytes);
// Import the replica workspace document to create the replica.
sGDStarget.importReplicaDataChanges
    (esriGDSReplicaImportSource.esriGDSReplicaImportSourceDeltaXmlFile,
    esriReplicaReconcilePolicyType.esriReplicaDetectConflicts, true, pGDSdata);


See Also:

Geodata management