/** * nullToZero. * @param value value * @return nullToZero */ private static Double nullToZero(Double value) { return !Objects.isNull(value) ? value : 0; }
/** * nullToZero. * @param value value * @return nullToZero */ private static Long nullToZero(Long value) { return !Objects.isNull(value) ? value : 0; }
public boolean isClusterNameUnique(String appId, String clusterName) { Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(clusterName, "ClusterName must not be null"); return Objects.isNull(clusterRepository.findByAppIdAndName(appId, clusterName)); }
public boolean isNamespaceUnique(String appId, String cluster, String namespace) { Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(cluster, "Cluster must not be null"); Objects.requireNonNull(namespace, "Namespace must not be null"); return Objects.isNull( namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, cluster, namespace)); }
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(namespaceName, "Namespace must not be null"); return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName)); }
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(namespaceName, "Namespace must not be null"); return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName)); }
public boolean isAppIdUnique(String appId) { Objects.requireNonNull(appId, "AppId must not be null"); return Objects.isNull(appRepository.findByAppId(appId)); }
@SuppressWarnings("unchecked") public static <T> ValueGenerator<T> get(final Class<T> type) { final ValueGenerator<?> valueGeneratorSupplier = generators.get( type ); if ( Objects.isNull( valueGeneratorSupplier ) ) { throw new HibernateException( "Unsupported property type [" + type.getName() + "] for @CreationTimestamp or @UpdateTimestamp generator annotation" ); } return (ValueGenerator<T>) valueGeneratorSupplier; } }
@Override public Release loadConfig(String clientAppId, String clientIp, String configAppId, String configClusterName, String configNamespace, String dataCenter, ApolloNotificationMessages clientMessages) { // load from specified cluster fist if (!Objects.equals(ConfigConsts.CLUSTER_NAME_DEFAULT, configClusterName)) { Release clusterRelease = findRelease(clientAppId, clientIp, configAppId, configClusterName, configNamespace, clientMessages); if (!Objects.isNull(clusterRelease)) { return clusterRelease; } } // try to load via data center if (!Strings.isNullOrEmpty(dataCenter) && !Objects.equals(dataCenter, configClusterName)) { Release dataCenterRelease = findRelease(clientAppId, clientIp, configAppId, dataCenter, configNamespace, clientMessages); if (!Objects.isNull(dataCenterRelease)) { return dataCenterRelease; } } // fallback to default release return findRelease(clientAppId, clientIp, configAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, configNamespace, clientMessages); }
@Override public Boolean updateRetry(final String id, final Integer retry, final String appName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) { return false; } final String tableName = RepositoryPathUtils.buildDbTableName(appName); String sqlBuilder = String.format("update %s set retried_count = %d,last_time= '%s' where trans_id =%s", tableName, retry, DateUtils.getCurrentDateTime(), id); jdbcTemplate.execute(sqlBuilder); return Boolean.TRUE; }
@Override public void removeAttachments(String groupId, String unitId) { GroupCache groupCache = transactionInfoMap.get(groupId); if (Objects.isNull(groupCache)) { return; } groupCache.getUnits().remove(unitId); if (groupCache.getUnits().size() == 0) { transactionInfoMap.remove(groupId); } }
private void test() { TestCls thisVar = this; if (Objects.isNull(thisVar)) { System.out.println("null"); } thisVar.method(); thisVar.field = 123; }
@Override public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) { final ModelId modelId = entityDescriptor.id(); final Collector collector = collectorService.find(modelId.id()); if (isNull(collector)) { LOG.debug("Couldn't find collector {}", entityDescriptor); return Optional.empty(); } return Optional.of(exportNativeEntity(collector, entityDescriptorIds)); } }
@Override public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) { final ModelId modelId = entityDescriptor.id(); final Configuration configuration = configurationService.find(modelId.id()); if (isNull(configuration)) { LOG.debug("Couldn't find collector configuration {}", entityDescriptor); return Optional.empty(); } return Optional.of(exportNativeEntity(configuration, entityDescriptorIds)); }
@Override public void deleteByFields(List<Field> fields) throws TxLoggerException { if (Objects.isNull(dbHelper)) { throw new TxLoggerException("系统日志被禁用"); } StringBuilder sql = new StringBuilder("delete from t_logger where 1=1 and "); List<String> values = whereSqlAppender(sql, fields); dbHelper.update(sql.toString(), values.toArray(new Object[0])); }
/** * @param clientAppId the application which uses public config * @param namespace the namespace * @param dataCenter the datacenter */ private Release findPublicConfig(String clientAppId, String clientIp, String clusterName, String namespace, String dataCenter, ApolloNotificationMessages clientMessages) { AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespace); //check whether the namespace's appId equals to current one if (Objects.isNull(appNamespace) || Objects.equals(clientAppId, appNamespace.getAppId())) { return null; } String publicConfigAppId = appNamespace.getAppId(); return configService.loadConfig(clientAppId, clientIp, publicConfigAppId, clusterName, namespace, dataCenter, clientMessages); }
@Transactional @PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @PostMapping(value = "/consumers") public ConsumerToken createConsumer(@RequestBody Consumer consumer, @RequestParam(value = "expires", required = false) @DateTimeFormat(pattern = "yyyyMMddHHmmss") Date expires) { if (StringUtils.isContainEmpty(consumer.getAppId(), consumer.getName(), consumer.getOwnerName(), consumer.getOrgId())) { throw new BadRequestException("Params(appId、name、ownerName、orgId) can not be empty."); } Consumer createdConsumer = consumerService.createConsumer(consumer); if (Objects.isNull(expires)) { expires = DEFAULT_EXPIRES; } return consumerService.generateAndSaveConsumerToken(createdConsumer, expires); }
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @PostMapping("/server/config") public ServerConfig createOrUpdate(@Valid @RequestBody ServerConfig serverConfig) { String modifiedBy = userInfoHolder.getUser().getUserId(); ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey()); if (Objects.isNull(storedConfig)) {//create serverConfig.setDataChangeCreatedBy(modifiedBy); serverConfig.setDataChangeLastModifiedBy(modifiedBy); serverConfig.setId(0L);//为空,设置ID 为0,jpa执行新增操作 return serverConfigRepository.save(serverConfig); } else {//update BeanUtils.copyEntityProperties(serverConfig, storedConfig); storedConfig.setDataChangeLastModifiedBy(modifiedBy); return serverConfigRepository.save(storedConfig); } }
/** * 插入 OR 更新 */ public boolean insertOrUpdate() { return StringUtils.checkValNull(pkVal()) || Objects.isNull(selectById(pkVal())) ? insert() : updateById(); }
@Override public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) { final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build(); mutableGraph.addNode(entityDescriptor); final ModelId modelId = entityDescriptor.id(); final Configuration configuration = configurationService.find(modelId.id()); if (isNull(configuration)) { LOG.debug("Could not find configuration {}", entityDescriptor); } else { final EntityDescriptor collectorEntityDescriptor = EntityDescriptor.create( configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1); mutableGraph.putEdge(entityDescriptor, collectorEntityDescriptor); } return ImmutableGraph.copyOf(mutableGraph); }