Java Code Examples for cn.hutool.core.lang.Assert#notNull()

The following examples show how to use cn.hutool.core.lang.Assert#notNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiDocProjectUserController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@PostMapping("dealInvite")
@ResponseBody
public Object list(Long id,Integer status) {
    BaseResult result = new BaseResult();
    try {
        ApiDocProjectUser apiDocProjectUser = apiDocProjectUserService.selectByPrimaryKey(id);
        Assert.notNull(apiDocProjectUser,"邀请不存在");
        //此条邀请已经被处理过了
        if(apiDocProjectUser.getStatus() != 0){
            result.setCode("1");
            result.setMessage("该条邀请已经被处理了!");
            return result;
        }
        if(apiDocProjectUser.getStatus().equals(status)){
           return result;
        }
        ApiDocProjectUser toUpdate = new ApiDocProjectUser();
        toUpdate.setId(id);
        toUpdate.setStatus(status);
        apiDocProjectUserService.updateByPrimaryKeySelective(toUpdate);
    } catch (Exception e) {
        logger.error("error", e);
        result.setCode("1");
    }
    return result;
}
 
Example 2
Source File: Db.java    From Aooms with Apache License 2.0 6 votes vote down vote up
/**
 * 注意:开启	@Transactional 时无法使用该方法
 */
public void useOn(String name) {
    Assert.notNull(name,"datasource name is not allow null !");
    // 如果包含在当前spring事务中,拒绝操作
    if(TransactionSynchronizationManager.isActualTransactionActive()){
        throw new UnsupportedOperationException("Cannot be used in spring transactions !");
    }

    if (!DynamicDataSourceHolder.containsDataSource(name)) {
        logger.error("datasource [{}] not found !",name);
    } else {
        logger.info("on datasource [{}]",name);
        // 设置动态数据源上下文
        DynamicDataSourceHolder.setDataSource(name);
    }
}
 
Example 3
Source File: Db.java    From Aooms with Apache License 2.0 6 votes vote down vote up
/**
 * 注意:开启	@Transactional 时无法使用该方法
 */
public Db use(String name) {
    Assert.notNull(name,"datasource name is not allow null !");
    // 如果包含在当前spring事务中,拒绝操作
    if(TransactionSynchronizationManager.isActualTransactionActive()){
        throw new UnsupportedOperationException("Cannot be used in spring transactions !");
    }

    if (!DynamicDataSourceHolder.containsDataSource(name)) {
        logger.error("datasource [{}] not found !",name);
    } else {
        logger.info("use datasource [{}]",name);
        // 设置动态数据源上下文
        DynamicDataSourceHolder.setDataSource(name);
    }

    return this;
}
 
Example 4
Source File: ClassUtil.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问. 如向上转型到Object仍无法找到, 返回null.
 */
public static Field getAccessibleField(final Class<?> cls, final String fieldName) {
	Assert.notNull(cls, "cls can't be null");
	Assert.notEmpty(fieldName, "fieldName can't be blank");
	for (Class<?> superClass = cls; superClass != Object.class; superClass = superClass
		.getSuperclass()) {
		try {
			Field field = superClass.getDeclaredField(fieldName);
			makeAccessible(field);
			return field;
		} catch (NoSuchFieldException e) {// NOSONAR
			// Field不在当前类定义,继续向上转型
			continue;// new add
		}
	}
	return null;
}
 
Example 5
Source File: FqWebsiteDirController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
/**
 * ajax删除FqWebsiteDir
 */
@ResponseBody
@RequestMapping("/delete")
public Object delete(@RequestParam Integer id) {
    BaseResult result = new BaseResult();
    try {
        FqUserCache fqUserCache = getCurrentUser();
        if(fqUserCache == null){
            result.setResult(ResultEnum.USER_NOT_LOGIN);
            return result;
        }
        logger.info("删除网址:用户id:{},图片id:{}",fqUserCache.getId(),id);
        FqWebsiteDir fqWebsiteDir = fqWebsiteDirService.selectByPrimaryKey(id);
        Assert.notNull(fqWebsiteDir,"网址不能为空");
        fqWebsiteDir.setDelFlag(YesNoEnum.YES.getValue());
        fqWebsiteDirService.updateByPrimaryKey(fqWebsiteDir);
        CacheManager.refreshWebsiteCache();
    } catch (Exception e) {
        logger.error("删除网址报错",e);
        result.setResult(ResultEnum.SYSTEM_ERROR);
        return result;
    }
    return result;
}
 
