home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / createuser.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  3.7 KB  |  122 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Step 1 -- Retrieve helper "beans" from the BSF framework
  17.  
  18. scriptaction = bsf.lookupBean( "scriptaction" )
  19. manager      = bsf.lookupBean( "manager" )            
  20. request      = bsf.lookupBean( "request" )
  21. logger       = bsf.lookupBean( "logger" )
  22. actionMap    = bsf.lookupBean( "actionMap" )
  23.  
  24. // Step 2 -- Perform the action
  25.  
  26. logger.debug( "START createuser.js" )
  27.  
  28. // Retrieve things from the session and request
  29. // NOTE: they are all of type java.lang.String
  30.  
  31. session = request.getSession( false )
  32. uwid     = session.getAttribute( "uwid" )
  33.  
  34. logger.debug( "Raw" )
  35. logger.debug( "  uwid [" + uwid + "]" )
  36.  
  37. // We have the choice of declaring things out here and making them explicitly
  38. // null, or we have to use a different comparison in the "finally" block (defined?)
  39.  
  40. dbselector = null
  41. datasource = null
  42. conn = null
  43. queryStatement = null
  44. insertStatement = null
  45.  
  46. try
  47. {
  48.     dbselector = manager.lookup( scriptaction.DB_CONNECTION )
  49.     datasource = dbselector.select( "ceabplanner" )
  50.     conn = datasource.getConnection()    
  51.  
  52.     // Check that the student exists
  53.  
  54.     queryStatement = conn.prepareStatement(
  55.               "select count(*) here from students where uw_userid=? "
  56.     )
  57.               
  58.     queryStatement.setString( 1, uwid )
  59.       
  60.     resultSet = queryStatement.executeQuery()
  61.     resultSet.next()
  62.      
  63.     userExists = resultSet.getInt("here")
  64.     
  65.     logger.debug( "Result #1 [" + userExists + "]" )
  66.  
  67.     if (!userExists)
  68.     {
  69.  
  70.         logger.debug( "User does not exist...creating and initializing" )
  71.  
  72.         insertStatement = conn.prepareStatement(
  73.                  "INSERT INTO students (id, uw_userid, name, uw_id, current_term) values (students_seq.nextval, ?, '','', (SELECT id FROM terms WHERE description = '1A'))"
  74.         )
  75.  
  76.         insertStatement.setString( 1, uwid ); 
  77.  
  78.         result = insertStatement.executeUpdate()
  79.         logger.debug( "Result #2 [" + result + "]" )
  80.  
  81.         insertStatement = conn.prepareStatement(
  82.                  "insert into studentNotes (student,note) values ( ( SELECT id FROM students WHERE uw_userid = ? ),'')"
  83.         )
  84.  
  85.         insertStatement.setString( 1, uwid ); 
  86.  
  87.         result = insertStatement.executeUpdate()
  88.         logger.debug( "Result #3 [" + result + "]" )
  89.  
  90.         insertStatement = conn.prepareStatement(
  91.                  "INSERT INTO studentKnownCourseList (student, known_course, term_taken, distance_ed, course_extra) ( SELECT ( SELECT id FROM students WHERE uw_userid = ? ), course, term, '1', '1' FROM corecourses )"
  92.         )
  93.  
  94.         insertStatement.setString( 1, uwid ); 
  95.  
  96.         result = insertStatement.executeUpdate()
  97.         logger.debug( "Result #4 [" + result + "]" )
  98.  
  99.         conn.commit()
  100.     }
  101.     else
  102.     {
  103.         logger.debug( "User exists" )
  104.     }
  105.     actionMap.put( "scriptaction-continue", "" )
  106. }
  107. catch( ex )
  108. {
  109.     logger.debug( "Caught Exception" )
  110.     logger.debug( "  " + ex )
  111. }
  112. finally
  113. {
  114.     if ( null != queryStatement ) { queryStatement.close() }
  115.     if ( null != insertStatement ) { insertStatement.close() }
  116.     if ( null != conn ) { conn.close() }
  117.     if ( null != datasource ) { dbselector.release( datasource ) }
  118.     if ( null != dbselector ) { manager.release( dbselector ) }
  119. }
  120.  
  121. logger.debug( "END createuser.js" )
  122.