private long doSubmitForRegistration()

in CRS/src/main/java/com/epam/indigo/crs/services/registration/BingoRegistrationImpl.java [156:214]


    private long doSubmitForRegistration(String tokenHash, List<CompoundInfo> compoundInfo, long jobId) throws CRSException {
    	synchronized (insertLock) {
    		log.info("Processing registration with JobID=" + jobId);
    		
            Connection dbConnection = getConnection();
            
            try {
                if (checkTokenHash(tokenHash)) {
                    int userId = brm.getUserId(tokenHash);

                    String query = "insert into " + getDbSchema() + ".compounds(data, userId, compoundNumber, batchNumber, casNumber, saltCode, " +
                            "saltEquivalents, comments, hazardComments, storageComments, jobId, conversationalBatchNumber, stereoisomerCode) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

                    try {
                        dbConnection.setAutoCommit(false);

                        for (CompoundInfo ci : compoundInfo) {
                            PreparedStatement ps = dbConnection.prepareStatement(query);
                            ps = submitCompoundInfoForRegistration(dbConnection, ps, ci, userId, jobId);
                            ps.executeUpdate();
                            ps.close();
                        }

                        dbConnection.commit();

                        brm.setCompoundRegistrationStatus(jobId, CompoundRegistrationStatus.SUCCESSFUL);
                        log.info("Successfully registered compounds with JobID=" + jobId);
                    } catch (Throwable e) {
                        dbConnection.rollback();

                        brm.setCompoundRegistrationStatus(jobId, CompoundRegistrationStatus.FAILED);
                        log.error("Error registering compounds with JobID=" + jobId, e);
                    }

                    try {
                        dbConnection.setAutoCommit(true);

                        String bingoFlushQuery = getBingoFlushQuery();
                        if (bingoFlushQuery != null && bingoFlushQuery.length() > 0) {
                            PreparedStatement fps = dbConnection.prepareCall(bingoFlushQuery);
                            fps.execute();
                            fps.close();
                        }
                    } catch (Throwable e) {
                        log.warn("Error executing Bing Flush Query!", e);
                    }
                } else {
                    brm.setCompoundRegistrationStatus(jobId, CompoundRegistrationStatus.WRONG_TOKEN_DURING_REGISTRATION);
                    log.warn("Wrong token during registration with JobID=" + jobId);
                }

                return jobId;
            } catch (Throwable e) {
                throw new CRSException(e.getMessage(), e);
            } finally {
            	closeConnection(dbConnection);
            }
    	}
    }