2011-04-04 50 views
1

我有一個類,位置。位置包含一個BorderPoint對象列表,但它可以是一個巨大的列表(20,000不是不可能的)。這個表是LOCATION和BORDERPOINT。自動交易在OpenJPA

我最初通過從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(); 
     } 

由於在該列表中,使許多BorderPoint對象,但我只是通過調用持久化Location對象上保存它們,我可以自動設置某種批量大小爲持續的BorderPoints ?

回答

2

我不知道OpenJPA,但我已經使用了很多Hibernate。您可能必須自己控制事務大小。如果稍微更改代碼,應該很容易:

  1. 創建並保留位置。你應該也可以提交數據庫事務。
  2. 將BorderPoints保存到數據庫中,確保已設置其父位置。這意味着父位置映射在BorderPoint上。你可能想要提交每100個邊界點左右。
  3. 從數據庫查詢位置並訪問其邊界點。所有持久的邊界點應該在那裏。
+0

這就是我害怕的答案,但我抱着希望。我在Hibernate自己有點經驗,看起來比JPA更可配置,特別是在Spring下。 – Jason 2011-04-05 00:49:46

1

如果您使用JTA,您可能必須自行將批量導入批處理。但是,您可能想要檢查是否真的必須將每個點存儲爲一行。

我的同事們試圖用很多分數來保存圖表,在表現糟糕之後,他們分析了使用情況,並意識到他們總是裝載所有分數。因此,他們最終將所有點連成一團,並且性能提升非常巨大。