Changeset 3664
- Timestamp:
- Aug 14, 2007, 2:50:43 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/migrate/net/sf/basedb/clients/migrate/ReporterProxy.java
r2614 r3664 43 43 private final int id; 44 44 45 ReporterProxy(int id) 46 { 47 this.id = id; 48 } 49 45 50 ReporterProxy(ReporterData reporter) 46 51 { -
trunk/src/clients/migrate/net/sf/basedb/clients/migrate/ReporterTransfer.java
r3663 r3664 26 26 27 27 import net.sf.basedb.core.BaseException; 28 import net.sf.basedb.core.DataQuery; 29 import net.sf.basedb.core.DataResultIterator; 28 import net.sf.basedb.core.DatabaseException; 30 29 import net.sf.basedb.core.DbControl; 30 import net.sf.basedb.core.DynamicReporterQuery; 31 import net.sf.basedb.core.DynamicResultIterator; 31 32 import net.sf.basedb.core.Reporter; 32 33 import net.sf.basedb.core.ReporterBatcher; 33 34 import net.sf.basedb.core.data.ReporterData; 34 import net.sf.basedb.core.query. Hql;35 import net.sf.basedb.core.query.Dynamic; 35 36 import net.sf.basedb.core.query.Orders; 37 import net.sf.basedb.core.query.SqlResult; 36 38 import net.sf.basedb.util.timer.PerformanceTimer; 37 39 … … 46 48 BASE 2. 47 49 48 @author Gregory, Martin 50 @author Gregory, Martin, Nicklas 49 51 @version 2.0 50 52 @base.modified $Date$ 51 53 */ 52 54 53 public class ReporterTransfer extends Transfer 55 public class ReporterTransfer 56 extends Transfer 54 57 { 55 58 … … 140 143 int batchSize = getBatchSize(); 141 144 142 DataQuery<ReporterData> query = Reporter.getQuery(); 143 query.order(Orders.asc(Hql.property("id"))); 145 DynamicReporterQuery query = Reporter.getDynamicQuery(); 146 query.select(Dynamic.selectReporter("id")); 147 query.select(Dynamic.selectReporter("externalId")); 148 query.order(Orders.asc(Dynamic.reporter("id"))); 144 149 query.setMaxResults(batchSize); 145 150 while (start < count) … … 214 219 } 215 220 216 private void mapMigratedReporters(DbControl dc, DataQuery<ReporterData> query) 217 { 218 DataResultIterator<ReporterData> result = null; 221 private void mapMigratedReporters(DbControl dc, DynamicReporterQuery query) 222 { 223 // DataResultIterator<ReporterData> result = null; 224 DynamicResultIterator result = null; 219 225 PerformanceTimer timer = new PerformanceTimer( 220 226 "iterate()", "hasNext()", "next()", "HashMap.get()", "HashMap.put()", "other"); … … 227 233 { 228 234 timer.stopStart(1, 2); 229 ReporterData reporter = result.next(); 235 SqlResult reporter = result.next(); 236 String externalId = reporter.getString(2); 230 237 timer.stopStart(2, 3); 231 Integer base1Id = externalIdMap.get( reporter.getExternalId());238 Integer base1Id = externalIdMap.get(externalId); 232 239 timer.stopStart(3, 4); 233 reporterMap.put(base1Id, new ReporterProxy(reporter ));240 reporterMap.put(base1Id, new ReporterProxy(reporter.getInt(1))); 234 241 timer.stopStart(4, 5); 235 242 progress.increase(); 236 243 if (log.isDebugEnabled()) 237 244 { 238 log.debug("Reporter: " + reporter.getExternalId()+245 log.debug("Reporter: " + externalId + 239 246 " has been mapped to BASE 1 ID="+base1Id); 240 247 } … … 246 253 log.info("\n"+timer.toString()); 247 254 } 255 } 256 catch (SQLException ex) 257 { 258 throw new DatabaseException(ex); 248 259 } 249 260 finally -
trunk/src/core/net/sf/basedb/core/AbstractEntityQuery.java
r2722 r3664 389 389 390 390 /** 391 If queries are using the stateless Hibernate session or the regular 392 session. 393 @return TRUE if the stateless session is used, FALSE otherwise 394 @since 2.4 395 */ 396 protected boolean isStateless() 397 { 398 return stateless; 399 } 400 401 /** 391 402 Enable runtime query filters for the query. 392 403 @see #disableFilters(DbControl) -
trunk/src/core/net/sf/basedb/core/DataQuery.java
r2474 r3664 90 90 ScrollIterator<I> result = HibernateUtil.loadIterator(dataClass, getMainHqlQuery(dc)); 91 91 disableFilters(dc); 92 return new DataResultIterator<I>(result, dc, dataClass, totalCount); 92 return new DataResultIterator<I>(result, dc.getSessionControl(), 93 isStateless() ? null : dc.getHibernateSession(), dataClass, totalCount); 93 94 } 94 95 96 95 97 96 } -
trunk/src/core/net/sf/basedb/core/DataResultIterator.java
r2474 r3664 31 31 of iterator is only used for batchable items like reporter and raw data. 32 32 It is expected that the query uses the stateless Hibernate session available 33 from {@link DbControl#getStatelessSession()}. If 34 The returned objects are automatically disconnected from the Hibernate session33 from {@link DbControl#getStatelessSession()}. If not, 34 the returned objects are automatically disconnected from the Hibernate session 35 35 to avoid memory problems and bypassing permission checks. 36 36 … … 49 49 50 50 /** 51 The DbControl that was used in the query, if it used the regular52 Hibernate session, null otherwise.51 The Hibernate Session that was used in the query, null if a stateless 52 session is used. 53 53 */ 54 private final DbControl dc;54 private final org.hibernate.Session session; 55 55 56 /** 57 The SessionControl 58 */ 56 59 private final SessionControl sc; 57 60 … … 71 74 private final Item itemType; 72 75 73 DataResultIterator(ScrollIterator<I> data, DbControl dc, Class<I> dataClass, long totalCount) 76 DataResultIterator(ScrollIterator<I> data, SessionControl sc, org.hibernate.Session session, 77 Class<I> dataClass, long totalCount) 74 78 { 75 79 assert data != null : "data == null"; 76 80 this.data = data; 77 this. dc = dc;78 this.s c = dc.getSessionControl();81 this.sc = sc; 82 this.session = session; 79 83 this.dataClass = dataClass; 80 84 this.itemType = Item.fromDataClass(dataClass); … … 116 120 sc.updateLastAccess(); 117 121 I dataObject = data.next(); 118 if ( dc!= null)122 if (session != null) 119 123 { 120 HibernateUtil.evictData( dc.getHibernateSession(), dataObject);124 HibernateUtil.evictData(session, dataObject); 121 125 } 122 126 return dataObject; -
trunk/src/core/net/sf/basedb/core/Reporter.java
r3471 r3664 129 129 130 130 /** 131 Get a dynamic query object configured to retrieve reporter information. 132 You must add columns/expressions to select with 133 {@link net.sf.basedb.core.query.Query#select(net.sf.basedb.core.query.Select)} 134 @return A {@link DynamicReporterQuery} object 135 @since 2.4 136 */ 137 public static DynamicReporterQuery getDynamicQuery() 138 { 139 return new DynamicReporterQuery(); 140 } 141 142 /** 131 143 Get the reporter type item from a reporter data object. 132 144
Note: See TracChangeset
for help on using the changeset viewer.