semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected void doRestoreOrganizeType() throws Exception {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        String strDelQuery = "DELETE FROM " + Common.ORGANIZE_TYPE_TABLE;
        String strSelQuery = "SELECT organize_type_id,organize_type_name,width " + "FROM " + Common.ORGANIZE_TYPE_B_TABLE + " " + "WHERE version_no = ?";
        String strInsQuery = "INSERT INTO " + Common.ORGANIZE_TYPE_TABLE + " " + "(organize_type_id,organize_type_name,width) " + "VALUES (?,?,?)";
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            try {
                con = dbo.getConnection();
                con.setAutoCommit(false);
                ps = con.prepareStatement(strDelQuery);
                ps.executeUpdate();
                ps = con.prepareStatement(strSelQuery);
                ps.setInt(1, this.versionNO);
                result = ps.executeQuery();
                ps = con.prepareStatement(strInsQuery);
                while (result.next()) {
                    ps.setString(1, result.getString("organize_type_id"));
                    ps.setString(2, result.getString("organize_type_name"));
                    ps.setInt(3, result.getInt("width"));
                    int resultCount = ps.executeUpdate();
                    if (resultCount != 1) {
                        con.rollback();
                        throw new CesSystemException("Organize_backup.doRestoreOrganizeType(): ERROR Inserting data " + "in T_SYS_ORGANIZE_TYPE INSERT !! resultCount = " + resultCount);
                    }
                }
                con.commit();
            } catch (SQLException se) {
                con.rollback();
                throw new CesSystemException("Organize_backup.doRestoreOrganizeType(): SQLException:  " + se);
            } finally {
                con.setAutoCommit(true);
                close(dbo, ps, result);
            }
        } catch (SQLException se) {
            throw new CesSystemException("Organize_backup.doRestoreOrganizeType(): SQLException while committing or rollback");
        }
    }
protected void doRestoreOrganizeTypeRelation() throws Exception {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        String strDelQuery = "DELETE FROM " + Common.ORGANIZE_TYPE_RELATION_TABLE;
        String strSelQuery = "SELECT parent_organize_type,child_organize_type " + "FROM " + Common.ORGANIZE_TYPE_RELATION_B_TABLE + " " + "WHERE version_no = ?";
        String strInsQuery = "INSERT INTO " + Common.ORGANIZE_TYPE_RELATION_TABLE + " " + "(parent_organize_type,child_organize_type) " + "VALUES (?,?)";
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            try {
                con = dbo.getConnection();
                con.setAutoCommit(false);
                ps = con.prepareStatement(strDelQuery);
                ps.executeUpdate();
                ps = con.prepareStatement(strSelQuery);
                ps.setInt(1, this.versionNO);
                result = ps.executeQuery();
                ps = con.prepareStatement(strInsQuery);
                while (result.next()) {
                    ps.setString(1, result.getString("parent_organize_type"));
                    ps.setString(2, result.getString("child_organize_type"));
                    int resultCount = ps.executeUpdate();
                    if (resultCount != 1) {
                        con.rollback();
                        throw new CesSystemException("Organize_backup.doRestoreOrganizeTypeRelation(): ERROR Inserting data " + "in T_SYS_ORGANIZE_TYPE_RELATION INSERT !! resultCount = " + resultCount);
                    }
                }
                con.commit();
            } catch (SQLException se) {
                con.rollback();
                throw new CesSystemException("Organize_backup.doRestoreOrganizeTypeRelation(): SQLException:  " + se);
            } finally {
                con.setAutoCommit(true);
                close(dbo, ps, result);
            }
        } catch (SQLException se) {
            throw new CesSystemException("Organize_backup.doRestoreOrganizeTypeRelation(): SQLException while committing or rollback");
        }
    }
