Java Code Examples for org.h2.util.IOUtils#closeSilently()
The following examples show how to use
org.h2.util.IOUtils#closeSilently() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
private void createSchema() { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); stmt.addBatch("create table if not exists rp(id varchar(36) primary key, data varchar(50000))"); stmt.addBatch("create table if not exists expired_objects( " + this.expiredObjectColumnName + " varchar(50), value varchar(50000), type varchar(20), iat TIMESTAMP NULL DEFAULT NULL, exp TIMESTAMP NULL DEFAULT NULL)"); stmt.executeBatch(); stmt.close(); conn.commit(); LOG.debug("Schema created successfully."); } catch (Exception e) { LOG.error("Failed to create schema. Error: " + e.getMessage(), e); rollbackSilently(conn); throw new RuntimeException(e); } finally { IOUtils.closeSilently(conn); } }
Example 2
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean createExpiredObject(ExpiredObject obj) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("insert into expired_objects(" + this.expiredObjectColumnName + ", value, type, iat, exp) values(?, ?, ?, ?, ?)"); query.setString(1, obj.getKey().trim()); query.setString(2, obj.getValue().trim()); query.setString(3, obj.getType().getValue()); query.setTimestamp(4, new Timestamp(obj.getIat().getTime())); query.setTimestamp(5, new Timestamp(obj.getExp().getTime())); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("Expired_object created successfully. Object : " + obj.getKey()); return true; } catch (Exception e) { LOG.error("Failed to create Expired_object: " + obj.getKey(), e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 3
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean create(Rp rp) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("insert into rp(id, data) values(?, ?)"); query.setString(1, rp.getOxdId()); query.setString(2, Jackson2.serializeWithoutNulls(rp)); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("RP created successfully. RP : " + rp); return true; } catch (Exception e) { LOG.error("Failed to create RP: " + rp, e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 4
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean update(Rp rp) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("update rp set data = ? where id = ?"); query.setString(1, Jackson2.serializeWithoutNulls(rp)); query.setString(2, rp.getOxdId()); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("RP updated successfully. RP : " + rp); return true; } catch (Exception e) { LOG.error("Failed to update RP: " + rp, e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 5
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean removeAllRps() { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("delete from rp"); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("All RPs are removed successfully."); return true; } catch (Exception e) { LOG.error("Failed to drop all RPs", e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 6
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
@Override public boolean remove(String oxdId) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("delete from rp where id = ?"); query.setString(1, oxdId); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("Removed rp successfully. oxdId: " + oxdId); return true; } catch (Exception e) { LOG.error("Failed to remove rp with oxdId: " + oxdId, e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 7
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean deleteExpiredObjectsByKey(String key) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("delete from expired_objects where " + this.expiredObjectColumnName + " = ?"); query.setString(1, key); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("Removed expired_objects successfully: " + key); return true; } catch (Exception e) { LOG.error("Failed to remove expired_objects: " + key, e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 8
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 6 votes |
public boolean deleteAllExpiredObjects() { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("delete from expired_objects where exp < CURRENT_TIMESTAMP()"); query.executeUpdate(); query.close(); conn.commit(); LOG.debug("Removed expired_objects successfully. "); return true; } catch (Exception e) { LOG.error("Failed to remove expired_objects. ", e); rollbackSilently(conn); return false; } finally { IOUtils.closeSilently(conn); } }
Example 9
Source File: DeploymentTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @CmmnDeployment public void testCaseDefinitionDI() throws Exception { org.flowable.cmmn.api.repository.CmmnDeployment cmmnDeployment = cmmnRepositoryService.createDeploymentQuery().singleResult(); assertThat(cmmnDeployment).isNotNull(); List<String> resourceNames = cmmnRepositoryService.getDeploymentResourceNames(cmmnDeployment.getId()); assertThat(resourceNames).hasSize(2); String resourceName = "org/flowable/cmmn/test/repository/DeploymentTest.testCaseDefinitionDI.cmmn"; String diagramResourceName = "org/flowable/cmmn/test/repository/DeploymentTest.testCaseDefinitionDI.caseB.png"; assertThat(resourceNames).contains(resourceName, diagramResourceName); InputStream inputStream = cmmnRepositoryService.getResourceAsStream(cmmnDeployment.getId(), resourceName); assertThat(inputStream).isNotNull(); IOUtils.closeSilently(inputStream); InputStream diagramInputStream = cmmnRepositoryService.getResourceAsStream(cmmnDeployment.getId(), diagramResourceName); assertThat(diagramInputStream).isNotNull(); IOUtils.closeSilently(diagramInputStream); CaseDefinition caseDefinition = cmmnRepositoryService.createCaseDefinitionQuery().deploymentId(cmmnDeployment.getId()).singleResult(); InputStream caseDiagramInputStream = cmmnRepositoryService.getCaseDiagram(caseDefinition.getId()); assertThat(caseDiagramInputStream).isNotNull(); IOUtils.closeSilently(caseDiagramInputStream); }
Example 10
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 5 votes |
public Rp getRp(String oxdId) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("select id, data from rp where id = ?"); query.setString(1, oxdId); ResultSet rs = query.executeQuery(); rs.next(); String data = rs.getString("data"); query.close(); conn.commit(); Rp rp = MigrationService.parseRp(data); if (rp != null) { LOG.debug("Found RP id: " + oxdId + ", RP : " + rp); return rp; } else { LOG.error("Failed to fetch RP by id: " + oxdId); return null; } } catch (Exception e) { LOG.error("Failed to find RP by id: " + oxdId + ". Error: " + e.getMessage(), e); rollbackSilently(conn); return null; } finally { IOUtils.closeSilently(conn); } }
Example 11
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 5 votes |
public ExpiredObject getExpiredObject(String key) { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("select " + this.expiredObjectColumnName + ", value, type, iat, exp from expired_objects where " + this.expiredObjectColumnName + " = ?"); query.setString(1, key.trim()); ResultSet rs = query.executeQuery(); ExpiredObject expiredObject = null; rs.next(); if (!Strings.isNullOrEmpty(rs.getString("key"))) { expiredObject = new ExpiredObject(rs.getString("key"), ExpiredObjectType.fromValue(rs.getString("type")), rs.getDate("iat"), rs.getDate("exp")); } query.close(); conn.commit(); if (expiredObject != null) { LOG.debug("Found ExpiredObject: " + expiredObject.getKey()); return expiredObject; } else { LOG.error("ExpiredObject not found: " + key); return expiredObject; } } catch (Exception e) { LOG.error("Failed to find ExpiredObject: " + key + ". Error: " + e.getMessage(), e); rollbackSilently(conn); return null; } finally { IOUtils.closeSilently(conn); } }
Example 12
Source File: SqlPersistenceServiceImpl.java From oxd with Apache License 2.0 | 5 votes |
public Set<Rp> getRps() { Connection conn = null; try { conn = provider.getConnection(); conn.setAutoCommit(false); PreparedStatement query = conn.prepareStatement("select id, data from rp"); ResultSet rs = query.executeQuery(); Set<Rp> result = new HashSet<>(); while (rs.next()) { String id = rs.getString("id"); String data = rs.getString("data"); Rp rp = MigrationService.parseRp(data); if (rp != null) { result.add(rp); } else { LOG.error("Failed to parse rp, id: " + id); } } query.close(); conn.commit(); LOG.info("Loaded " + result.size() + " RPs."); return result; } catch (Exception e) { LOG.error("Failed to fetch rps. Error: " + e.getMessage(), e); rollbackSilently(conn); throw new RuntimeException(e); } finally { IOUtils.closeSilently(conn); } }