KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > serversystem > DatabaseConnection


1 package com.daffodilwoods.daffodildb.server.serversystem;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.datatriggersystem.*;
7 import com.daffodilwoods.database.resource.*;
8
9 public class DatabaseConnection {
10
11    ServerSystem serverSystem;
12    _DataTriggerDatabase dataTrigerDatabase;
13
14    public DatabaseConnection(ServerSystem serverSystem0) {
15       serverSystem = serverSystem0;
16    }
17
18    public _ServerSession executeAll(String JavaDoc databaseName) throws DException {
19       try {
20          dataTrigerDatabase = serverSystem.getDataTriggerDatabase(databaseName);
21          Properties prop = new Properties();
22          prop.setProperty(_Server.USER, SystemTables.SYSTEM);
23          prop.setProperty(_Server.XID, SystemTables.SYSTEM);
24          prop.setProperty(_Server.ISCREATED, "false");
25          _ServerSession connection = serverSystem.getServerSession(SystemTables.SYSTEM, SystemTables.SYSTEM, prop, databaseName);
26          ( (ServerSession) connection).setVerboseForCreatingDatabase();
27          ArrayList informationschemastatements = SystemTablesCreator.getInformationSchemaStatements();
28          ArrayList definationschemastatements = SystemTablesCreator.getDefinitionSchemaStatement();
29          ArrayList indexesList = SystemTablesCreator.getSystemTableIndexes();
30          for (int i = 0; i < informationschemastatements.size(); i++) {
31             connection.execute( (String JavaDoc) informationschemastatements.get(i), 0);
32          }
33          for (int i = 0; i < definationschemastatements.size(); i++) {
34             connection.execute( (String JavaDoc) definationschemastatements.get(i), 0);
35          }
36          for (int i = 0; i < indexesList.size(); i++) {
37             connection.execute( (String JavaDoc) indexesList.get(i), 0);
38          }
39          return connection;
40       } catch (DException dex) {
41          throw dex;
42       } catch (Exception JavaDoc ex) {
43          throw new DException("DSE0", new Object JavaDoc[] {ex.getMessage()});
44       }
45    }
46
47    public _ServerSession executeAllNew(String JavaDoc databaseName) throws DException {
48       try {
49          dataTrigerDatabase = serverSystem.getDataTriggerDatabase(databaseName);
50          Properties prop = new Properties();
51          prop.setProperty(_Server.USER, SystemTables.SYSTEM);
52          prop.setProperty(_Server.XID, SystemTables.SYSTEM);
53          prop.setProperty(_Server.ISCREATED, "false");
54          _ServerSession connection = serverSystem.getServerSession(SystemTables.SYSTEM, SystemTables.SYSTEM, prop, databaseName);
55
56          ( (ServerSession) connection).setVerboseForCreatingDatabase();
57          ArrayList informationschemastatements = SystemTablesCreator.getInformationSchemaStatements();
58          ArrayList definationschemastatements = SystemTablesCreator.getDefinitionSchemaStatement();
59          ArrayList indexesList = SystemTablesCreator.getSystemTableIndexes();
60          connection.getDataDictionary().setSystemTableConstraint(false);
61          for (int i = 0; i < informationschemastatements.size(); i++) {
62             connection.execute( (String JavaDoc) informationschemastatements.get(i), 0);
63          }
64          connection.execute( (String JavaDoc) definationschemastatements.get(0), 0);
65
66          return connection;
67       } catch (DException dex) {
68          throw dex;
69       } catch (Exception JavaDoc ex) {
70          throw new DException("DSE0", new Object JavaDoc[] {ex.getMessage()});
71       }
72    }
73 }
74
Popular Tags