Changeset 27316


Ignore:
Timestamp:
05/08/13 11:10:33 (8 years ago)
Author:
sjm84
Message:

Reformatting this file as well as tidying imports

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java

    r26911 r27316  
    1919package org.greenstone.gsdl3.util;
    2020
    21 import javax.swing.*;
    22 
    23 import org.greenstone.gsdl3.service.Authentication;
    24 
    25 import java.io.File;
    2621import java.sql.Connection;
    2722import java.sql.DriverManager;
    2823import java.sql.ResultSet;
    2924import java.sql.SQLException;
    30 import java.sql.SQLWarning;
    3125import java.sql.Statement;
    3226import java.util.ArrayList;
    3327import java.util.HashMap;
    34 import java.util.Properties;
     28
     29import org.greenstone.gsdl3.service.Authentication;
    3530
    3631public class DerbyWrapper
     
    8782    public void closeDatabase()
    8883    {
    89             //state = null;
     84        //state = null;
    9085        //conn = null;
    9186        boolean gotSQLExc = false;
    9287        try
    93             {
    94             //  shutdown the database
    95             DriverManager.getConnection(protocol_str + ";shutdown=true");
    96            
    97             }
     88        {
     89            //  shutdown the database
     90            DriverManager.getConnection(protocol_str + ";shutdown=true");
     91
     92        }
    9893        catch (SQLException se)
    9994        {
    100             // this is good (i.e. what Derby is designed to do on a successful shutdown)
    101             gotSQLExc = true;
    102         }
    103         catch (Exception e) {
    104             e.printStackTrace();
     95            // this is good (i.e. what Derby is designed to do on a successful shutdown)
     96            gotSQLExc = true;
     97        }
     98        catch (Exception e)
     99        {
     100            e.printStackTrace();
    105101        }
    106102
    107103        if (!gotSQLExc)
    108104        {
    109             System.err.println("Warning: Derby Database did not shut down normally");
    110         }
    111     }
    112 
    113        public static void shutdownDatabaseServer()
    114        {
    115        boolean gotSQLExc = false;
    116 
    117        try {
    118            //  shutdown the whole server
    119            DriverManager.getConnection(PROTOCOL + ";shutdown=true");
    120            
    121        }
    122        catch (SQLException se) {
    123            // this is good (i.e. what Derby is designed to do on a successful shutdown)
    124            gotSQLExc = true;
    125            //System.out.println("Shutdown returned: " + se);
    126        }
    127        catch (Exception e) {
    128 
    129            e.printStackTrace();
    130        }
    131        if (!gotSQLExc) {
    132            System.err.println("Warning: Derby did not shut down normally");
    133        }
    134 
    135        }
     105            System.err.println("Warning: Derby Database did not shut down normally");
     106        }
     107    }
     108
     109    public static void shutdownDatabaseServer()
     110    {
     111        boolean gotSQLExc = false;
     112
     113        try
     114        {
     115            //  shutdown the whole server
     116            DriverManager.getConnection(PROTOCOL + ";shutdown=true");
     117
     118        }
     119        catch (SQLException se)
     120        {
     121            // this is good (i.e. what Derby is designed to do on a successful shutdown)
     122            gotSQLExc = true;
     123            //System.out.println("Shutdown returned: " + se);
     124        }
     125        catch (Exception e)
     126        {
     127
     128            e.printStackTrace();
     129        }
     130        if (!gotSQLExc)
     131        {
     132            System.err.println("Warning: Derby did not shut down normally");
     133        }
     134
     135    }
    136136
    137137    public void createDatabase()
     
    375375    }
    376376
    377     // findUser(null) will return all users, which is why a UserQueryResult
    378     // (a vector of UserTermInfo) is returned
     377    // findUser(null) will return all users, which is why a UserQueryResult
     378    // (a vector of UserTermInfo) is returned
    379379    public UserQueryResult findUser(String username) throws SQLException
    380380    {
     
    443443            conn.setAutoCommit(false);
    444444            String sql_modify_user_info = "update " + USERS + " set ";
    445            
     445
    446446            boolean needComma = false;
    447447            if (new_password != null && !new_password.equals(""))
     
    456456                needComma = true;
    457457            }
    458            
    459             if(email != null)
     458
     459            if (email != null)
    460460            {
    461461                sql_modify_user_info += (needComma ? "," : "") + " email='" + email + "'";
    462462            }
    463            
     463
    464464            sql_modify_user_info += " where username='" + username + "'";
    465465            state.execute(sql_modify_user_info);
     
    496496    public void db2txt()
    497497    {
    498         System.err.println(db2txtString());     
     498        System.err.println(db2txtString());
    499499    }
    500500
    501501    public String db2txtString()
    502502    {
    503         //String db2txt = "Error in converting db2txt string.";
    504         String db2txt = "";
    505         try
    506         {
    507             conn.setAutoCommit(false); // An exception at this line can happen when the GS3 tomcat server is already running
    508                                        // and GS3 is already accessing the usersDB when this function independently tries to
    509                                        // connect to it (via usersDB2txt.java's main(). For an explanation of the possible
    510                                        // reasons, see http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
    511                                        // section "Embedded Derby supports multiple users in one JVM".
     503        //String db2txt = "Error in converting db2txt string.";
     504        String db2txt = "";
     505        try
     506        {
     507            conn.setAutoCommit(false); // An exception at this line can happen when the GS3 tomcat server is already running
     508                                        // and GS3 is already accessing the usersDB when this function independently tries to
     509                                        // connect to it (via usersDB2txt.java's main(). For an explanation of the possible
     510                                        // reasons, see http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
     511                                        // section "Embedded Derby supports multiple users in one JVM".
    512512            String sql_list_all_user = "select username, password, accountstatus, comment, email from " + USERS;
    513513            ResultSet rs = state.executeQuery(sql_list_all_user);
     
    541541                }
    542542                conn.commit();
    543                                
     543
    544544                buffer.append("USERNAME = " + user.get("username"));
    545545                buffer.append("\nPASSWORD = " + user.get("password"));
     
    548548                buffer.append("\nCOMMENT = " + user.get("comment"));
    549549                buffer.append("\nEMAIL = " + user.get("email"));
    550                 buffer.append("\n-------------------------------------\n");             
     550                buffer.append("\n-------------------------------------\n");
    551551            }
    552552            db2txt = buffer.toString();
     
    558558        {
    559559            ex.printStackTrace();
    560         } finally {
    561             return db2txt;
     560        }
     561        finally
     562        {
     563            return db2txt;
    562564        }
    563565    }
Note: See TracChangeset for help on using the changeset viewer.