@ Override public int delete ( Integer id , boolean autoCommit ) throws SQLException { try { // Handle "cascading" delete or constraints on deleting entities that other entities depend on // (e.g., keep a calendar from being deleted if trips reference it). // FIXME: actually add "cascading"? Currently, it just deletes one level down. deleteFromReferencingTables ( tablePrefix , specTable , id ) ; // Next, delete the actual record specified by id. PreparedStatement statement = connection . prepareStatement ( specTable . generateDeleteSql ( tablePrefix ) ) ; statement . setInt ( 1 , id ) ; LOG . info ( statement . toString ( ) ) ; // Execute query int result = statement . executeUpdate ( ) ; if ( result == 0 ) { LOG . error ( "Could not delete {} entity with id: {}" , specTable . name , id ) ; throw new SQLException ( "Could not delete entity" ) ; } if ( autoCommit ) connection . commit ( ) ; // FIXME: change return message based on result value return result ; } catch ( Exception e ) { LOG . error ( "Could not delete {} entity with id: {}" , specTable . name , id ) ; e . printStackTrace ( ) ; // Rollback changes if errors encountered. connection . rollback ( ) ; throw e ; } finally { // Always close connection if auto-committing. Otherwise, leave open (for potential further updates). if ( autoCommit ) connection . close ( ) ; } }
Deletes an entity for the specified ID .