public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue())!=null) { removeAccessToken(token.getValue()); } String bid = getAuthorizationDetail(authentication).get("bid"); String pid = getAuthorizationDetail(authentication).get("pid"); jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()), new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getOAuth2Request().getClientId(), new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken),bid,pid}, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR,Types.VARCHAR,Types.VARCHAR }); }
private void addExternalIds() { FudgeMsgEnvelope env = s_fudgeContext.toFudgeMsg(ExternalId.of("A", "B")); byte[] bytes = s_fudgeContext.toByteArray(env.getMessage()); String cls = ExternalId.class.getName(); LobHandler lobHandler = new DefaultLobHandler(); final JdbcOperations template = _cfgMaster.getDbConnector().getJdbcOperations(); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 101, 101, toSqlTimestamp(_version1aInstant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1aInstant), MAX_SQL_TIMESTAMP, "TestConfig101", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 102, 102, toSqlTimestamp(_version1bInstant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1bInstant), MAX_SQL_TIMESTAMP, "TestConfig102", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 201, 201, toSqlTimestamp(_version1cInstant), toSqlTimestamp(_version2Instant), toSqlTimestamp(_version1cInstant), MAX_SQL_TIMESTAMP, "TestConfig201", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 202, 201, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, "TestConfig202", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); _totalExternalIds = 3; }
private void addExternalIdBundles() { FudgeMsgEnvelope env = s_fudgeContext.toFudgeMsg(ExternalIdBundle.of(ExternalId.of("C", "D"), ExternalId.of("E", "F"))); byte[] bytes = s_fudgeContext.toByteArray(env.getMessage()); String cls = ExternalIdBundle.class.getName(); LobHandler lobHandler = new DefaultLobHandler(); final JdbcOperations template = _cfgMaster.getDbConnector().getJdbcOperations(); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 301, 301, toSqlTimestamp(_version1aInstant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1aInstant), MAX_SQL_TIMESTAMP, "TestConfig301", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 302, 302, toSqlTimestamp(_version1bInstant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version1bInstant), MAX_SQL_TIMESTAMP, "TestConfig302", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 401, 401, toSqlTimestamp(_version1cInstant), toSqlTimestamp(_version2Instant), toSqlTimestamp(_version1cInstant), MAX_SQL_TIMESTAMP, "TestConfig401", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); template.update("INSERT INTO cfg_config VALUES (?,?,?,?,?, ?,?,?,?)", 402, 401, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, toSqlTimestamp(_version2Instant), MAX_SQL_TIMESTAMP, "TestConfig402", cls, new SqlParameterValue(Types.BLOB, new SqlLobValue(bytes, lobHandler))); _totalBundles = 3; }
public void storeAccessToken(AccessToken token, Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue())!=null) { removeAccessToken(token.getValue()); } jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()), new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication), authentication.getUser().getUsername(), authentication.getClientDetails().getClientId(), new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken) }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); }
private MapSqlParameterSource getCompleteParameters() { MapSqlParameterSource tcParameters = getInitialDataParameters(); tcParameters.addValues(getGuidParameter().getValues()); tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp()); int warningTime = testSuite.getWarningTime(); tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null); int criticalTime = testSuite.getCriticalTime(); tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null); tcParameters.addValue("duration", testSuite.getDuration()); //try to save the screenshot try { if (testSuite.getScreenShotPath() != null) { final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath()); final int length = (int) testSuite.getScreenShotPath().toFile().length(); tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB); } } catch (IOException e) { throw new RuntimeException(e); } tcParameters.addValue("msg", testSuite.getExceptionMessages(false)); return tcParameters; }
/** * Determine the first available screenshot inside of the testcase and respectively in the assigned steps. * For Details of the transformation, see {@link org.springframework.jdbc.support.lob.LobHandler}. * * @return a {@link SqlLobValue} */ protected SqlLobValue getScreenshotAsSqlLobValue(TestCase testCase) { try { Path screenShotPath = testCase.getScreenShotPath(); if (screenShotPath == null) { //get first step exception for (TestCaseStep step : testCase.getStepsAsSortedSet()) { if (step.getScreenShotPath() != null) { screenShotPath = step.getScreenShotPath(); break; } } } if (screenShotPath != null) { final InputStream blobIs = Files.newInputStream(screenShotPath); final int length = (int) screenShotPath.toFile().length(); return new SqlLobValue(blobIs, length, lobHandler); } return null; } catch (IOException e) { throw new RuntimeException(e); } }
private void storeRawSecurityDetail(RawSecurity security) { final DbMapSqlParameterSource rawArgs = createParameterSource() .addValue("security_id", extractRowId(security.getUniqueId())) .addValue("raw_data", new SqlLobValue(security.getRawData(), getDialect().getLobHandler()), Types.BLOB); final String sqlRaw = getElSqlBundle().getSql("InsertRaw", rawArgs); getJdbcTemplate().update(sqlRaw, rawArgs); }
@Override protected ConfigDocument insert(ConfigDocument document) { ArgumentChecker.notNull(document.getName(), "document.name"); ArgumentChecker.notNull(document.getConfig(), "document.value"); ArgumentChecker.notNull(document.getType(), "document.type"); Timer.Context context = _insertTimer.time(); try { final Object value = document.getConfig().getValue(); final long docId = nextId("cfg_config_seq"); final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId); // set the uniqueId final UniqueId uniqueId = createUniqueId(docOid, docId); document.setUniqueId(uniqueId); if (value instanceof MutableUniqueIdentifiable) { ((MutableUniqueIdentifiable) value).setUniqueId(uniqueId); } byte[] bytes = serializeToFudge(value); // the arguments for inserting into the config table final DbMapSqlParameterSource docArgs = createParameterSource() .addValue("doc_id", docId) .addValue("doc_oid", docOid) .addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("name", document.getName()) .addValue("config_type", document.getType().getName()) .addValue("config", new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB); final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs); getJdbcTemplate().update(sqlDoc, docArgs); return document; } finally { context.stop(); } }
/** * Inserts a new document. * * @param document the document, not null * @return the new document, not null */ @Override protected MarketDataSnapshotDocument insert(final MarketDataSnapshotDocument document) { long docId = nextId("snp_snapshot_seq"); long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId); // set the uniqueId (needs to go in Fudge message) UniqueId uniqueId = createUniqueId(docOid, docId); document.setUniqueId(uniqueId); // Copy the snapshot adding in the unique id NamedSnapshot snapshot = document.getNamedSnapshot().withUniqueId(uniqueId); // Replace the snapshot in the document so it is available to the caller document.setNamedSnapshot(snapshot); // the arguments for inserting into the marketDataSnapshot table FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(snapshot); byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage()); DbMapSqlParameterSource snapshotArgs = createParameterSource() .addValue("doc_id", docId) .addValue("doc_oid", docOid).addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("name", document.getName()) .addValue("snapshot_type", document.getNamedSnapshot().getClass().getName()) .addValue("detail", new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB); String sql = getElSqlBundle().getSql("Insert", snapshotArgs); getJdbcTemplate().update(sql, snapshotArgs); return document; }
private Object blob(String name, ExternalIdBundle bundle) { MockLegalEntity value = new MockLegalEntity(name, bundle, Currency.GBP); String xml = JodaBeanSer.COMPACT.xmlWriter().write(value); byte[] bytes = ZipUtils.deflateString(xml); SqlLobValue lob = new SqlLobValue(bytes, getDbConnector().getDialect().getLobHandler()); return new SqlParameterValue(Types.BLOB, lob); }
private Object blob(String name, ExternalIdBundle bundle) { MockConvention value = new MockConvention(name, bundle, Currency.GBP); String xml = JodaBeanSerialization.serializer(false).xmlWriter().write(value); byte[] bytes = ZipUtils.deflateString(xml); SqlLobValue lob = new SqlLobValue(bytes, getDbConnector().getDialect().getLobHandler()); return new SqlParameterValue(Types.BLOB, lob); }
private Object blob(String name, ExternalIdBundle bundle) { EquitySecurity value = new EquitySecurity("LONDON", "LON", "LSE", Currency.GBP); value.setName(name); value.setExternalIdBundle(bundle); String xml = JodaBeanSerialization.serializer(false).xmlWriter().write(value); byte[] bytes = ZipUtils.deflateString(xml); SqlLobValue lob = new SqlLobValue(bytes, getDbConnector().getDialect().getLobHandler()); return new SqlParameterValue(Types.BLOB, lob); }
@Test public void testGetScreenshotAsSqlLobValue() throws Exception { Path screenshotPath = Paths.get(this.getClass().getResource("computer.png").toURI()); TestCase testCase = new TestCaseExampleBuilder() .withException(new SakuliExceptionWithScreenshot("test-exception", screenshotPath)) .buildExample(); SqlLobValue result = testling.getScreenshotAsSqlLobValue(testCase); assertNotNull(result); }
@Test public void testGetScreenshotAsSqlLobValueTestCase() throws Exception { Path screenshotPath = Paths.get(this.getClass().getResource("computer.png").toURI()); TestCase testCase = new TestCaseExampleBuilder() .withException(null) .withTestCaseSteps(Collections.singletonList( new TestCaseStepExampleBuilder() .withException(new SakuliExceptionWithScreenshot("test-exception", screenshotPath)) .buildExample() )).buildExample(); SqlLobValue result = testling.getScreenshotAsSqlLobValue(testCase); assertNotNull(result); }
public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { removeAccessToken(resource, authentication); jdbcTemplate.update( insertAccessTokenSql, new Object[] { accessToken.getValue(), new SqlLobValue(SerializationUtils.serialize(accessToken)), keyGenerator.extractKey(resource, authentication), authentication.getName(), resource.getClientId() }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); }
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()), new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getOAuth2Request().getClientId(), new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken) }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); }
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { jdbcTemplate.update(insertRefreshTokenSql, new Object[] { extractTokenKey(refreshToken.getValue()), new SqlLobValue(serializeRefreshToken(refreshToken)), new SqlLobValue(serializeAuthentication(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB, Types.BLOB }); }
/** * Inserts a new document. * * @param document the document, not null * @return the new document, not null */ @Override protected ExchangeDocument insert(final ExchangeDocument document) { ArgumentChecker.notNull(document.getExchange(), "document.exchange"); ArgumentChecker.notNull(document.getName(), "document.name"); final ManageableExchange exchange = document.getExchange(); final long docId = nextId("exg_exchange_seq"); final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId); // set the uniqueId (needs to go in Fudge message) final UniqueId uniqueId = createUniqueId(docOid, docId); exchange.setUniqueId(uniqueId); document.setUniqueId(uniqueId); // the arguments for inserting into the exchange table FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(exchange); byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage()); final DbMapSqlParameterSource docArgs = createParameterSource() .addValue("doc_id", docId) .addValue("doc_oid", docOid) .addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("name", document.getName()) .addValue("time_zone", exchange.getTimeZone() != null ? exchange.getTimeZone().getId() : null, Types.VARCHAR) .addValue("detail", new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB); // the arguments for inserting into the idkey tables final List<DbMapSqlParameterSource> assocList = new ArrayList<DbMapSqlParameterSource>(); final List<DbMapSqlParameterSource> idKeyList = new ArrayList<DbMapSqlParameterSource>(); final String sqlSelectIdKey = getElSqlBundle().getSql("SelectIdKey"); for (ExternalId id : exchange.getExternalIdBundle()) { final DbMapSqlParameterSource assocArgs = createParameterSource() .addValue("doc_id", docId) .addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); assocList.add(assocArgs); if (getJdbcTemplate().queryForList(sqlSelectIdKey, assocArgs).isEmpty()) { // select avoids creating unecessary id, but id may still not be used final long idKeyId = nextId("exg_idkey_seq"); final DbMapSqlParameterSource idkeyArgs = createParameterSource() .addValue("idkey_id", idKeyId) .addValue("key_scheme", id.getScheme().getName()) .addValue("key_value", id.getValue()); idKeyList.add(idkeyArgs); } } final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs); final String sqlIdKey = getElSqlBundle().getSql("InsertIdKey"); final String sqlDoc2IdKey = getElSqlBundle().getSql("InsertDoc2IdKey"); getJdbcTemplate().update(sqlDoc, docArgs); getJdbcTemplate().batchUpdate(sqlIdKey, idKeyList.toArray(new DbMapSqlParameterSource[idKeyList.size()])); getJdbcTemplate().batchUpdate(sqlDoc2IdKey, assocList.toArray(new DbMapSqlParameterSource[assocList.size()])); return document; }
/** * Inserts a new document. * * @param document the document, not null * @return the new document, not null */ protected D insert(final D document) { @SuppressWarnings("unchecked") V value = (V) document.getValue(); ArgumentChecker.notNull(value, "document.value"); final String name = getCallback().getName(value); final ExternalIdBundle externalIdBundle = getCallback().getExternalIdBundle(value); final Map<String, String> attributes = getCallback().getAttributes(value); final Map<String, String> indexedProperties = getCallback().getIndexedProperties(value); final Character mainType = getCallback().getMainType(value); final String subType = getCallback().getSubType(value); final String actualType = getCallback().getActualType(value); final byte[] packedData = getCallback().getPackedData(value); ArgumentChecker.notNull(name, "document.value.name"); ArgumentChecker.notNull(externalIdBundle, "document.value.externalIdBundle"); ArgumentChecker.notNull(attributes, "document.value.attributes"); ArgumentChecker.notNull(subType, "document.value.subType"); ArgumentChecker.notNull(actualType, "document.value.actualType"); try (Timer.Context context = _insertTimer.time()) { final long docId = nextId(_sequenceDocument); final long docOid = (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId); // the arguments for inserting into the table final DbMapSqlParameterSource docArgs = createParameterSource() .addValue("doc_id", docId) .addValue("doc_oid", docOid) .addTimestamp("ver_from_instant", document.getVersionFromInstant()) .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant()) .addTimestamp("corr_from_instant", document.getCorrectionFromInstant()) .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant()) .addValue("name", name) .addValue("main_type", mainType.toString()) // need String not Character for SQL server .addValue("sub_type", subType) .addValue("actual_type", actualType) .addValue("packed_data", new SqlLobValue(packedData, getDialect().getLobHandler()), Types.BLOB); // store document final String sqlDoc = getElSqlBundle().getSql("Insert", docArgs); getJdbcTemplate().update(sqlDoc, docArgs); // store idkey and attributes if (externalIdBundle.size() > 0) { insertIdKey(docId, externalIdBundle); } if (attributes.size() > 0) { insertMap(docId, attributes, _sequenceAttribute, "Attr"); } if (indexedProperties.size() > 0) { insertMap(docId, indexedProperties, _sequenceProperties, "Prop"); } // set the uniqueId final UniqueId uniqueId = createUniqueId(docOid, docId); IdUtils.setInto(value, uniqueId); document.setUniqueId(uniqueId); return document; } }
public void storeRefreshToken(RefreshToken refreshToken, Authentication authentication) { jdbcTemplate.update(insertRefreshTokenSql, new Object[] { extractTokenKey(refreshToken.getValue()), new SqlLobValue(serializeRefreshToken(refreshToken)), new SqlLobValue(serializeAuthentication(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB, Types.BLOB }); }
@Override protected void store(String code, OAuth2Authentication authentication) { jdbcTemplate.update(insertAuthenticationSql, new Object[] { code, new SqlLobValue(SerializationUtils.serialize(authentication)) }, new int[] { Types.VARCHAR, Types.BLOB }); }