public void run ( ) throws SQLException { if ( ApplicationContext . isDevelopment ( ) && embeddedDb . checkRunning ( ) ) { // only checked in development (otherwise let db startup file due to locked resources) logger . severe ( "\n***WARNING***\nEmbedded DB appears to be running already. This can happen due to an unclean previous shutdown.\n***WARNING***" ) ; return ; } if ( shutdownHook != null ) { embeddedDb . shutdown ( ) ; Runtime . getRuntime ( ) . removeShutdownHook ( shutdownHook ) ; } shutdownHook = new Thread ( new Runnable ( ) { public void run ( ) { try { embeddedDb . shutdown ( ) ; } catch ( SQLException ex ) { System . err . println ( "ERROR: Cannot shut down embedded db cleanly" ) ; ex . printStackTrace ( ) ; } } } ) ; Runtime . getRuntime ( ) . addShutdownHook ( shutdownHook ) ; embeddedDb . startup ( ) ; if ( ! embeddedDb . checkMdwSchema ( ) ) { embeddedDb . createMdwSchema ( ) ; // seed users try { String usersJson = JsonUtil . read ( "seed_users.json" ) ; if ( usersJson != null ) { logger . info ( "Loading seed users into " + MDW_EMBEDDED_DB_CLASS + ":" ) ; JSONObject usersObj = new JsonObject ( usersJson ) ; if ( usersObj . has ( "users" ) ) { JSONArray usersArr = usersObj . getJSONArray ( "users" ) ; for ( int i = 0 ; i < usersArr . length ( ) ; i ++ ) { User user = new User ( usersArr . getJSONObject ( i ) ) ; logger . info ( " creating user: '" + user . getCuid ( ) + "'" ) ; embeddedDb . insertUser ( user ) ; } } } } catch ( Exception ex ) { throw new SQLException ( "Error inserting from seed_users.json" , ex ) ; } extensionsNeedInitialization = true ; } }
Starts the db if not running and connects to confirm process_instance table exists and creates the schema if the table is not found .