本文整理了Java中javax.inject.Provider
类的一些代码示例,展示了Provider
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Provider
类的具体详情如下:
包路径:javax.inject.Provider
类名称:Provider
[英]Provides instances of T. Typically implemented by an injector. For any type T that can be injected, you can also inject Provider. Compared to injecting T directly, injecting Provider enables:
For example:
class Car {
@Inject Car(Provider<Seat> seatProvider) {
Seat driver = seatProvider.get();
Seat passenger = seatProvider.get();
...
}
}
[中]
代码示例来源:origin: dropwizard/dropwizard
@Override
public void writeTo(T entity,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> responseHeaders,
OutputStream entityStream)
throws IOException, WebApplicationException {
final MessageBodyWriter<U> writer = requireNonNull(mbw).get().getMessageBodyWriter(representation,
representation, annotations, contentType);
// Fix the headers, because Dropwizard error mappers always set the content type to APPLICATION_JSON
responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, contentType);
writer.writeTo(getRepresentation(entity), representation, representation, annotations,
contentType, responseHeaders, entityStream);
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-workspace
@Override
@Transactional
public Page<WorkspaceImpl> getWorkspaces(String userId, int maxItems, long skipCount)
throws ServerException {
try {
final List<WorkspaceImpl> list =
managerProvider
.get()
.createNamedQuery("Workspace.getAll", WorkspaceImpl.class)
.setMaxResults(maxItems)
.setFirstResult((int) skipCount)
.getResultList()
.stream()
.map(WorkspaceImpl::new)
.collect(Collectors.toList());
final long count =
managerProvider
.get()
.createNamedQuery("Workspace.getAllCount", Long.class)
.getSingleResult();
return new Page<>(list, skipCount, maxItems, count);
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-installer
@Override
@Transactional
public List<String> getVersions(String id) throws InstallerException {
try {
return managerProvider
.get()
.createNamedQuery("Inst.getAllById", InstallerImpl.class)
.setParameter("id", id)
.getResultList()
.stream()
.map(InstallerImpl::getVersion)
.collect(Collectors.toList());
} catch (RuntimeException x) {
throw new InstallerException(x.getMessage(), x);
}
}
代码示例来源:origin: Netflix/metacat
@Override
public Map<String, List<QualifiedName>> getByUris(final String sourceName, final List<String> uris,
final boolean prefixSearch) {
final StringBuilder builder = new StringBuilder(SQL_GET_TABLE_NAMES_BY_URIS);
if (prefixSearch) {
builder.append(" and ( 1=0");
uris.forEach(uri -> builder.append(" or uri like '").append(uri).append("%'"));
builder.append(")");
} else {
builder.append(" and uri in (:uris)");
}
final Query query = em.get().createNativeQuery(builder.toString());
query.setParameter("sourceName", sourceName);
if (!prefixSearch) {
query.setParameter("uris", uris);
}
final List<Object[]> result = query.getResultList();
return result.stream().collect(Collectors.groupingBy(o -> (String) o[2], Collectors
.mapping(o -> QualifiedName.ofTable(sourceName, (String) o[0], (String) o[1]), Collectors.toList())));
}
}
代码示例来源:origin: Netflix/metacat
@Override
public Long count(final String sourceName, final String databaseName, final String tableName) {
final TypedQuery<Long> query = em.get().createNamedQuery(Partition.NAME_QUERY_GET_COUNT_FOR_TABLE,
Long.class);
query.setParameter("sourceName", sourceName);
query.setParameter("databaseName", databaseName);
query.setParameter("tableName", tableName);
return query.getSingleResult();
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-workspace
@Override
@Transactional
public WorkspaceImpl get(String id) throws NotFoundException, ServerException {
requireNonNull(id, "Required non-null id");
try {
final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id);
if (workspace == null) {
throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id));
}
return new WorkspaceImpl(workspace);
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
代码示例来源:origin: Netflix/metacat
@Override
public List<Database> getBySourceDatabaseNames(final String sourceName, final List<String> databaseNames) {
final TypedQuery<Database> query = em.get().createNamedQuery(Database.NAME_QUERY_GET_BY_SOURCE_DATABASE_NAMES,
Database.class);
query.setParameter("sourceName", sourceName);
query.setParameter("databaseNames", databaseNames);
return query.getResultList();
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-ssh
@Transactional
protected void doCreate(SshPairImpl entity) {
EntityManager manager = managerProvider.get();
manager.persist(entity);
manager.flush();
}
代码示例来源:origin: Netflix/eureka
@Override
public Supplier<Boolean> get() {
final EurekaUpStatusResolver resolver = upStatus.get();
return new Supplier<Boolean>() {
@Override
public Boolean get() {
return !resolver.getStatus().equals(InstanceInfo.InstanceStatus.UP);
}
};
}
}
代码示例来源:origin: org.eclipse.che.multiuser/che-multiuser-api-resource
@Transactional
protected void doRemove(String id) {
final EntityManager manager = managerProvider.get();
final FreeResourcesLimitImpl resourcesLimit = manager.find(FreeResourcesLimitImpl.class, id);
if (resourcesLimit != null) {
manager.remove(resourcesLimit);
manager.flush();
}
}
代码示例来源:origin: Netflix/metacat
@Override
public List<Table> searchBySourceDatabaseTableName(final String sourceName, final String databaseName,
final String tableNamePrefix, final Sort sort, final Pageable pageable) {
final StringBuilder queryBuilder = new StringBuilder(SQL_SEARCH_TABLES);
if (sort != null && sort.hasSort()) {
queryBuilder.append(" order by ").append(sort.getSortBy()).append(" ").append(sort.getOrder().name());
}
final TypedQuery<Table> query = em.get().createQuery(queryBuilder.toString(), Table.class);
query.setParameter("sourceName", sourceName);
query.setParameter("databaseName", databaseName);
query.setParameter("isTableNameNull", tableNamePrefix == null ? 1 : 0);
query.setParameter("tableName", tableNamePrefix + "%");
if (pageable != null && pageable.isPageable()) {
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getLimit());
}
return query.getResultList();
}
代码示例来源:origin: Netflix/metacat
@Override
public List<T> get(final Iterable<Long> ids) {
final EntityManager entityManager = em.get();
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<T> criteriaQuery = cb.createQuery(getEntityClass());
final Root<T> root = criteriaQuery.from(getEntityClass());
criteriaQuery.where(root.get("id").in(Lists.newArrayList(ids)));
return entityManager.createQuery(criteriaQuery).getResultList();
}
代码示例来源:origin: Netflix/metacat
@Override
@SuppressFBWarnings
public T getByName(final String name) {
T result = null;
Preconditions.checkArgument(name != null, "Name cannot be null.");
final TypedQuery<T> query = em.get()
.createQuery(String.format(SQL_GET_BY_NAME, getEntityClass().getName()), getEntityClass());
query.setParameter("name", name);
try {
result = query.getSingleResult();
} catch (Exception ignored) { }
return result;
}
代码示例来源:origin: Netflix/metacat
@Override
public long count() {
return (long) em.get().createQuery("select count(a) from " + getEntityClass().getName() + " a")
.getSingleResult();
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-installer
@Transactional
protected void doRemove(InstallerFqn fqn) {
final EntityManager manager = managerProvider.get();
InstallerImpl installer =
manager
.createNamedQuery("Inst.getByKey", InstallerImpl.class)
.setParameter("id", fqn.getId())
.setParameter("version", fqn.getVersion())
.getSingleResult();
manager.remove(installer);
manager.flush();
}
代码示例来源:origin: Netflix/metacat
@Override
public T get(final Long id) {
Preconditions.checkArgument(id != null, "Id cannot be null.");
return em.get().find(getEntityClass(), id);
}
代码示例来源:origin: org.eclipse.che.multiuser/che-multiuser-api-resource
private long getTotalCount() throws ServerException {
return managerProvider
.get()
.createNamedQuery("FreeResourcesLimit.getTotalCount", Long.class)
.getSingleResult();
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-installer
@Override
@Transactional
public Page<InstallerImpl> getAll(int maxItems, long skipCount) throws InstallerException {
checkArgument(maxItems >= 0, "The number of items to return can't be negative.");
checkArgument(
skipCount >= 0 && skipCount <= Integer.MAX_VALUE,
"The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE);
try {
final List<InstallerImpl> list =
managerProvider
.get()
.createNamedQuery("Inst.getAll", InstallerImpl.class)
.setMaxResults(maxItems)
.setFirstResult((int) skipCount)
.getResultList();
return new Page<>(list, skipCount, maxItems, getTotalCount());
} catch (RuntimeException x) {
throw new InstallerException(x.getMessage(), x);
}
}
代码示例来源:origin: Netflix/metacat
@Override
public void delete(final T entity) {
Preconditions.checkArgument(entity != null, "Entity cannot be null.");
final EntityManager entityManager = em.get();
entityManager.remove(entity);
}
代码示例来源:origin: Netflix/metacat
@Override
public void deleteByNames(final String sourceName, final String databaseName, final String tableName,
final List<String> partitionNames) {
final Query query = em.get().createNamedQuery(Partition.NAME_QUERY_DELETE_BY_PARTITION_NAMES);
query.setParameter("sourceName", sourceName);
query.setParameter("databaseName", databaseName);
query.setParameter("tableName", tableName);
query.setParameter("partitionNames", partitionNames);
query.executeUpdate();
}
内容来源于网络,如有侵权,请联系作者删除!