Changeset 2142
- Timestamp:
- Apr 3, 2006, 1:14:21 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/common-queries.xml
r2129 r2142 1622 1622 </description> 1623 1623 </query> 1624 1625 <query id="GET_SCHEMA_VERSION" type="HQL"> 1626 <sql> 1627 SELECT sv 1628 FROM SchemaVersionData sv 1629 </sql> 1630 <description> 1631 A Hibernate query that loads the schema version (there should only be one record). 1632 </description> 1633 </query> 1634 1635 <query id="SET_SCHEMA_VERSION" type="HQL"> 1636 <sql> 1637 UPDATE SchemaVersionData sv 1638 SET sv.schemaVersion = :schemaVersion, 1639 sv.build = :build 1640 </sql> 1641 <description> 1642 A Hibernate query that updates the schema version and build number. 1643 </description> 1644 </query> 1645 1646 <query id="SET_PROJECT_ID_FOR_JOBS" type="HQL"> 1647 <sql> 1648 UPDATE JobData job 1649 SET job.activeProjectId = 0 1650 WHERE job.activeProjectId IS NULL 1651 </sql> 1652 <description> 1653 A Hibernate query that sets the active project ID for all 1654 jobs to 0 if they have a null value. 1655 </description> 1656 </query> 1624 1657 1625 1658 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/Application.java
r2038 r2142 26 26 27 27 import net.sf.basedb.core.data.ClientData; 28 import net.sf.basedb.core.data.SchemaVersionData; 28 29 import net.sf.basedb.core.authentication.Authenticator; 29 30 … … 185 186 return BUILD; 186 187 } 188 189 /** 190 Get the current database schema version number. 191 @return The schema version number, or -1 if it could not be loaded 192 */ 193 public static int getSchemaVersion() 194 { 195 org.hibernate.Session session = null; 196 org.hibernate.Transaction tx = null; 197 int schemaVersion = -1; 198 try 199 { 200 session = HibernateUtil.newSession(); 201 tx = HibernateUtil.newTransaction(session); 202 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_SCHEMA_VERSION"); 203 schemaVersion = HibernateUtil.loadData(SchemaVersionData.class, query).getSchemaVersion(); 204 HibernateUtil.commit(tx); 205 } 206 catch (BaseException ex) 207 { 208 if (tx != null) HibernateUtil.rollback(tx); 209 log.error("getSchemaVersion", ex); 210 } 211 finally 212 { 213 if (session != null) HibernateUtil.close(session); 214 } 215 return schemaVersion; 216 } 217 187 218 188 219 /** -
trunk/src/core/net/sf/basedb/core/HibernateUtil.java
r2051 r2142 439 439 session = HibernateUtil.newSession(); 440 440 DatabaseMetaData metaData = session.connection().getMetaData(); 441 441 442 Iterator<PersistentClass> classes = cfg.getClassMappings(); 442 443 while (classes.hasNext() && isEmpty) … … 1087 1088 } 1088 1089 } 1089 1090 /** 1091 Exceute an update or delete query. 1092 1093 @param query A <code>Query</code> object which is executed using the 1094 {@link Query#executeUpdate()} method 1095 @return The number of affected items 1096 */ 1097 static int executeUpdate(Query query) 1098 throws BaseException 1099 { 1100 assert query != null : "query == null"; 1101 try 1102 { 1103 return query.executeUpdate(); 1104 } 1105 catch(HibernateException ex) 1106 { 1107 throw new BaseException(ex); 1108 } 1109 } 1110 1090 1111 /** 1091 1112 Get the value of a property on a data object using Hibernate -
trunk/src/core/net/sf/basedb/core/Install.java
r2106 r2142 36 36 import net.sf.basedb.core.data.QuotaIndex; 37 37 import net.sf.basedb.core.data.RoleData; 38 import net.sf.basedb.core.data.SchemaVersionData; 38 39 import net.sf.basedb.core.data.SoftwareTypeData; 39 40 import net.sf.basedb.core.data.SoftwareData; … … 86 87 private static SessionControl sessionControl = null; 87 88 89 /** 90 The schema version to give to new installations. Already 91 existing installations will be updated to this version number 92 by the {@link Update#updateDatabase(ProgressReporter, String, String)} 93 method. 94 */ 95 private static final int NEW_SCHEMA_VERSION = 2; 96 88 97 public static synchronized void createTables(boolean update, final ProgressReporter progress) 89 98 throws BaseException … … 139 148 @throws BaseException This exception is thrown if there is an error 140 149 */ 141 public static synchronized void initDatabase(ProgressReporter progress, String rootPassword) 142 throws BaseException 143 { 144 Application.start(false); 145 session = HibernateUtil.newSession(); 146 150 public static synchronized void initDatabase(boolean update, ProgressReporter progress, String rootLogin, String rootPassword) 151 throws BaseException 152 { 147 153 final int total_progress_steps = 22; 148 154 final float progress_factor = 100 / total_progress_steps; … … 150 156 try 151 157 { 158 Application.start(false); 159 session = HibernateUtil.newSession(); 160 161 // SchemaVersion 162 createSchemaVersion(update ? 1 : NEW_SCHEMA_VERSION); 152 163 153 164 // QuotaTypes … … 177 188 // Users 178 189 if (progress != null) progress.display((int)(4*progress_factor), "--Creating users..."); 179 UserData rootUser = createUser(User.ROOT, "root", rootPassword, "Root", "This is the root user account of BASE. It has full permission to everything.", roleAdmin, quotaUnlimit);190 UserData rootUser = createUser(User.ROOT, rootLogin, rootPassword, "Root", "This is the root user account of BASE. It has full permission to everything.", roleAdmin, quotaUnlimit); 180 191 // createUser(0, "demo", "demo", "Demo", "This account can be used for demonstration purposes.", Role.GUEST); 181 192 // createUser(0, "power", "power", "Power user", "This account has power user privileges.", Role.POWER_USER); … … 183 194 // Now that we have a root user let's create a session 184 195 sessionControl = Application.newSessionControl( null, null, null ); 185 sessionControl.login( "root", rootPassword, "InitDBSessionId", false);196 sessionControl.login(rootLogin, rootPassword, "InitDBSessionId", false); 186 197 187 198 if (progress != null) progress.display((int)(5*progress_factor), "--Creating groups..."); … … 577 588 } 578 589 590 /** 591 Create the schema version. 592 */ 593 private static SchemaVersionData createSchemaVersion(int sv) 594 throws BaseException 595 { 596 org.hibernate.Transaction tx = null; 597 SchemaVersionData schemaVersion = null; 598 try 599 { 600 tx = HibernateUtil.newTransaction(session); 601 602 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_SCHEMA_VERSION"); 603 schemaVersion = HibernateUtil.loadData(SchemaVersionData.class, query); 604 if (schemaVersion != null) 605 { 606 log.info("createSchemaVersion: EXISTS"); 607 HibernateUtil.commit(tx); 608 } 609 else 610 { 611 schemaVersion = new SchemaVersionData(); 612 schemaVersion.setBuild(Application.getBuild()); 613 schemaVersion.setSchemaVersion(sv); 614 HibernateUtil.saveData(session, schemaVersion); 615 HibernateUtil.commit(tx); 616 log.info("createSchemaVersion: OK"); 617 } 618 } 619 catch (BaseException ex) 620 { 621 if(tx != null) HibernateUtil.rollback(tx); 622 log.error("createSchemaVersion: FAILED", ex); 623 throw ex; 624 } 625 return schemaVersion; 626 } 627 579 628 /** 580 629 Create a {@link Directory}. -
trunk/src/install/net/sf/basedb/install/InitDB.java
r2021 r2142 26 26 27 27 import net.sf.basedb.core.Install; 28 import net.sf.basedb.core. ProgressReporter;28 import net.sf.basedb.core.Update; 29 29 import net.sf.basedb.util.ConsoleProgressReporter; 30 30 import net.sf.basedb.util.ChainedProgressReporter; … … 50 50 } 51 51 String rootPassword = args.length == 2 ? args[1] : args[0]; 52 String rootLogin = "root"; 52 53 boolean update = args.length == 2 && "update".equals(args[0]); 53 54 try … … 56 57 progress.setRange(0, 30); 57 58 Install.createTables(update, progress); 58 progress.setRange(35, 90); 59 Install.initDatabase(progress, rootPassword); 59 progress.setRange(35, 70); 60 Install.initDatabase(update, progress, rootLogin, rootPassword); 61 progress.setRange(75, 90); 62 Update.updateDatabase(progress, rootLogin, rootPassword); 60 63 progress.setRange(95, 100); 61 64 progress.display(0, "Installing web application..."); … … 63 66 progress.display(100, "Web application installed successfully.\n"); 64 67 } 65 catch ( Exception ex)68 catch (Throwable t) 66 69 { 67 70 System.out.println("\n"); 68 ex.printStackTrace();71 t.printStackTrace(); 69 72 } 70 73 } -
trunk/src/test/TestInstall.java
r1913 r2142 37 37 ProgressReporter progress = new ConsoleProgressReporter(); 38 38 Install.createTables(false, progress); 39 Install.initDatabase( progress, "root");39 Install.initDatabase(false, progress, "root", "root"); 40 40 progress.display(100, "Database installed successfully.\n"); 41 41 } -
trunk/src/test/TestUpdate.java
r2021 r2142 37 37 ProgressReporter progress = new ConsoleProgressReporter(); 38 38 Install.createTables(true, progress); 39 Install.initDatabase(progress, "root"); 39 Install.initDatabase(true, progress, "root", "root"); 40 Update.updateDatabase(progress, "root", "root"); 40 41 progress.display(100, "Database updated successfully.\n"); 41 42 } -
trunk/www/exception/exception.jsp
r2118 r2142 116 116 <tr> 117 117 <td class="prompt">Base version</td> 118 <td><%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+" )"%></td>118 <td><%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+"; schema #" + Application.getSchemaVersion()+")"%></td> 119 119 </tr> 120 120 <tr> -
trunk/www/info/about.jsp
r2091 r2142 60 60 <b>Administrator:</b> <%=Values.getString(serverAdminName, "<i>- unknown -</i>")%><br> 61 61 <b>Email:</b> <%=serverAdminEmail == null ? "<i>- unknown -</i>": "<a href=\"mailto:"+serverAdminEmail+"\">"+serverAdminEmail+"</a>"%><br> 62 <b>Version:</b> <%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+" )"%><br>62 <b>Version:</b> <%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+"; schema #" + Application.getSchemaVersion()+")"%><br> 63 63 <br> 64 64 <font size="-1"> … … 75 75 <tr> 76 76 <td class="prompt">Base version</td> 77 <td><%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+" )"%></td>77 <td><%=Application.getMajorVersion() + "." +Application.getMinorVersion() + " (build #" + Application.getBuild()+"; schema #" + Application.getSchemaVersion()+")"%></td> 78 78 </tr> 79 79 <tr>
Note: See TracChangeset
for help on using the changeset viewer.