protected void doRestoreOrganize() throws Exception {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        String strDelQuery = "DELETE FROM " + Common.ORGANIZE_TABLE;
        String strSelQuery = "SELECT organize_id,organize_type_id,organize_name,organize_manager," + "organize_describe,work_type,show_order,position_x,position_y " + "FROM " + Common.ORGANIZE_B_TABLE + " " + "WHERE version_no = ?";
        String strInsQuery = "INSERT INTO " + Common.ORGANIZE_TABLE + " " + "(organize_id,organize_type_id,organize_name,organize_manager," + "organize_describe,work_type,show_order,position_x,position_y) " + "VALUES (?,?,?,?,?,?,?,?,?)";
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            try {
                con = dbo.getConnection();
                con.setAutoCommit(false);
                ps = con.prepareStatement(strDelQuery);
                ps.executeUpdate();
                ps = con.prepareStatement(strSelQuery);
                ps.setInt(1, this.versionNO);
                result = ps.executeQuery();
                ps = con.prepareStatement(strInsQuery);
                while (result.next()) {
                    ps.setString(1, result.getString("organize_id"));
                    ps.setString(2, result.getString("organize_type_id"));
                    ps.setString(3, result.getString("organize_name"));
                    ps.setString(4, result.getString("organize_manager"));
                    ps.setString(5, result.getString("organize_describe"));
                    ps.setString(6, result.getString("work_type"));
                    ps.setInt(7, result.getInt("show_order"));
                    ps.setInt(8, result.getInt("position_x"));
                    ps.setInt(9, result.getInt("position_y"));
                    int resultCount = ps.executeUpdate();
                    if (resultCount != 1) {
                        con.rollback();
                        throw new CesSystemException("Organize_backup.doRestoreOrganize(): ERROR Inserting data " + "in T_SYS_ORGANIZE INSERT !! resultCount = " + resultCount);
                    }
                }
                con.commit();
            } catch (SQLException se) {
                con.rollback();
                throw new CesSystemException("Organize_backup.doRestoreOrganize(): SQLException:  " + se);
            } finally {
                con.setAutoCommit(true);
                close(dbo, ps, result);
            }
        } catch (SQLException se) {
            throw new CesSystemException("Organize_backup.doRestoreOrganize(): SQLException while committing or rollback");
        }
    }
protected void doRestoreOrganizeRelation() throws Exception {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet result = null;
        String strDelQuery = "DELETE FROM " + Common.ORGANIZE_RELATION_TABLE;
        String strSelQuery = "SELECT organize_id,organize_type_id,child_id,child_type_id,remark " + "FROM " + Common.ORGANIZE_RELATION_B_TABLE + " " + "WHERE version_no = ?";
        String strInsQuery = "INSERT INTO " + Common.ORGANIZE_RELATION_TABLE + " " + "(organize_id,organize_type,child_id,child_type,remark) " + "VALUES (?,?,?,?,?)";
        DBOperation dbo = factory.createDBOperation(POOL_NAME);
        try {
            try {
                con = dbo.getConnection();
                con.setAutoCommit(false);
                ps = con.prepareStatement(strDelQuery);
                ps.executeUpdate();
                ps = con.prepareStatement(strSelQuery);
                ps.setInt(1, this.versionNO);
                result = ps.executeQuery();
                ps = con.prepareStatement(strInsQuery);
                while (result.next()) {
                    ps.setString(1, result.getString("organize_id"));
                    ps.setString(2, result.getString("organize_type_id"));
                    ps.setString(3, result.getString("child_id"));
                    ps.setString(4, result.getString("child_type_id"));
                    ps.setString(5, result.getString("remark"));
                    int resultCount = ps.executeUpdate();
                    if (resultCount != 1) {
                        con.rollback();
                        throw new CesSystemException("Organize_backup.doRestoreOrganizeRelation(): ERROR Inserting data " + "in T_SYS_ORGANIZE_RELATION INSERT !! resultCount = " + resultCount);
                    }
                }
                con.commit();
            } catch (SQLException se) {
                con.rollback();
                throw new CesSystemException("Organize_backup.doRestoreOrganizeRelation(): SQLException:  " + se);
            } finally {
                con.setAutoCommit(true);
                close(dbo, ps, result);
            }
        } catch (SQLException se) {
            throw new CesSystemException("Organize_backup.doRestoreOrganizeRelation(): SQLException while committing or rollback");
        }
    }
protected void removeMessage(ReplicationMessage message) {
        logger.info(String.format("remove replication message: %d", message.getId()));
        ConnectionProvider cp = null;
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            SessionFactoryImplementor impl = (SessionFactoryImplementor) portalDao.getSessionFactory();
            cp = impl.getConnectionProvider();
            conn = cp.getConnection();
            conn.setAutoCommit(false);
            ps = conn.prepareStatement("delete from light_replication_message where id=?");
            ps.setLong(1, message.getId());
            ps.executeUpdate();
            conn.commit();
            ps.close();
            conn.close();
        } catch (Exception e) {
            try {
                conn.rollback();
                ps.close();
                conn.close();
            } catch (Exception se) {
            }
        }
    }
