source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbySQLServer.java@ 30055

Last change on this file since 30055 was 30055, checked in by ak19, 9 years ago

Fixing bug in GS3 installer that didn't use the longer password provided, despite the installer now allowing more than 8. The problem was bigger and manifold. 1. Fixed ModifyUsersDB to allow up to and incl 20 chars instead of 8. 2. Fixed the DerbyWrapper classes since the ant config-admin and config-user tasks had stopped working when global.properties was consulted for the derbyserver name and port. Now providing fallbacks again for the installer. 3. build.xml may no longer need to stop tomcat then modify the derby db and then start tomcat again because we're no longer using an embedded derby, but because we're using a networked derby, modifying the usersdb now didn't work unless greenstone (actually derby) was running. Changed the config targets to allow modifying admin and user data even if greenstone is not running, by making the update-userdb target that's called by these two tasks ensure the derbyserver is running before modifying the userdb, and stopping it if it was started up by the target.

File size: 2.3 KB
Line 
1package org.greenstone.gsdl3.sql.derby;
2
3
4import org.apache.log4j.*;
5import org.greenstone.gsdl3.sql.*;
6import java.sql.Connection;
7import java.sql.DriverManager;
8import java.sql.SQLException;
9
10import org.greenstone.util.GlobalProperties;
11
12public class DerbySQLServer implements SQLServer{
13
14 static final String PORT = GlobalProperties.getProperty("derby.server.port", "1527");
15 static final String DERBYSERVER = GlobalProperties.getProperty("derby.server", "localhost");
16 static final String PROTOCOL = "jdbc:derby://"+DERBYSERVER+":"+PORT+"/"; // "jdbc:derby://localhost:1527";
17 static final String DRIVER = "org.apache.derby.jdbc.ClientDriver"; //"org.apache.derby.jdbc.EmbeddedDriver";
18 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.sql.derby.DerbySQLServer.class.getName());
19
20 public DerbySQLServer(){
21 try{
22 Class.forName(DRIVER).newInstance();
23 }
24 catch(Exception e){
25 logger.error("Couldn't find derby driver: "+DRIVER,e);
26 }
27 }
28
29 public Connection connect(String databasePath){
30 try{
31 String protocol_str = PROTOCOL + databasePath;
32 Connection connection = DriverManager.getConnection(protocol_str);
33 return connection;
34 }
35 catch(Exception e){
36 logger.info("Connect to database "+databasePath + " failed!");
37 }
38
39 return null;
40
41 }
42
43 public Connection connectAndCreate(String databasePath){
44 try{
45 String protocol_str = PROTOCOL + databasePath + ";create=true";
46 Connection connection = DriverManager.getConnection(protocol_str);
47 return connection;
48 }
49 catch(Exception e){
50 logger.error("Connect to database "+databasePath + " failed!",e);
51
52 }
53 return null;
54 }
55
56 public boolean disconnect(String databasePath){
57
58 // Only shutdown if using embedded derby,
59 // not if it's a networked derby server, which is what we now use
60
61 if(!DRIVER.equals("org.apache.derby.jdbc.EmbeddedDriver")) {
62 return true;
63 }
64
65 // embedded derby driver
66 try{
67 String protocol_str = PROTOCOL + databasePath + ";shutdown=true";
68 DriverManager.getConnection(protocol_str);
69
70 }catch (SQLException se){
71 String theError = (se).getSQLState();
72 if (!theError.equals("08006")){
73// logger.error("Database "+databasePath + " couldn't be shut down properly!",se);
74 }
75 else{
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83
84
85}
Note: See TracBrowser for help on using the repository browser.