Example 6
Source File: MqBaseModel.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 获取构造message
 *
 * @return
 */
@JSONField(serialize = false)
public Message getMessage() {
    Assert.notNull(getTag(), "tag cannot be null");
    Assert.notNull(getRequestNo(), "requestNo cannot be null");
    this.key = String.format(MqConstant.ROCKETMQ_MESSAGE_KEY, tag,
            StrUtil.lowerFirst(this.getClass().getSimpleName()), getRequestNo());
    Assert.notNull(getKey(), "key");
    Message message = new Message(TOPIC, getTag(), getKey(), this.toString().getBytes());
    Properties userProperties = new Properties();
    userProperties.setProperty(MqConstant.MODEL_CLASS_NAME, modelClassName);
    message.setUserProperties(userProperties);
    return message;
}
 
Example 7
Source File: PacketCodec.java    From bitchat with Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
    // leastPacketLen = 1byte(magic) + 1byte(serialize algorithm) + 1byte(packet type) + 4bytes(content length)
    int leastPacketLen = 7;
    // until we can read at least 7 bytes
    if (in.readableBytes() < leastPacketLen) {
        return;
    }
    // mark reader index at here
    // if no enough bytes arrived
    // we should wait and reset the
    // reader index to here
    in.markReaderIndex();
    // do common check before decode
    byte magic = in.readByte();
    Assert.state(magic == Packet.PACKET_MAGIC, "magic number is invalid");

    byte algorithm = in.readByte();
    Serializer serializer = chooser.choose(algorithm);
    Assert.notNull(serializer, "No serializer is chosen cause the algorithm of packet is invalid");
    byte type = in.readByte();
    int len = in.readInt();
    // until we have the entire packet received
    if (in.readableBytes() < len) {
        // after read some bytes: magic/algorithm/type/len
        // the left readable bytes length is less than len
        // so we need to wait until enough bytes received
        // but we must reset the reader index to we marked
        // before we return
        in.resetReaderIndex();
        return;
    }
    // read content
    byte[] content = new byte[len];
    in.readBytes(content);

    Packet packet = serializer.deserialize(content, DefaultPacket.class);
    out.add(packet);
}
 
Example 8
Source File: GenericClient.java    From bitchat with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() {
    Assert.notNull(serverAttr, "serverAttr can not be null");
    EventLoopGroup group = new NioEventLoopGroup();
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(group)
            .channel(NioSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO))
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline pipeline = ch.pipeline();
                    pipeline.addLast(new ClientInitializer(GenericClient.this));
                }
            });

    ChannelFuture future = bootstrap.connect(serverAttr.getAddress(), serverAttr.getPort());
    future.addListener(new GenericFutureListener<Future<? super Void>>() {
        @Override
        public void operationComplete(Future<? super Void> f) throws Exception {
            channel = future.channel();
            if (f.isSuccess()) {
                connected = true;
                log.info("[{}] Has connected to {} successfully", GenericClient.class.getSimpleName(), serverAttr);
            } else {
                log.warn("[{}] Connect to {} failed, cause={}", GenericClient.class.getSimpleName(), serverAttr, f.cause().getMessage());
                // fire the channelInactive and make sure
                // the {@link HealthyChecker} will reconnect
                channel.pipeline().fireChannelInactive();
            }
        }
    });
}
 
