@Override public int insertUnassignedGroup(int analysisGroup) throws AdeException {
  if (analysisGroup != UNASSIGNED_ANALYSIS_GROUP_ID) {
    throw new AdeInternalException("This update is for unassigned analysis groups ONLY");
  }
  int analysisGroupInternalId;
  analysisGroupInternalId=getUnassignedGroupInternalId();
  if (analysisGroupInternalId != 0)   return analysisGroupInternalId;
  final ConnectionWrapper cw=new ConnectionWrapper(AdeInternal.getDefaultConnection());
  ResultSet generatedKey=null;
  PreparedStatement ps=null;
  try {
    final int ruleId=insertUnassignedRules();
    final int evaluationOrder=getNumOfGroups(cw) + 1;
    PreparedStatementWrapper psw=cw.preparedStatement("INSERT INTO " + SQL.GROUPS + " (GROUP_NAME, "+ "GROUP_TYPE, DATA_TYPE, RULE_INTERNAL_ID, EVALUATION_ORDER) "+ "VALUES (?,?,?,?,?)",new String[]{"GROUP_INTERNAL_ID"});
    ps=psw.getPreparedStatement();
    int pos=1;
    ps.setString(pos++,UNASSIGNED_GROUP_NAME);
    ps.setInt(pos++,UNASSIGNED_GROUP_TYPE);
    ps.setInt(pos++,UNASSIGNED_DATA_TYPE);
    ps.setInt(pos++,ruleId);
    ps.setInt(pos++,evaluationOrder);
    ps.execute();
    generatedKey=ps.getGeneratedKeys();
    if (generatedKey.next()) {
      analysisGroupInternalId=generatedKey.getInt(1);
    }
    cw.close();
  }
 catch (  SQLException e) {
    cw.failed(e);
  }
 finally {
    cw.quietCleanup();
    try {
      if (generatedKey != null)       generatedKey.close();
    }
 catch (    SQLException e) {
      logger.error("Error encountered closing the ResultSet.",e);
    }
    try {
      if (ps != null)       ps.close();
    }
 catch (    SQLException e) {
      logger.error("Error encountered closing the PreparedStatement.",e);
    }
  }
  return analysisGroupInternalId;
}

@ Override public int insertUnassignedGroup ( int analysisGroup ) throws AdeException { if ( analysisGroup != UNASSIGNED_ANALYSIS_GROUP_ID ) { throw new AdeInternalException ( "This update is for unassigned analysis groups ONLY" ) ; } int analysisGroupInternalId ; analysisGroupInternalId = getUnassignedGroupInternalId ( ) ; if ( analysisGroupInternalId != 0 ) return analysisGroupInternalId ; final ConnectionWrapper cw = new ConnectionWrapper ( AdeInternal . getDefaultConnection ( ) ) ; ResultSet generatedKey = null ; PreparedStatement ps = null ; try { final int ruleId = insertUnassignedRules ( ) ; final int evaluationOrder = getNumOfGroups ( cw ) + 1 ; PreparedStatementWrapper psw = cw . preparedStatement ( "INSERT INTO " + SQL . GROUPS + " (GROUP_NAME, " + "GROUP_TYPE, DATA_TYPE, RULE_INTERNAL_ID, EVALUATION_ORDER) " + "VALUES (?,?,?,?,?)" , new String [ ] { "GROUP_INTERNAL_ID" } ) ; ps = psw . getPreparedStatement ( ) ; int pos = 1 ; ps . setString ( pos ++ , UNASSIGNED_GROUP_NAME ) ; ps . setInt ( pos ++ , UNASSIGNED_GROUP_TYPE ) ; ps . setInt ( pos ++ , UNASSIGNED_DATA_TYPE ) ; ps . setInt ( pos ++ , ruleId ) ; ps . setInt ( pos ++ , evaluationOrder ) ; ps . execute ( ) ; generatedKey = ps . getGeneratedKeys ( ) ; if ( generatedKey . next ( ) ) { analysisGroupInternalId = generatedKey . getInt ( 1 ) ; } cw . close ( ) ; } catch ( SQLException e ) { cw . failed ( e ) ; } finally { cw . quietCleanup ( ) ; try { if ( generatedKey != null ) generatedKey . close ( ) ; } catch ( SQLException e ) { logger . error ( "Error encountered closing the ResultSet." , e ) ; } try { if ( ps != null ) ps . close ( ) ; } catch ( SQLException e ) { logger . error ( "Error encountered closing the PreparedStatement." , e ) ; } } return analysisGroupInternalId ; }
this method returns the group internal id of the unassigned group . first it checks to see if the unassigned group is already in the database . if it is , it returns the internal id otherwise , we add the unassigned rule into the rules table , retrieve the rule internal id , and uses this id as one of the column values when inserting the analysis group .
