ArcGIS Engine+分布式数据库操作

简介: 我们知道Geodatabase的分布式数据库可以在线也可以离线,而在线和离线的接口是不同的,这是因为两者的操作过程不一样,我们看一下两者的区别:                                                                             ...

我们知道Geodatabase的分布式数据库可以在线也可以离线,而在线和离线的接口是不同的,这是因为两者的操作过程不一样,我们看一下两者的区别:
                  

                                
          
                                        在线

 



                                                                                                                      离线




通过这4张图很清楚的说明了原理(其中每一种方式又分为局域网和互联网)

重要的接口:

GeoDataServer  代表了一个数据库的连接,这句话可能不好理解,但是通过代码,也许会明白:

public IGeoDataServer InitGeoDataServerFromFile(String path)

{

    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.

    IGeoDataServer geoDataServer = new GeoDataServerClass();

    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;

    geoDataServerInit.InitFromFile(@"C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb");

    return geoDataServer;

}

在离线方式下,我们的数据同步是通过导入,导出,而导入,导出这些方法由此接口提供,看下面的例子:

public void ExportReplicaDataChanges(IGeoDataServer sourceGDS, String replicaName,

    String outputDirectory)

{

    try

    {

        // Set the export options.

        GDSExportOptions gdsExportOptions = new GDSExportOptions();

        gdsExportOptions.ExportFormat = esriGDSExportFormat.esriGDSExportFormatXml;

        gdsExportOptions.Compressed = true;

        gdsExportOptions.BinaryGeometry = false;



        // Export the data changes. Note: The replica must be in a Sending Data State.

        IGDSData gdsData = sourceGDS.ExportReplicaDataChanges(replicaName,

            gdsExportOptions, esriGDSTransportType.esriGDSTransportTypeUrl,

            esriExportGenerationsOption.esriExportGenerationsAll, false);



        // Force deletion of folder and contents if they exist.

        if (Directory.Exists(outputDirectory))

        {

            Directory.Delete(outputDirectory, true);

        }



        // Create the output folder.

        Directory.CreateDirectory(outputDirectory);



        // Get the compressed data changes document from the URL to the local output directory.

        if (gdsData.TransportType == esriGDSTransportType.esriGDSTransportTypeUrl)

        {

            string fileName = System.IO.Path.GetFileName(gdsData.URL);

            string outputFileName = System.IO.Path.Combine(outputDirectory, fileName)

                ;

            WebClient wc = new WebClient();

            wc.DownloadFile(gdsData.URL, outputFileName);

            wc.Dispose();

        }

        else

        {

            // The file has been embedded because there is no output directory set on ArcGIS Server.

            Console.WriteLine("Server is not configured with a virtual directory.");

        }

    }

    catch (COMException comExc)

    {

        throw new Exception(String.Format(

            "Exporting data changes errored: {0}, Error Code: {1}", comExc.Message,

            comExc.ErrorCode), comExc);

    }

    catch (Exception exc)

    {

        throw new Exception(String.Format("Exporting data changes errored: {0}",

            exc.Message), exc);

    }

}

而在在线方式下,用ReplicatonAgent接口

ReplicatonAgent 接口就是用来实现在线方式下的同步

public void SynchronizeReplica(IGeoDataServer parentGDS, IGeoDataServer childGDS,

    String replicaName, esriReplicationAgentReconcilePolicy conflictPolicy,

    esriReplicaSynchronizeDirection syncDirection, Boolean columnLevel)

