本文整理汇总了Java中io.dropwizard.hibernate.UnitOfWork类的典型用法代码示例。如果您正苦于以下问题:Java UnitOfWork类的具体用法?Java UnitOfWork怎么用?Java UnitOfWork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitOfWork类属于io.dropwizard.hibernate包,在下文中一共展示了UnitOfWork类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: search
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@Path(SEARCH_ENDPOINT)
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Timed
@UnitOfWork
public Response search(
@NotNull @Auth User user,
@NotNull @Valid SearchRequest searchRequest) {
LOGGER.debug("Received search request");
return performWithAuthorisation(
user,
searchRequest.getQuery().getDataSource(),
() -> Response.ok(hBaseClient.query(searchRequest)).build());
}
开发者ID:gchq,项目名称:stroom-stats,代码行数:17,代码来源:QueryResource.java
示例2: createWebSocket
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@Override
@UnitOfWork
public Object createWebSocket(
ServletUpgradeRequest servletUpgradeRequest,
ServletUpgradeResponse servletUpgradeResponse) {
String path = servletUpgradeRequest.getRequestPath();
if(!StringUtils.isEmpty(path)) {
String[] paths = servletUpgradeRequest.getRequestPath().split("/");
String userID = paths[paths.length - 1];
try {
long id = Long.parseLong(userID);
Optional<User> optionalUser = userRepository.getUserWithGroups(id);
if (optionalUser.isPresent())
return new ChatSocketListener(optionalUser.get(), this.messageHandler);
log.error("Invalid user id was passed in");
} catch (NumberFormatException exception) {
log.error("Value passed in for user id is not a number", exception);
}
}
return null;
}
开发者ID:tosinoni,项目名称:SECP,代码行数:26,代码来源:ChatSocketCreator.java
示例3: authenticate
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@Override
@UnitOfWork
public Optional<User> authenticate(String token) throws AuthenticationException {
String username;
try {
username = tokenController.getUsernameFromToken(token);
} catch (InvalidJwtException e) {
throw new AuthenticationException(e);
}
if (StringUtils.isBlank(username)) {
LOG.error("Username is blank.");
return Optional.empty();
} else {
User user = userDAO.findByUserName(username);
return Optional.ofNullable(user);
}
}
开发者ID:tosinoni,项目名称:SECP,代码行数:20,代码来源:SECPAuthenticator.java
示例4: getByRegion
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@GET
@UnitOfWork
@Timed
@ExceptionMetered
@JsonView(Views.Public.class)
public SearchResults getByRegion(@BeanParam SearchCriteria searchCriteria) throws IOException {
boolean shouldGetDataFromOpendataServer = !searchCriteria.getUser().isPresent();
if (shouldGetDataFromOpendataServer) {
return getFromOpendata(searchCriteria);
}
validateBean(searchCriteria);
// TODO add sorting
return searchService.searchByCriteria(searchCriteria);
}
开发者ID:blstream,项目名称:AugumentedSzczecin_java,代码行数:17,代码来源:SearchResource.java
示例5: getOffers
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
/**
* Find all offers that belong to a particular driver.
* @param showActiveAndNotFullOnly if false this method will return all offers that belong to a driver,
* otherwise only those which are active (not disable due to timeouts etc.)
* and are not full (passengers can still join). Default is true.
*/
@GET
@Path(PATH_OFFERS)
@UnitOfWork
public List<TripOffer> getOffers(@Auth User driver, @DefaultValue("true") @QueryParam("active") boolean showActiveAndNotFullOnly) {
List<TripOffer> offers = new ArrayList<>(tripsManager.findOffersByDriver(driver));
if (!showActiveAndNotFullOnly) return offers;
// filter by active status
Iterator<TripOffer> iterator = offers.iterator();
while (iterator.hasNext()) {
TripOffer offer = iterator.next();
if (!offer.getStatus().equals(TripOfferStatus.ACTIVE)) iterator.remove();
else if (tripsUtils.getActivePassengerCountForOffer(offer) >= offer.getVehicle().getCapacity()) iterator.remove();
}
return offers;
}
开发者ID:AMOS-2015,项目名称:amos-ss15-proj2,代码行数:24,代码来源:TripsResource.java
示例6: authenticate
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@UnitOfWork
public Optional<User> authenticate(final BasicCredentials basicCredentials) throws AuthenticationException {
String email = basicCredentials.getUsername();
String plaintextPassword = basicCredentials.getPassword();
final Optional<User> user = userDao.findByEmail(email);
if (user.isPresent()) {
final User existingUser = user.get();
checkState(existingUser.getPassword() != null, "Cannot authenticate: user with id: %s (email: %s) without password",
existingUser.getId(), existingUser.getEmail());
if (isMatched(plaintextPassword, existingUser.getPassword())) {
return user;
}
}
return Optional.absent();
}
开发者ID:blstream,项目名称:AugumentedSzczecin_java,代码行数:19,代码来源:BasicAuthenticator.java
示例7: cancelActiveSuperTrips
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@PUT
@UnitOfWork
@Path(PATH_SUPER_TRIP + "/cancel")
public void cancelActiveSuperTrips( @Auth User passenger ){
List<SuperTrip> superTrips = tripsManager.findAllActiveTrips(passenger);
for( SuperTrip superTrip : superTrips ) {
for( JoinTripRequest request : superTrip.getJoinRequests() ) {
JoinTripStatus status = request.getStatus();
if (status.equals(JoinTripStatus.PASSENGER_IN_CAR) || status.equals(JoinTripStatus.PASSENGER_AT_DESTINATION))
throw RestUtils.createJsonFormattedException("cannot cancel when in car or at destination", 409);
assertUserIsPassenger(request, passenger);
}
tripsManager.updateSuperTripPassengerCancel(superTrip);
}
}
开发者ID:AMOS-2015,项目名称:amos-ss15-proj2,代码行数:17,代码来源:TripsResource.java
示例8: getRun
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@GET
@Path("/{runId}")
@UnitOfWork
@ApiOperation(value = "Get a specific run")
@ApiResponses({
@ApiResponse(code = HttpStatus.OK_200, response = RunApiEntity.class, message = "OK"),
@ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
@ApiResponse(
code = HttpStatus.CONFLICT_409,
response = ErrorMessage.class,
message = "Event ID and Run ID are mismatched"
)
})
public RunApiEntity getRun(
@PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
@PathParam("runId") @ApiParam(value = "Run ID", required = true) String runId
) throws EntityMismatchException, EntityNotFoundException {
Run domainRun = runEntityService.getByEventIdAndRunId(eventId, runId);
return runMapper.toApiEntity(domainRun);
}
开发者ID:caeos,项目名称:coner-core,代码行数:21,代码来源:EventRunsResource.java
示例9: addHandicapGroupToHandicapGroupSet
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@Path("/{handicapGroupSetId}/handicapGroups/{handicapGroupId}")
@UnitOfWork
@ApiOperation(value = "Add a Handicap Group to a Handicap Group Set", response = HandicapGroupSetApiEntity.class)
@ApiResponses({
@ApiResponse(code = HttpStatus.OK_200, response = HandicapGroupSetApiEntity.class, message = "OK"),
@ApiResponse(code = HttpStatus.NOT_FOUND_404, response = ErrorMessage.class, message = "Not found"),
})
public HandicapGroupSetApiEntity addHandicapGroupToHandicapGroupSet(
@PathParam("handicapGroupSetId") @ApiParam(value = "Handicap Group Set ID", required = true)
String handicapGroupSetId,
@PathParam("handicapGroupId") @ApiParam(value = "Handicap Group ID", required = true)
String handicapGroupId
) throws EntityNotFoundException {
HandicapGroupSet domainSetEntity = handicapGroupSetService.getById(handicapGroupSetId);
HandicapGroup domainEntity = handicapGroupEntityService.getById(handicapGroupId);
handicapGroupSetService.addToHandicapGroups(domainSetEntity, domainEntity);
return handicapGroupSetMapper.toApiEntity(domainSetEntity);
}
开发者ID:caeos,项目名称:coner-core,代码行数:20,代码来源:HandicapGroupSetsResource.java
示例10: computePendingNavigationResultForOffer
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
/**
* Get the {@link org.croudtrip.api.directions.NavigationResult} for an offer containing a not
* yet accepted additionally provided {@link JoinTripRequest}. The result will contain a complete
* route visiting all the passengers pick-up and destination locations as well as a list of all
* the waypoints in the correct order of the current trip.
* @param offerId The offer the navigation result should be computed for
* @param joinRequestId the not yet accepted join trip request ({@link JoinTripStatus#PASSENGER_ACCEPTED})
* which should be included into the navigation result.
* @return A navigation result that contains the route and waypoints for all the passengers
* especially of the additionally provided request.
*/
@GET
@Path(PATH_OFFERS + "/{offerId}/navigation/{joinRequestId}")
@UnitOfWork
public NavigationResult computePendingNavigationResultForOffer(@PathParam("offerId") long offerId, @PathParam("joinRequestId") long joinRequestId) throws RouteNotFoundException {
TripOffer offer = assertIsValidOfferId( offerId );
Optional<JoinTripRequest> request = tripsManager.findJoinRequest(joinRequestId);
if (!request.isPresent()) throw RestUtils.createNotFoundException();
if( request.get().getStatus() != JoinTripStatus.PASSENGER_ACCEPTED )
throw RestUtils.createJsonFormattedException("Request must have status PASSENGER_ACCEPTED.", 409);
SuperTripSubQuery subQuery = request.get().getSubQuery();
TripQuery origQuery = request.get().getSuperTrip().getQuery();
TripQuery query = new TripQuery( null, subQuery.getStartLocation(), subQuery.getDestinationLocation(), origQuery.getMaxWaitingTimeInSeconds(), origQuery.getCreationTimestamp(), origQuery.getPassenger() );
return tripsNavigationManager.getNavigationResultForOffer( offer, query );
}
开发者ID:AMOS-2015,项目名称:amos-ss15-proj2,代码行数:31,代码来源:TripsResource.java
示例11: findByParent
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@GET
@UnitOfWork
@Path("/{parentId}")
public List<Long> findByParent(@PathParam("parentId") Long parentId) {
List<AnomalyFunctionRelation> result = dao.findByParent(parentId);
if (result.isEmpty()) {
throw new NotFoundException();
}
List<Long> childIds = new ArrayList<>();
for (AnomalyFunctionRelation relation : result) {
childIds.add(relation.getChildId());
}
return childIds;
}
开发者ID:Hanmourang,项目名称:Pinot,代码行数:17,代码来源:AnomalyFunctionRelationResource.java
示例12: put
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@PUT
@Timed
@UnitOfWork
@ExceptionMetered
public User put(@Auth User existingUser, User user) {
if (user.getPassword() != null) {
final PasswordHashed passwordHashed = PasswordEncoder.encode(user.getPassword());
existingUser.setSalt(passwordHashed.salt());
existingUser.setPassword(passwordHashed.encodedPassword());
}
if (user.getRole() != null) {
existingUser.setRole(user.getRole());
}
if (user.getUsername() != null) {
throw new IllegalArgumentException("You cannot update username");
}
_userDao.save(existingUser);
return existingUser;
}
开发者ID:adelolmo,项目名称:biblio-server,代码行数:21,代码来源:UserResource.java
示例13: createBook
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@Timed
@UnitOfWork
public Response createBook(@Auth User user, @Context UriInfo info, Book book) {
final Book persistedBook;
try {
book.setUser(user);
persistedBook = _bookDao.save(book);
String uri = String.format("%s/%s", info.getAbsolutePath().getPath(), persistedBook.getId());
return Response.created(URI.create(uri)).build();
} catch (Exception e) {
LOGGER.error("Error on creating book.", e);
formatAndThrow(LOGGER, Response.Status.CONFLICT, String.format("Book with isbn %s already exists", book.getIsbn()));
return null;
}
}
开发者ID:adelolmo,项目名称:biblio-server,代码行数:17,代码来源:BookResource.java
示例14: login
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@UnitOfWork
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response login(@Context ContainerRequestContext requestContext, @NotNull @Valid Credentials credentials) {
JwtCookiePrincipal principal = sessionService.startSession(credentials, requestContext);
try {
// Sleep for a while to avoid brute-force attacks
Thread.sleep(500);
} catch (InterruptedException e) {
LOGGER.debug("Unexpected interruption while sleeping", e);
}
if (principal == null) {
return Response.status(Response.Status.UNAUTHORIZED).build();
} else {
return Response.ok(ResponseContainer.fromSuccessful(principal)).build();
}
}
开发者ID:jhendess,项目名称:metadict,代码行数:21,代码来源:SessionResource.java
示例15: register
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
/**
* Register a new user account. The given {@link RegistrationRequestData} must be valid, i.e. matching bean
* constraints or the registration will be blocked.
*
* @param registrationRequestData
* The registration request.
* @return Either a response with {@link javax.ws.rs.core.Response.Status#ACCEPTED} if the registration was
* successful or either 422 if any validation errors occurred or {@link javax.ws.rs.core.Response.Status#CONFLICT}
* if the user already exists. If the registration was successful, the user will also be logged in automatically.
*/
@POST
@UnitOfWork
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response register(@Valid @NotNull RegistrationRequestData registrationRequestData) {
Optional<User> newUser = this.userService.createNewUser(registrationRequestData.getName(), registrationRequestData.getPassword());
Response.ResponseBuilder responseBuilder;
if (!newUser.isPresent()) {
responseBuilder = Response.status(Response.Status.CONFLICT).entity(ResponseContainer.withStatus(ResponseStatus.DUPLICATE));
} else {
Optional<User> user = this.userService.authenticateWithPassword(registrationRequestData.getName(),
registrationRequestData.getPassword());
if (user.isPresent() && Objects.equals(newUser.get(), user.get())) {
responseBuilder = Response.accepted(ResponseContainer.withStatus(ResponseStatus.OK));
} else {
// This should never happen
responseBuilder = Response.serverError();
LOGGER.error("User authentication after registration failed");
}
}
return responseBuilder.build();
}
开发者ID:jhendess,项目名称:metadict,代码行数:34,代码来源:RegistrationResource.java
示例16: getLoggedQueries
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
/**
* Returns the logged queries for the currently authenticated user.
*
* @param offset
* The offset for logged queries.
* @param size
* The total size of queries to return. If zero, all entries will be returned.
* @return A list containing the logged queries. If no user is currently authenticated, the list will be empty.
*/
@NotNull
@UnitOfWork
public List<QueryLogEntry> getLoggedQueries(@NotNull Principal principal, int offset, int size) {
checkArgument(offset >= 0, "Offset must be greater than zero or equal");
checkArgument(size > 0, "Size must be greater than zero");
List<QueryLogEntry> result;
Optional<PersistedUser> user = userService.findPersistedUserByName(principal.getName());
if (user.isPresent()) {
result = readQueryLog(user.get(), offset, size);
} else {
LOGGER.warn("User {} doesn't exist", principal.getName());
result = new ArrayList<>();
}
return result;
}
开发者ID:jhendess,项目名称:metadict,代码行数:27,代码来源:QueryLoggingService.java
示例17: notifySession
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@Override
@UnitOfWork
public void notifySession(MessageDTO message, IMessageReceiver receiver) {
long groupID = message.getGroupId();
long senderID = receiver.getUser().getId();
MessageDTO savedMessage = saveMessage(message, receiver);
for(IMessageReceiver messageReceiver: activeGroups.get(groupID)) {
long receiverID = messageReceiver.getUser().getId();
if (receiverID != senderID)
messageReceiver.updateUser(savedMessage);
}
}
开发者ID:tosinoni,项目名称:SECP,代码行数:13,代码来源:ChatSocketHandler.java
示例18: registerAdmin
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@Path("{id}")
@UnitOfWork
public Response registerAdmin(@PathParam("id") String id) {
adminController.registerAdmin(id);
return Response.status(Response.Status.OK).build();
}
开发者ID:tosinoni,项目名称:SECP,代码行数:8,代码来源:AdminResource.java
示例19: removeAdmin
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@DELETE
@Path("{id}")
@UnitOfWork
public Response removeAdmin(@Auth @PathParam("id") String id) {
adminController.removeAdmin(id);
return Response.status(Response.Status.OK).build();
}
开发者ID:tosinoni,项目名称:SECP,代码行数:8,代码来源:AdminResource.java
示例20: create
import io.dropwizard.hibernate.UnitOfWork; //导入依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Timed
@UnitOfWork
@Path("/register")
public Response create(UserRegistrationRequest request) {
return userRegistrationController.registerUser(request);
}
开发者ID:tosinoni,项目名称:SECP,代码行数:10,代码来源:AdminResource.java
注:本文中的io.dropwizard.hibernate.UnitOfWork类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论