Example 9
Source File: ServerBootstrap.java    From bitchat with Apache License 2.0 5 votes vote down vote up
public void start(Integer serverPort) {
    ServerFactory factory = SimpleServerFactory.getInstance();
    Server server;
    if (ServerMode.STAND_ALONE == serverMode) {
        server = factory.newServer(serverPort, channelListener);
    } else {
        Assert.notNull(routerServerAttr, "routerServerAttr can not be null cause you are starting the server in cluster mode");
        Assert.isTrue(routerServerAttr.valid(), "routerServerAttr is invalid");
        server = factory.newClusterServer(serverPort, channelListener, routerServerAttr);
    }
    server.start();
}
 
Example 10
Source File: DefaultSession.java    From bitchat with Apache License 2.0 5 votes vote down vote up
@Override
public void bound(ChannelId channelId, long userId) {
    if (bounded.compareAndSet(false, true)) {
        ChannelWrapper channelWrapper = ChannelHelper.getChannelWrapper(channelId);
        Assert.notNull(channelWrapper, "channelId does not exists");
        this.channelId = channelId;
        this.userId = userId;
        this.channel = channelWrapper.getChannel();
        this.channelType = channelWrapper.getChannelType();
    }
}
 
Example 11
Source File: RedisConfig.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
private StringRedisSerializer(Charset charset) {
    Assert.notNull(charset, "Charset must not be null!");
    this.charset = charset;
}
 
Example 12
Source File: Db.java    From Aooms with Apache License 2.0 4 votes vote down vote up
/**
 * 更新对象
 * @return
 * @
 */
public int update(String tableName, Record record){
    Assert.notNull(record,"record must not be null");
    record.setGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER,tableName);
    return getSqlSession().update(MyBatisConst.MS_RECORD_UPDATE, record);
}
 
Example 13
Source File: AbstractSessionManager.java    From bitchat with Apache License 2.0 4 votes vote down vote up
@Override
public Session getSession(String sessionId) {
    Assert.notNull(sessionId, "sessionId can not be null");
    return sessionMap.get(sessionId);
}
 
Example 14
Source File: FastJsonSerializer.java    From bitchat with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) {
    Assert.notNull(bytes, "the deserialize bytes can not be null");
    return JSON.parseObject(bytes, clazz);
}
 
Example 15
Source File: Db.java    From Aooms with Apache License 2.0 4 votes vote down vote up
/**
 * 删除对象
 * @return
 * @
 */
public int delete(String tableName, Record record)  {
    Assert.notNull(record,"record must not be null");
    record.setGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER,tableName);
    return getSqlSession().delete(MyBatisConst.MS_RECORD_DELETE, record);
}
 
Example 16
Source File: Db.java    From Aooms with Apache License 2.0 4 votes vote down vote up
/**
 * 保存对象
 * @return 
 * @ 
 */
public int insert(String tableName, Record record) {
    Assert.notNull(record,"record must not be null");
    record.setGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER,tableName);
    return getSqlSession().insert(MyBatisConst.MS_RECORD_INSERT, record);
}
 
Example 17
Source File: HttpHandler.java    From bitchat with Apache License 2.0 4 votes vote down vote up
private HttpHandler(ChannelListener channelListener) {
    Assert.notNull(channelListener, "channelListener can not be null");
    this.executor = HttpExecutor.getInstance();
    this.channelListener = channelListener;
}
 
Example 18
Source File: DefaultChannelManager.java    From bitchat with Apache License 2.0 4 votes vote down vote up
@Override
public void removeChannel(ChannelId channelId) {
    Assert.notNull(channelId, "channelId can not be null");
    channels.remove(channelId);
}
 
Example 19
Source File: FrameHandler.java    From bitchat with Apache License 2.0 4 votes vote down vote up
private FrameHandler(ChannelListener channelListener) {
    Assert.notNull(channelListener, "channelListener can not be null");
    this.executor = FrameExecutor.getInstance();
    this.channelListener = channelListener;
}
 
Example 20
Source File: RedisConfig.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
private StringRedisSerializer(Charset charset) {
    Assert.notNull(charset, "Charset must not be null!");
    this.charset = charset;
}