Changeset 7947
- Timestamp:
- May 7, 2021, 1:44:50 PM (21 months ago)
- Location:
- trunk/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/DbControl.java
r7946 r7947 160 160 { 161 161 this.sc = sc; 162 System.out.println("Transaction name: "+name);162 // System.out.println("Transaction name: "+name); 163 163 this.name = name; 164 164 -
trunk/src/core/net/sf/basedb/core/HibernateUtil.java
r7853 r7947 2127 2127 @since 3.12 2128 2128 */ 2129 static <T> ScrollIterator<T> loadIterator(Query<T> query, SessionControl sc)2129 static <T> ScrollIterator<T> loadIterator(Query<T> query, boolean returnArray, SessionControl sc) 2130 2130 throws BaseException 2131 2131 { … … 2136 2136 if (sc != null) pinger = Application.newPinger(sc); 2137 2137 ScrollableResults result = query.scroll(ScrollMode.FORWARD_ONLY); 2138 return new ScrollIterator<T>(result );2138 return new ScrollIterator<T>(result, returnArray); 2139 2139 } 2140 2140 catch (Throwable ex) -
trunk/src/core/net/sf/basedb/core/Install.java
r7899 r7947 119 119 method. 120 120 */ 121 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(15 0).intValue();121 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(151).intValue(); 122 122 123 123 public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress, … … 235 235 roleJobAgent, quota0, true, true); 236 236 237 // Now that we have a root user let's create a session 238 sessionControl = Application.newSessionControl( null, null, null ); 237 ClientData install = createClient(rootUser, "net.sf.basedb.core.install", "Install", "This is the installation program", null); 238 239 // Now that we have a root user and install client and let's create a session 240 sessionControl = Application.newSessionControl(install.getExternalId(), null, null); 239 241 LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword); 240 242 loginRequest.setComment("InitDBSessionId"); … … 2472 2474 { 2473 2475 2474 dc = sessionControl.newDbControl( );2476 dc = sessionControl.newDbControl("Install: Create plug-in definitions"); 2475 2477 plugin = PluginDefinition.installOrUpdate(dc, info, null, shareToEveryone); 2476 2478 if (plugin != null) … … 2520 2522 try 2521 2523 { 2522 dc = sessionControl.newDbControl( );2524 dc = sessionControl.newDbControl("Install: Create plug-in configurations"); 2523 2525 2524 2526 org.hibernate.query.Query<PluginConfigurationData> query = null; -
trunk/src/core/net/sf/basedb/core/ItemQuery.java
r7381 r7947 123 123 124 124 ScrollIterator<? extends BasicData> result = 125 HibernateUtil.loadIterator(getMainHqlQuery(dc, dataClass), sc);125 HibernateUtil.loadIterator(getMainHqlQuery(dc, dataClass), false, sc); 126 126 disableFilters(dc); 127 127 return new ItemResultIterator<I>(result, dc, itemClass, totalCount); -
trunk/src/core/net/sf/basedb/core/QueryExecutor.java
r7461 r7947 315 315 { 316 316 ScrollableResults result = query.scroll(ScrollMode.FORWARD_ONLY); 317 return new ScrollIterator<T>(result );317 return new ScrollIterator<T>(result, false); 318 318 } 319 319 } -
trunk/src/core/net/sf/basedb/core/ScrollIterator.java
r7551 r7947 40 40 41 41 private final ScrollableResults results; 42 private final boolean returnArray; 42 43 private boolean isClosed; 43 44 private E nextElement; 44 45 45 ScrollIterator(ScrollableResults results )46 ScrollIterator(ScrollableResults results, boolean returnArray) 46 47 { 47 48 assert results != null : "results == null"; 48 49 this.results = results; 50 this.returnArray = returnArray; 49 51 this.isClosed = false; 50 52 this.nextElement = null; … … 65 67 if (results.next()) 66 68 { 67 nextElement = (E)results.get(0);69 nextElement = returnArray ? (E)results.get() : (E)results.get(0); 68 70 } 69 71 else -
trunk/src/core/net/sf/basedb/core/StringUtil.java
r6022 r7947 291 291 return value.substring(0, 1).toLowerCase() + value.substring(1); 292 292 } 293 294 /** 295 Return the first non-null value (or null if all values are null). 296 @since 3.19 297 */ 298 public static final String coalesce(String... values) 299 { 300 if (values == null || values.length == 0) return null; 301 for (String v : values) 302 { 303 if (v != null) return v; 304 } 305 return null; 306 } 307 293 308 } -
trunk/src/core/net/sf/basedb/core/Update.java
r7926 r7947 47 47 import net.sf.basedb.core.data.BioPlateData; 48 48 import net.sf.basedb.core.data.BioPlateTypeData; 49 import net.sf.basedb.core.data.ChangeHistoryData; 49 50 import net.sf.basedb.core.data.ChangeHistoryDetailData; 50 51 import net.sf.basedb.core.data.ClientData; … … 459 460 </td> 460 461 </tr> 462 <tr> 463 <td>151</td> 464 <td> 465 Added {@link ChangeHistoryData#getName()}. The update will generate a default name for all 466 existing entries based on the registred job, plug-in, client, etc. 467 </td> 468 </tr> 461 469 </table> 462 470 … … 755 763 } 756 764 765 if (schemaVersion < 151) 766 { 767 if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 151..."); 768 schemaVersion = updateToSchemaVersion151(session, schemaVersion, progress); 769 progress_current += progress_step; 770 } 771 757 772 sc.logout(); 758 773 if (progress != null) progress.display(100, "Database updated successfully."); … … 958 973 959 974 if (progress != null) progress.display(50, "Checking existing items..."); 960 // Test root user account 961 SessionControl sc = Application.newSessionControl( null, null, null);975 // Test root user account (the install client was added in schema version 151 so we can't use this before updating) 976 SessionControl sc = Application.newSessionControl(schemaVersion < 151 ? null : "net.sf.basedb.core.install", null, null); 962 977 LoginRequest loginRequest = new LoginRequest(rootLogin, rootPassword); 963 978 sc.login(loginRequest); … … 1463 1478 1464 1479 org.hibernate.query.Query<ChangeHistoryDetailData> query = HibernateUtil.createQuery(statelessSession, hql, ChangeHistoryDetailData.class); 1465 Iterator<ChangeHistoryDetailData> changes = HibernateUtil.loadIterator(query, null);1480 Iterator<ChangeHistoryDetailData> changes = HibernateUtil.loadIterator(query, false, null); 1466 1481 1467 1482 int i = 0; … … 2157 2172 "where [id] = :id"); 2158 2173 2159 Iterator<JobData> it = HibernateUtil.loadIterator(query, null);2174 Iterator<JobData> it = HibernateUtil.loadIterator(query, false, null); 2160 2175 while (it.hasNext()) 2161 2176 { … … 2321 2336 } 2322 2337 2338 /** 2339 2340 @return The new schema version (=151) 2341 */ 2342 private static int updateToSchemaVersion151(org.hibernate.Session session, int currentSchemaVersion, ProgressReporter progress) 2343 throws BaseException 2344 { 2345 final int schemaVersion = 151; 2346 org.hibernate.Transaction tx = null; 2347 2348 try 2349 { 2350 tx = HibernateUtil.newTransaction(session); 2351 2352 // Pre-load names for all clients, plug-ins and jobs 2353 Map<Integer, String> clientNames = loadIdToNameMap(session, "select [c].[id], [c].[name] from [Clients] [c]"); 2354 Map<Integer, String> pluginNames = loadIdToNameMap(session, "select [p].[id], [p].[name] from [PluginDefinitions] [p]"); 2355 Map<Integer, String> jobNames = loadIdToNameMap(session, "select [j].[id], [j].[name] from [Jobs] [j]"); 2356 if (progress != null) progress.append("."); 2357 2358 // Count all 2359 String countSql = "select count(*) from ChangeHistoryData ch where ch.name is null"; 2360 org.hibernate.query.Query<Long> countQuery = HibernateUtil.createQuery(session, countSql, Long.class); 2361 long numItems = HibernateUtil.loadData(countQuery); 2362 int delta = (int)numItems / 50; 2363 2364 // Load all ChangeHistory entries 2365 String sql = "select [ch].[id], [ch].[client_id], [ch].[plugin_id], [ch].[job_id] "+ 2366 " from [ChangeHistory] [ch] where [ch].[name] is null"; 2367 org.hibernate.query.Query<Object[]> query = HibernateUtil.createSqlQuery(session, sql, Object[].class); 2368 2369 // This query is used to update the 'name' for a single entry 2370 org.hibernate.query.Query<?> fixQuery = HibernateUtil.createSqlQuery(session, 2371 "update [ChangeHistory] set [name] = :name where [id] = :id"); 2372 2373 int count = 0; 2374 Iterator<Object[]> it = HibernateUtil.loadIterator(query, true, null); 2375 while (it.hasNext()) 2376 { 2377 Object[] ch = it.next(); 2378 2379 int id = (Integer)ch[0]; 2380 Integer clientId = (Integer)ch[1]; 2381 Integer pluginId = (Integer)ch[2]; 2382 Integer jobId = (Integer)ch[3]; 2383 String clientName = clientId != null ? clientNames.get(clientId) : null; 2384 String pluginName = pluginId != null ? pluginNames.get(pluginId) : null; 2385 String jobName = jobId != null ? jobNames.get(jobId) : null; 2386 2387 String name = "Unknown"; 2388 if (jobName != null && pluginName != null && !jobName.contains(pluginName)) 2389 { 2390 name = StringUtil.trimString(pluginName+": "+jobName, Nameable.MAX_NAME_LENGTH); 2391 } 2392 else 2393 { 2394 name = StringUtil.coalesce(jobName, pluginName, clientName, "Unknown"); 2395 } 2396 2397 fixQuery.setParameter("name", name, TypeWrapper.H_STRING); 2398 fixQuery.setParameter("id", id, TypeWrapper.H_INTEGER); 2399 fixQuery.executeUpdate(); 2400 2401 count++; 2402 if (progress != null && count % delta == 0) progress.append("."); 2403 } 2404 2405 // Update the schema version number 2406 setSchemaVersion(session, schemaVersion); 2407 2408 // Commit the changes 2409 HibernateUtil.commit(tx); 2410 log.info("updateToSchemaVersion151: OK"); 2411 } 2412 catch (RuntimeException ex) 2413 { 2414 if (tx != null) HibernateUtil.rollback(tx); 2415 log.error("updateToSchemaVersion151: FAILED", ex); 2416 throw ex; 2417 } 2418 return schemaVersion; 2419 } 2420 2421 2422 private static Map<Integer, String> loadIdToNameMap(org.hibernate.Session session, String sql) 2423 { 2424 Map<Integer, String> map = new HashMap<>(); 2425 org.hibernate.query.Query<Object[]> query = HibernateUtil.createSqlQuery(session, sql, Object[].class); 2426 Iterator<Object[]> it = HibernateUtil.loadIterator(query, true, null); 2427 while (it.hasNext()) 2428 { 2429 Object[] e = it.next(); 2430 map.put((Integer)e[0], (String)e[1]); 2431 } 2432 return map; 2433 } 2323 2434 2324 2435 /** -
trunk/src/install/net/sf/basedb/install/OneTimeFix.java
r7899 r7947 77 77 .disableInternalJobQueue(true) 78 78 ); 79 SessionControl sc = Application.newSessionControl( null, null, null);79 SessionControl sc = Application.newSessionControl("net.sf.basedb.core.install", null, null); 80 80 sc.login(new LoginRequest(login, pwd)); 81 81 int numModified = Update.recalculateRemainingQuantity(new ConsoleProgressReporter(false)); … … 104 104 .disableInternalJobQueue(true) 105 105 ); 106 SessionControl sc = Application.newSessionControl( null, null, null);106 SessionControl sc = Application.newSessionControl("net.sf.basedb.core.install", null, null); 107 107 sc.login(new LoginRequest(login, pwd)); 108 108 int numModified = Update.recalculateFreeWells(new ConsoleProgressReporter(false)); -
trunk/src/install/net/sf/basedb/install/Webclient.java
r7899 r7947 97 97 .disableInternalJobQueue(true) 98 98 ); 99 SessionControl sc = Application.newSessionControl( null, null, null);99 SessionControl sc = Application.newSessionControl("net.sf.basedb.core.install", null, null); 100 100 LoginRequest loginRequest = new LoginRequest(login, password); 101 101 loginRequest.setComment("Installing web client"); 102 102 sc.login(loginRequest); 103 103 104 DbControl dc = sc.newDbControl( );104 DbControl dc = sc.newDbControl("Install: Web client"); 105 105 try 106 106 { -
trunk/src/plugins/core/net/sf/basedb/plugins/HelpImporter.java
r7714 r7947 331 331 try 332 332 { 333 dc = sc.newDbControl( );333 dc = sc.newDbControl(":Import help texts"); 334 334 client = Client.getById(dc, client.getId()); 335 335 float progLastUpdated = 0;
Note: See TracChangeset
for help on using the changeset viewer.