protected void syncMessages(Message message) {
        if (message.getEvent() == Event.CONNECT || message.getEvent() == Event.SYNC_DONE) return;
        logger.info(String.format("remove stale replication messages: %s", message.toString()));
        String className = "";
        long classId = 0;
        if (message.getBody() instanceof Entity) {
            Entity entity = (Entity) message.getBody();
            className = entity.getClass().getName();
            classId = entity.getId();
        }
        ConnectionProvider cp = null;
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            SessionFactoryImplementor impl = (SessionFactoryImplementor) portalDao.getSessionFactory();
            cp = impl.getConnectionProvider();
            conn = cp.getConnection();
            conn.setAutoCommit(false);
            ps = conn.prepareStatement("delete from light_replication_message where event=? and className=? and classId=?");
            ps.setString(1, message.getEvent().toString());
            ps.setString(2, className);
            ps.setLong(3, classId);
            ps.executeUpdate();
            conn.commit();
            ps.close();
            conn.close();
        } catch (Exception e) {
            try {
                conn.rollback();
                ps.close();
                conn.close();
            } catch (Exception se) {
            }
        }
    }
private List getPluginClassList(List pluginFileList) {
        ArrayList l = new ArrayList();
        for (Iterator i = pluginFileList.iterator(); i.hasNext(); ) {
            URL url = (URL) i.next();
            log.debug("Trying file " + url.toString());
            try {
                BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
                String line;
                while ((line = r.readLine()) != null) {
                    line = line.trim();
                    if (line.length() == 0 || line.charAt(0) == '#') continue;
                    l.add(line);
                }
            } catch (Exception e) {
                log.warn("Could not load " + url, e);
            }
        }
        return l;
    }
public URLConnection makeURLcon() {
        URI uri;
        URL url;
        try {
            uri = new URI(this.URLString);
            url = uri.toURL();
            this.urlcon = (HttpURLConnection) url.openConnection();
        } catch (final URISyntaxException e) {
            e.printStackTrace();
        } catch (final MalformedURLException e) {
            e.printStackTrace();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return this.urlcon;
    }
private static BufferedReader createReaderConnection(String urlString) throws SiteNotFoundException {
        BufferedReader reader = null;
        try {
            URL url = new URL(urlString);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("User-agent", "Mozilla/4.5");
            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                Logger.logln("Response code for url [" + urlString + "] was " + conn.getResponseCode() + " [" + conn.getResponseMessage() + "]");
                throw new SiteNotFoundException(urlString);
            }
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        } catch (IOException ex) {
            Logger.logln("" + ex);
        }
        return reader;
    }
private void inject(int x, int y) throws IOException {
            Tag source = data.getTag();
            Log.event(Log.DEBUG_INFO, "source: " + source.getString());
            if (source == Tag.ORGANISM) {
                String seed = data.readString();
                data.readTag(Tag.STREAM);
                injectCodeTape(data.getIn(), seed, x, y);
            } else if (source == Tag.URL) {
                String url = data.readString();
                String seed = url.substring(url.lastIndexOf('.') + 1);
                BufferedReader urlIn = null;
                try {
                    urlIn = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
                    injectCodeTape(urlIn, seed, x, y);
                } finally {
                    if (urlIn != null) urlIn.close();
                }
            } else data.writeString("unknown organism source: " + source.getString());
        }
@Override
    public void incluir(Igreja igreja) throws Exception {
        Connection connection = criaConexao(false);
        String sql = "insert into igreja ? as idlocal, ? as possui_salao;";
        String sql2 = "SELECT MAX(idlocal) FROM Local";
        PreparedStatement stmt = null;
        PreparedStatement stmt2 = null;
        ResultSet rs = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt2 = connection.prepareStatement(sql2);
            rs = stmt2.executeQuery();
            stmt.setInt(1, rs.getInt("max"));
            stmt.setBoolean(2, igreja.getPossuiSalao());
            int retorno = stmt.executeUpdate();
            if (retorno == 0) {
                connection.rollback();
                throw new SQLException("Ocorreu um erro inesperado no momento de inserir dados de cliente no banco!");
            }
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                stmt2.close();
                rs.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }
