List of usage examples for org.springframework.jdbc.core.support SqlLobValue SqlLobValue
public SqlLobValue(@Nullable String content)
From source file:nl.surfnet.coin.api.oauth.OpenConextOauth2JdbcTokenStore.java
@Override public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { AuthorizationRequest authorizationRequest = authentication.getAuthorizationRequest(); String clientId = authorizationRequest.getClientId(); ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId); if (!(clientDetails instanceof OpenConextClientDetails)) { throw new RuntimeException("The clientDetails is of the type '" + (clientDetails != null ? clientDetails.getClass() : "null") + "'. Required is a (sub)class of ExtendedBaseClientDetails"); }// www .java 2s . c om ClientMetaData clientMetaData = ((OpenConextClientDetails) clientDetails).getClientMetaData(); String refreshToken = null; if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } String value = extractTokenKey(token.getValue()); jdbcTemplate.update(ACCESS_TOKEN_INSERT_STATEMENT, new Object[] { value, new SqlLobValue(SerializationUtils.serialize(token)), authenticationKeyGenerator.extractKey(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getAuthorizationRequest().getClientId(), clientMetaData.getAppEntityId(), new SqlLobValue(SerializationUtils.serialize(authentication)), refreshToken }, new int[] { Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
public void add(StateInfoBase<T> info, String collectionTypeName) { if (collectionTypeName == null) throw new IllegalArgumentException("Cannot add null collection type to collection."); if (info == null) throw new IllegalArgumentException("Cannot add null info object to collection."); if (info.getId() == null) throw new IllegalArgumentException("Cannot add info object with null id to collection."); try {//from w ww . j ava2 s . c o m Object[] params = new Object[] { info.getId(), collectionTypeName, info.getVersionId(), info.getLastUsedTime(), info.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(info)), }; int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB }; getJdbcTemplate().update(INSERT_SQL, params, types); } catch (DataIntegrityViolationException e) { throw new IllegalArgumentException( String.format("Info %s already exists in database, use replaceDialog instead", info.getId()), e); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot add info %s to database", info.getId()), e); } }
From source file:com.bt.aloha.dao.ConferenceInfoDaoImpl.java
private List<Object> createParams(ConferenceInfo conferenceInfo) { List<Object> result = new Vector<Object>(); result.add(conferenceInfo.getId());/* w ww . java 2 s . c o m*/ result.add(conferenceInfo.getSimpleSipBeanId()); result.add(conferenceInfo.getCreateTime()); result.add(conferenceInfo.getVersionId()); result.add(conferenceInfo.getLastUsedTime()); result.add(conferenceInfo.getStartTime()); result.add(conferenceInfo.getEndTime()); result.add(conferenceInfo.getMediaServerAddress()); result.add(readEnum(conferenceInfo.getConferenceState())); result.add(readEnum(conferenceInfo.getConferenceTerminationCause())); result.add(conferenceInfo.getMaxNumberOfParticipants()); result.add(conferenceInfo.getMaxDurationInMinutes()); result.add(conferenceInfo.isHousekeepForced()); result.add(new SqlLobValue(conferenceInfo.getParticipants().toString())); return result; }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
public void replace(final T info) { if (info == null) throw new IllegalArgumentException("Cannot replace null info object in collection."); T newInfo = info.cloneObject();/*from w w w. j a va2s.co m*/ newInfo.updateVersionId(); newInfo.updateLastUsedTime(); int updated = 0; try { Object[] params = new Object[] { newInfo.getVersionId(), newInfo.getLastUsedTime(), newInfo.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(newInfo)), info.getId(), info.getVersionId(), }; int[] types = new int[] { Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB, Types.VARCHAR, Types.VARCHAR }; updated = getJdbcTemplate().update(UPDATE_SQL, params, types); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot update info %s in database", info.getId()), e); } if (updated == 0) throw new ConcurrentUpdateException(info.getId(), String.format("Info %s modified in database, try again", info.getId())); info.setVersionId(newInfo.getVersionId()); info.setLastUsedTime(newInfo.getLastUsedTime()); }
From source file:com.bt.aloha.dao.CallInfoDaoImpl.java
private List<Object> createParams(CallInfo callInfo) { List<Object> result = new Vector<Object>(); result.add(callInfo.getId());/*from ww w . ja v a 2s . co m*/ result.add(callInfo.getClass().getName()); result.add(callInfo.getSimpleSipBeanId()); result.add(callInfo.getCreateTime()); result.add(callInfo.getStartTime()); result.add(callInfo.getEndTime()); result.add(callInfo.getVersionId()); result.add(callInfo.getLastUsedTime()); result.add(readEnum(callInfo.getCallState())); result.add(callInfo.getFirstDialogId()); result.add(callInfo.getSecondDialogId()); result.add(readEnum(callInfo.getFirstCallLegConnectionState())); result.add(readEnum(callInfo.getSecondCallLegConnectionState())); result.add(readEnum(callInfo.getMediaNegotiationState())); result.add(readEnum(callInfo.getMediaNegotiationMethod())); result.add(callInfo.getMaxDurationInMinutes()); result.add(readEnum(callInfo.getAutoTerminate())); result.add(readEnum(callInfo.getCallTerminationCause())); result.add(readEnum(callInfo.getCallLegCausingTermination())); result.add( null == callInfo.getPendingCallReinvite() ? null : callInfo.getPendingCallReinvite().getDialogId()); result.add(null == callInfo.getPendingCallReinvite() ? null : callInfo.getPendingCallReinvite().getRemoteContact()); result.add(null == callInfo.getPendingCallReinvite() ? false : callInfo.getPendingCallReinvite().getOfferInOkResponse()); result.add(null == callInfo.getPendingCallReinvite() ? false : callInfo.getPendingCallReinvite().getAutoTerminate()); result.add(null == callInfo.getPendingCallReinvite() ? null : null == callInfo.getPendingCallReinvite().getMediaDescription() ? null : new SqlLobValue(objectSerialiser .serialise(callInfo.getPendingCallReinvite().getMediaDescription()))); result.add(null == callInfo.getPendingCallReinvite() ? null : callInfo.getPendingCallReinvite().getApplicationData()); result.add(callInfo.isHousekeepForced()); return result; }
From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
public void saveOAuthTokensForUserId(String userId, String email, Map<String, OAuthConsumerToken> tokens) { HashMap<String, OAuthConsumerToken> hashMapForTokens = new HashMap<String, OAuthConsumerToken>(); hashMapForTokens.putAll(tokens);//from w w w. ja va2 s. co m SqlLobValue blob = new SqlLobValue(SerializationUtils.serialize(hashMapForTokens)); if (email != null) { jdbcTemplate.update(saveAccessTokensForUser, new Object[] { userId, email, blob }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.BLOB }); } else { jdbcTemplate.update(saveAccessTokensForUserWithoutEmail, new Object[] { userId, blob }, new int[] { Types.VARCHAR, Types.BLOB }); } }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenStore.java
@Override public String createAuthorizationCode(OAuth2Authentication authentication) { final int max_tries = 3; performExpirationClean();//from ww w . ja v a 2 s . c om JdbcTemplate template = new JdbcTemplate(dataSource); int tries = 0; while ((tries++) <= max_tries) { try { String code = generator.generate(); long expiresAt = System.currentTimeMillis() + getExpirationTime(); String userId = authentication.getUserAuthentication() == null ? null : ((UaaPrincipal) authentication.getUserAuthentication().getPrincipal()).getId(); String clientId = authentication.getOAuth2Request().getClientId(); SqlLobValue data = new SqlLobValue(serializeOauth2Authentication(authentication)); int updated = template.update(SQL_INSERT_STATEMENT, new Object[] { code, userId, clientId, expiresAt, data }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.BLOB }); if (updated == 0) { throw new DataIntegrityViolationException("[oauth_code] Failed to insert code. Result was 0"); } return code; } catch (DataIntegrityViolationException exists) { if (tries >= max_tries) throw exists; } } return null; }