1

我有一门课,位置。Location 包含一个 BorderPoint 对象列表,但它可以是一个巨大的列表(20,000 个并非不可能)。用于此的表是 LOCATION 和 BORDERPOINT。

我最初通过从 ESRI Shapefile 导入来填充位置。这是一个代码片段:

        try {
            while (featureIterator.hasNext()) {
                Location location = new Location();

                SimpleFeatureImpl feature = (SimpleFeatureImpl) featureIterator.next();

                // set the information in location based on stuff in the feature, lets me clean up this
                // method a bit
                setLocationInfo(location, feature);

                List<BorderPoint> borderPointList = getBorderPoints(feature, location);
                //saveBorderPoints(location, feature);
                location.setBorderPointList(borderPointList);

                try {
                    locationRepository.persist(location);
                } catch (RepositoryException e) {
                    throw new ServiceException("processShapefile() threw RepositoryException", e);
                }
            }
        } finally {
            featureIterator.close();
        }

由于 List 中有这么多 BorderPoint 对象,但我只是通过在 Location 对象上调用 persist 来保存它们,我可以自动设置某种批处理大小来持久保存 BorderPoints 吗?

4

2 回答 2

2

我不知道 OpenJPA,但我用过很多 Hibernate。您可能必须自己控制交易规模。如果您稍微更改代码,这应该很容易:

  1. 创建并保留位置。您可能还应该提交数据库事务。
  2. 将 BorderPoints 持久保存到数据库中,确保您已设置其父位置。这意味着父位置映射到 BorderPoint。您可能希望每 100 个 BorderPoints 左右提交一次。
  3. 从数据库中查询位置并访问其边界点。所有持久的边界点都应该在那里。
于 2011-04-04T19:09:35.640 回答
1

如果您使用 JTA,您可能必须自己将导入分成批次。但是,您可能想检查是否真的必须将每个点存储为一行。

我的同事试图保存一个包含很多点的图表,在表现不佳后,他们分析了使用情况并意识到他们总是加载所有点。因此,他们最终将所有点序列化为一个 blob,性能提升巨大。

于 2011-04-04T19:08:51.550 回答