{

    try

    {

        // Iterate through the replicas of the parent geodata server.

        IGPReplicas gpReplicas = parentGDS.Replicas;

        IGPReplica parentReplica = null;

        for (int i = 0; i < gpReplicas.Count; i++)

        {

            // See if the unqualified replica name matches the replicaName parameter.

            IGPReplica currentReplica = gpReplicas.get_Element(i);

            String currentReplicaName = currentReplica.Name;

            int dotIndex = currentReplicaName.LastIndexOf(".") + 1;

            String baseName = currentReplicaName.Substring(dotIndex,

                currentReplicaName.Length - dotIndex);

            if (baseName.ToLower() == replicaName.ToLower())

            {

                parentReplica = currentReplica;

                break;

            }

        }



        // Check to see if the parent replica was found.

        if (parentReplica == null)

        {

            throw new ArgumentException(

                "The requested replica could not be found on the parent GDS.");

        }



        // Iterate through the replica of the child geodata server.

        gpReplicas = childGDS.Replicas;

        IGPReplica childReplica = null;

        for (int i = 0; i < gpReplicas.Count; i++)

        {

            // See if the unqualified replica name matches the replicaName parameter.

            IGPReplica currentReplica = gpReplicas.get_Element(i);

            String currentReplicaName = currentReplica.Name;

            int dotIndex = currentReplicaName.LastIndexOf(".") + 1;

            String baseName = currentReplicaName.Substring(dotIndex,

                currentReplicaName.Length - dotIndex);

            if (baseName.ToLower() == replicaName.ToLower())

            {

                childReplica = currentReplica;

                break;

            }

        }



        // Check to see if the child replica was found.

        if (childReplica == null)

        {

            throw new ArgumentException(

                "The requested replica could not be found on the child GDS.");

        }



        // Synchronize the replica.

        IReplicationAgent replicationAgent = new ReplicationAgentClass();

        replicationAgent.SynchronizeReplica(parentGDS, childGDS, parentReplica,

            childReplica, conflictPolicy, syncDirection, columnLevel);

    }

    catch (COMException comExc)

    {

        throw new Exception(String.Format(

            "Create replica errored: {0}, Error Code: {1}", comExc.Message,

            comExc.ErrorCode), comExc);

    }

    catch (Exception exc)

    {

        throw new Exception(String.Format("Create replica errored: {0}", exc.Message)

            , exc);

    }

相关文章
|
SQL 关系型数据库 MySQL
乐观锁在分布式数据库中如何与事务隔离级别结合使用
乐观锁在分布式数据库中如何与事务隔离级别结合使用
221 5
|
7月前
|
存储 监控 分布式数据库
ClickHouse分布式数据库动态伸缩(弹性扩缩容)的实现
实现ClickHouse数据库的动态伸缩需要持续的维护和精细的操作。从集群配置到数据迁移,再到监控和自动化,每一步都要仔细管理以确保服务的可靠性和性能。这些活动可以显著提高应用的响应性和成本效率,帮助业务根据实际需求灵活调整资源分配。
418 10
|
8月前
|
存储 关系型数据库 分布式数据库
【赵渝强老师】基于PostgreSQL的分布式数据库:Citus
Citus 是基于 PostgreSQL 的开源分布式数据库,采用 shared nothing 架构,具备良好的扩展性。它以插件形式集成,部署简单,适用于处理大规模数据和高并发场景。本文介绍了 Citus 的基础概念、安装配置步骤及其在单机环境下的集群搭建方法。
715 2
|
SQL 关系型数据库 MySQL
乐观锁在分布式数据库中如何与事务隔离级别结合使用
乐观锁在分布式数据库中如何与事务隔离级别结合使用
|
10月前
|
SQL 存储 分布式数据库
分布式存储数据恢复—hbase和hive数据库数据恢复案例
分布式存储数据恢复环境: 16台某品牌R730xd服务器节点,每台服务器节点上有数台虚拟机。 虚拟机上部署Hbase和Hive数据库。 分布式存储故障: 数据库底层文件被误删除,数据库不能使用。要求恢复hbase和hive数据库。
344 12
|
存储 SQL 分布式数据库
OceanBase 入门:分布式数据库的基础概念
【8月更文第31天】在当今的大数据时代,随着业务规模的不断扩大,传统的单机数据库已经难以满足高并发、大数据量的应用需求。分布式数据库应运而生,成为解决这一问题的有效方案之一。本文将介绍一款由阿里巴巴集团自主研发的分布式数据库——OceanBase,并通过一些基础概念和实际代码示例来帮助读者理解其工作原理。
1298 0
|
12月前
|
SQL 运维 关系型数据库
体验用分布式数据库突破资源瓶颈,完成任务领智能台灯!
体验用分布式数据库突破资源瓶颈,完成任务领智能台灯!
|
12月前
|
SQL 数据建模 BI
【YashanDB 知识库】用 yasldr 配置 Bulkload 模式作单线程迁移 300G 的业务数据到分布式数据库,迁移任务频繁出错
问题描述 详细版本:YashanDB Server Enterprise Edition Release 23.2.4.100 x86_64 6db1237 影响范围: 离线数据迁移场景,影响业务数据入库。 外场将部分 NewCIS 的报表业务放到分布式数据库,验证 SQL 性能水平。 操作系统环境配置: 125G 内存 32C CPU 2T 的 HDD 磁盘 问题出现的步骤/操作: 1、部署崖山分布式数据库 1mm 1cn 3dn 单线启动 yasldr 数据迁移任务,设置 32 线程的 bulk load 模式 2、观察 yasldr.log 是否出现如下错
|
容灾 关系型数据库 分布式数据库
PolarDB分布式版:与云融合的分布式数据库发展新阶段
PolarDB分布式版标志着分布式数据库与云融合的新阶段。它经历了三个发展阶段:从简单的分布式中间件,到一体化分布式架构,再到云原生分布式数据库。PolarDB充分利用云资源的弹性、高性价比、高可用性和隔离能力,解决了大规模数据扩展性问题,并支持多租户场景和复杂事务处理。零售中台的建设背景包括国家数字化转型战略及解决信息孤岛问题,采用分布式数据库提升高可用性和性能,满足海量订单处理需求。展望未来,零售中台将重点提升容灾能力、优化资源利用并引入AI技术,以实现更智能的服务和更高的业务连续性。
412 9

热门文章

最新文章