org.h2.util.IOUtils Java Examples
The following examples show how to use
org.h2.util.IOUtils.
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: 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); } }
Example #10
Source File: JdbcAppenderColumnMappingPatternTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { try (Connection connection = jdbcRule.getConnection()) { final Error exception = new Error("This is a test."); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (final PrintWriter writer = new PrintWriter(outputStream)) { exception.printStackTrace(writer); } final String stackTrace = outputStream.toString(); final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testDataSourceConfig"); logger.trace("Data source logged message 01."); logger.fatal("Error from data source 02.", exception); Thread.sleep(1000); try (final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery("SELECT * FROM dsMappingLogEntry ORDER BY id")) { assertTrue("There should be at least one row.", resultSet.next()); assertEquals("The level column is not correct (1).", "FATAL", resultSet.getNString("level")); assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getNString("logger")); assertEquals("The message column is not correct (1).", "Error from data source 02.", resultSet.getString("message")); assertEquals("The exception column is not correct (1).", stackTrace, IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1)); assertFalse("There should not be two rows.", resultSet.next()); } } }
Example #11
Source File: AbstractJdbcAppenderDataSourceTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testDataSourceConfig() throws Exception { try (final Connection connection = jdbcRule.getConnectionSource().getConnection()) { final Error exception = new Error("Final error massage is fatal!"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (final PrintWriter writer = new PrintWriter(outputStream)) { exception.printStackTrace(writer); } final String stackTrace = outputStream.toString(); final long millis = System.currentTimeMillis(); final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testDataSourceConfig"); logger.trace("Data source logged message 01."); logger.fatal("Error from data source 02.", exception); try (final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery("SELECT * FROM dsLogEntry ORDER BY id")) { assertTrue("There should be at least one row.", resultSet.next()); final long date = resultSet.getTimestamp("eventDate").getTime(); assertTrue("The date should be later than pre-logging (1).", date >= millis); assertTrue("The date should be earlier than now (1).", date <= System.currentTimeMillis()); assertEquals("The literal column is not correct (1).", "Literal Value of Data Source", resultSet.getString("literalColumn")); assertEquals("The level column is not correct (1).", "FATAL", resultSet.getNString("level")); assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getNString("logger")); assertEquals("The message column is not correct (1).", "Error from data source 02.", resultSet.getString("message")); assertEquals("The exception column is not correct (1).", stackTrace, IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1)); assertFalse("There should not be two rows.", resultSet.next()); } } }
Example #12
Source File: JdbcAppenderColumnMappingLiteralTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { try (Connection connection = jdbcRule.getConnection()) { final Error exception = new Error("This is a test."); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (final PrintWriter writer = new PrintWriter(outputStream)) { exception.printStackTrace(writer); } final String stackTrace = outputStream.toString(); final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testDataSourceConfig"); logger.trace("Data source logged message 01."); logger.fatal("Error from data source 02.", exception); Thread.sleep(1000); try (final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery("SELECT * FROM dsMappingLogEntry ORDER BY id")) { assertTrue("There should be at least one row.", resultSet.next()); assertEquals("The level column is not correct (1).", "FATAL", resultSet.getNString("level")); assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getNString("logger")); assertEquals("The message column is not correct (1).", "Hello World!", resultSet.getString("message")); assertEquals("The exception column is not correct (1).", stackTrace, IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1)); assertFalse("There should not be two rows.", resultSet.next()); } } }
Example #13
Source File: SlaveServerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private HttpResponse mockResponse( int statusCode, String entityText ) throws IOException { HttpResponse resp = mock( HttpResponse.class ); StatusLine status = mock( StatusLine.class ); when( status.getStatusCode() ).thenReturn( statusCode ); when( resp.getStatusLine() ).thenReturn( status ); HttpEntity entity = mock( HttpEntity.class ); when( entity.getContent() ).thenReturn( IOUtils.getInputStream( entityText ) ); when( resp.getEntity() ).thenReturn( entity ); return resp; }
Example #14
Source File: FileTool.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
public static void unzip(File zipFile, File unzipDir) throws IOException{ try (ZipFile file = new ZipFile(zipFile)) { FileSystem fileSystem = FileSystems.getDefault(); // Get file entries Enumeration<? extends ZipEntry> entries = file.entries(); // We will unzip files in this folder String uncompressedDirectory = unzipDir.getAbsolutePath(); // Iterate over entries while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // If directory then create a new directory in uncompressed folder if (entry.isDirectory()) { Files.createDirectories( fileSystem.getPath(uncompressedDirectory + entry.getName())); } // Else create the file else { try (InputStream is = file.getInputStream(entry); BufferedInputStream bis = new BufferedInputStream(is)) { String uncompressedFileName = uncompressedDirectory + File.separator + entry.getName(); Path uncompressedFilePath = fileSystem.getPath(uncompressedFileName); // make sure directories exist Files.createDirectories(uncompressedFilePath.getParent()); Files.createFile(uncompressedFilePath); try (FileOutputStream fileOutput = new FileOutputStream(uncompressedFileName)) { IOUtils.copy(bis, fileOutput); } } } } } }
Example #15
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 #16
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 #17
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 #18
Source File: ModelUtils.java From openwebflow with BSD 2-Clause "Simplified" License | 5 votes |
public static void importModel(RepositoryService repositoryService, File modelFile) throws IOException, XMLStreamException { InputStreamReader reader = new InputStreamReader(new FileInputStream(modelFile), "utf-8"); String fileContent = IOUtils.readStringAndClose(reader, (int) modelFile.length()); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(new StringStreamSourceEx(fileContent), false, false); String processName = bpmnModel.getMainProcess().getName(); if (processName == null || processName.isEmpty()) { processName = bpmnModel.getMainProcess().getId(); } Model modelData = repositoryService.newModel(); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelData.setMetaInfo(modelObjectNode.toString()); modelData.setName(processName); modelData.setKey(modelFile.getName()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), fileContent.getBytes("utf-8")); Logger.getLogger(ModelUtils.class) .info(String.format("importing model file: %s", modelFile.getCanonicalPath())); }
Example #19
Source File: AbstractJdbcAppenderFactoryMethodTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Test public void testFactoryMethodConfig() throws Exception { try (final Connection connection = jdbcRule.getConnectionSource().getConnection()) { final SQLException exception = new SQLException("Some other error message!"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (final PrintWriter writer = new PrintWriter(outputStream)) { exception.printStackTrace(writer); } final String stackTrace = outputStream.toString(); final long millis = System.currentTimeMillis(); ThreadContext.put("some_int", "42"); final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testFactoryMethodConfig"); logger.debug("Factory logged message 01."); logger.error("Error from factory 02.", exception); try (final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery("SELECT * FROM fmLogEntry ORDER BY id")) { assertTrue("There should be at least one row.", resultSet.next()); long date = resultSet.getTimestamp("eventDate").getTime(); long anotherDate = resultSet.getTimestamp("anotherDate").getTime(); assertEquals(date, anotherDate); assertTrue("The date should be later than pre-logging (1).", date >= millis); assertTrue("The date should be earlier than now (1).", date <= System.currentTimeMillis()); assertEquals("The literal column is not correct (1).", "Some Other Literal Value", resultSet.getString("literalColumn")); assertEquals("The level column is not correct (1).", "DEBUG", resultSet.getNString("level")); assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getNString("logger")); assertEquals("The message column is not correct (1).", "Factory logged message 01.", resultSet.getString("message")); assertEquals("The exception column is not correct (1).", Strings.EMPTY, IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1)); assertTrue("There should be two rows.", resultSet.next()); date = resultSet.getTimestamp("eventDate").getTime(); anotherDate = resultSet.getTimestamp("anotherDate").getTime(); assertEquals(date, anotherDate); assertTrue("The date should be later than pre-logging (2).", date >= millis); assertTrue("The date should be earlier than now (2).", date <= System.currentTimeMillis()); assertEquals("The literal column is not correct (2).", "Some Other Literal Value", resultSet.getString("literalColumn")); assertEquals("The level column is not correct (2).", "ERROR", resultSet.getNString("level")); assertEquals("The logger column is not correct (2).", logger.getName(), resultSet.getNString("logger")); assertEquals("The message column is not correct (2).", "Error from factory 02.", resultSet.getString("message")); assertEquals("The exception column is not correct (2).", stackTrace, IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1)); assertFalse("There should not be three rows.", resultSet.next()); } } }
Example #20
Source File: MailMessageNotifier.java From openwebflow with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void afterPropertiesSet() throws Exception { _messageTemplate = IOUtils.readStringAndClose(new InputStreamReader(_messageTemplateResource.getInputStream()), (int) _messageTemplateResource.contentLength()); }