public int create(BusinessObject o) throws DAOException {
        int insert = 0;
        int id = 0;
        Project project = (Project) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("INSERT_PROJECT"));
            pst.setString(1, project.getName());
            pst.setString(2, project.getDescription());
            pst.setInt(3, project.getIdAccount());
            pst.setInt(4, project.getIdContact());
            insert = pst.executeUpdate();
            if (insert <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (insert > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select max(id_project) from project");
            rs.next();
            id = rs.getInt(1);
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return id;
    }
public int delete(BusinessObject o) throws DAOException {
        int delete = 0;
        Project project = (Project) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("DELETE_PROJECT"));
            pst.setInt(1, project.getId());
            delete = pst.executeUpdate();
            if (delete <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (delete > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return delete;
    }
public int update(BusinessObject o) throws DAOException {
        int update = 0;
        Project project = (Project) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("UPDATE_PROJECT"));
            pst.setString(1, project.getName());
            pst.setString(2, project.getDescription());
            pst.setInt(3, project.getIdAccount());
            pst.setInt(4, project.getIdContact());
            pst.setBoolean(5, project.isArchived());
            pst.setInt(6, project.getId());
            update = pst.executeUpdate();
            if (update <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (update > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return update;
    }
public static void testMapSource(MapSource mapSource, EastNorthCoordinate coordinate) {
        try {
            System.out.println("Testing " + mapSource.toString());
            int zoom = mapSource.getMinZoom() + ((mapSource.getMaxZoom() - mapSource.getMinZoom()) / 2);
            MapSpace mapSpace = mapSource.getMapSpace();
            int tilex = mapSpace.cLonToX(coordinate.lon, zoom) / mapSpace.getTileSize();
            int tiley = mapSpace.cLatToY(coordinate.lat, zoom) / mapSpace.getTileSize();
            url = new URL(mapSource.getTileUrl(zoom, tilex, tiley));
            System.out.println("Sample url: " + url);
            c = (HttpURLConnection) url.openConnection();
            System.out.println("Connecting...");
            c.connect();
            System.out.println("Connection established - response HTTP " + c.getResponseCode());
            if (c.getResponseCode() != 200) return;
            String contentType = c.getContentType();
            System.out.print("Image format          : ");
            if ("image/png".equals(contentType)) System.out.println("png"); else if ("image/jpeg".equals(contentType)) System.out.println("jpg"); else System.out.println("unknown");
            String eTag = c.getHeaderField("ETag");
            boolean eTagSupported = (eTag != null);
            if (eTagSupported) {
                System.out.println("eTag                  : " + eTag);
                testIfNoneMatch();
            } else System.out.println("eTag                  : -");
            long date = c.getDate();
            if (date == 0) System.out.println("Date time             : -"); else System.out.println("Date time             : " + new Date(date));
            long exp = c.getExpiration();
            if (exp == 0) System.out.println("Expiration time       : -"); else System.out.println("Expiration time       : " + new Date(exp));
            long modified = c.getLastModified();
            if (modified == 0) System.out.println("Last modified time    : not set"); else System.out.println("Last modified time    : " + new Date(modified));
            testIfModified();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n");
    }
private static void testIfNoneMatch() throws Exception {
        String eTag = c.getHeaderField("ETag");
        InputStream in = c.getInputStream();
        byte[] buffer = new byte[1024];
        int read = 0;
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        do {
            read = in.read(buffer);
            if (read > 0) md5.update(buffer, 0, read);
        } while (read < 0);
        byte[] digest = md5.digest();
        String hexDigest = getHexString(digest);
        if (hexDigest.equals(eTag)) System.out.print("eTag content          : md5 hex string");
        String quotedHexDigest = "\"" + hexDigest + "\"";
        if (quotedHexDigest.equals(eTag)) System.out.print("eTag content          : quoted md5 hex string");
        HttpURLConnection c2 = (HttpURLConnection) url.openConnection();
        c2.addRequestProperty("If-None-Match", eTag);
        c2.connect();
        int code = c2.getResponseCode();
        System.out.print("If-None-Match response: ");
        boolean supported = (code == 304);
        System.out.println(b2s(supported) + " - " + code + " (" + c2.getResponseMessage() + ")");
    }
private static void testIfModified() throws IOException {
        HttpURLConnection c2 = (HttpURLConnection) url.openConnection();
        c2.setIfModifiedSince(System.currentTimeMillis() + 1000);
        c2.connect();
        int code = c2.getResponseCode();
        System.out.print("If-Modified-Since     : ");
        boolean supported = (code == 304);
        System.out.println(b2s(supported) + " - " + code + " (" + c2.getResponseMessage() + ")");
    }