KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > admin > AdminManager


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: AdminManager.java,v 1.6 2002/12/29 11:15:56 per_nyfelt Exp $
8

9 package org.ozoneDB.core.admin;
10
11 import org.ozoneDB.OzoneInterface;
12 import org.ozoneDB.core.*;
13 import org.ozoneDB.util.LogWriter;
14
15
16 /**
17  * This class does nothing than handling the initialization of the admin
18  * system.
19  *
20  * @version $Revision: 1.6 $ $Date: 2002/12/29 11:15:56 $
21  * @author <a HREF="http://www.smb-tec.com">SMB</a>
22  * @see Admin
23  */

24 public final class AdminManager extends ServerComponent {
25
26     public AdminManager( Env _env) {
27         super( _env );
28     }
29
30
31     public void startup() throws Exception JavaDoc {
32         env.logWriter.newEntry( this, "startup...", LogWriter.INFO );
33
34         User user = env.userManager.userForID( 0 );
35         // happens if db was not initialized by proper version of install tool
36
if (user == null) {
37             env.userManager.newUser( "root", 0 );
38             user = env.userManager.userForID( 0 );
39             if (user == null) {
40                 throw new UserManagerException( "Unable to create root user account." );
41             }
42         }
43         Transaction ta = env.transactionManager.newTransaction( user );
44
45         ObjectContainer adminContainer = env.storeManager.containerForID( ta, new ObjectID( AdminImpl.OBJECT_ID ));
46
47         try {
48             if (adminContainer == null) {
49                 env.logWriter.newEntry( this, "No admin object found. Initializing...", LogWriter.INFO );
50
51                 ObjectContainer container = ta.createObject( AdminImpl.class.getName(), OzoneInterface.GroupRead | OzoneInterface.GroupLock, AdminImpl.OBJECT_NAME, null, null, new ObjectID( AdminImpl.OBJECT_ID ) );
52
53                 try {
54                     ta.prepareCommit();
55                     ta.commit();
56                     env.logWriter.newEntry( this, "Admin object created.", LogWriter.INFO );
57                 } finally {
58                     container.unpin();
59                 }
60             }
61         } finally {
62             if (adminContainer!=null) {
63                 adminContainer.unpin();
64             }
65         }
66         env.transactionManager.deleteTransaction();
67     }
68
69
70     public void shutdown() throws Exception JavaDoc {
71         env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO );
72     }
73
74
75     public void save() throws Exception JavaDoc {
76     }
77
78 }
79
80
Popular Tags