Used by many functions to create players or admins @param ApplicationRoot @param classId Cannot be null, relationship depending @param userName Cannot be null @param userPass Cannot be null @param userRole Cannot be null, must be "player" or "admin" @param userAddress Must be unique @param tempPass
(String ApplicationRoot, String classId, String userName, String userPass, String userRole, String userAddress, boolean tempPass)
| 868 | * @throws SQLException If the creation fails, a Exception is thrown |
| 869 | */ |
| 870 | public static boolean userCreate (String ApplicationRoot, String classId, String userName, String userPass, String userRole, String userAddress, boolean tempPass) |
| 871 | throws SQLException |
| 872 | { |
| 873 | boolean result = false; |
| 874 | log.debug("*** Setter.userCreate ***"); |
| 875 | log.debug("classId = " + classId); |
| 876 | log.debug("userName" + userName); |
| 877 | log.debug("userRole" + userRole); |
| 878 | log.debug("userAddress" + userAddress); |
| 879 | Connection conn = Database.getCoreConnection(ApplicationRoot); |
| 880 | try |
| 881 | { |
| 882 | log.debug("Executing userCreate procedure on Database"); |
| 883 | CallableStatement callstmt = conn.prepareCall("call userCreate(?, ?, ?, ?, ?, ?)"); |
| 884 | callstmt.setString(1, classId); |
| 885 | callstmt.setString(2, userName); |
| 886 | callstmt.setString(3, userPass); |
| 887 | callstmt.setString(4, userRole); |
| 888 | callstmt.setString(5, userAddress); |
| 889 | callstmt.setBoolean(6, tempPass); |
| 890 | ResultSet registerAttempt = callstmt.executeQuery(); |
| 891 | log.debug("Opening result set"); |
| 892 | boolean goOn = false; |
| 893 | try |
| 894 | { |
| 895 | registerAttempt.next(); //Procedure Ran correctly |
| 896 | goOn = true; |
| 897 | } |
| 898 | catch(Exception e) |
| 899 | { |
| 900 | log.fatal("Could not open result set for register..."); |
| 901 | result = false; |
| 902 | } |
| 903 | if(goOn) |
| 904 | { |
| 905 | if(registerAttempt.getString(1) == null) //Registration success |
| 906 | { |
| 907 | log.debug("Register Success"); |
| 908 | result = true; |
| 909 | } |
| 910 | else //Registration failure |
| 911 | { |
| 912 | result = false; |
| 913 | log.debug("ResultSet contained -> " + registerAttempt.getString(1)); |
| 914 | throw new SQLException(registerAttempt.getString(1)); |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | catch(SQLException e) |
| 919 | { |
| 920 | log.fatal("userCreate Failure: " + e.toString()); |
| 921 | throw new SQLException(e); |
| 922 | } |
| 923 | Database.closeConnection(conn); |
| 924 | log.debug("*** END userCreate ***"); |
| 925 | return result; |
| 926 | } |
| 927 |