GVKun编程网logo

什么是Common Lisp中使用的最佳SQL库?(common lisp gui)

10

关于什么是CommonLisp中使用的最佳SQL库?和commonlispgui的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于apache-commonscommons-pool2整合c

关于什么是Common Lisp中使用的最佳SQL库?common lisp gui的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于apache-commons commons-pool2整合 commons-net 自定 FTPClient对象池、common lisp、common lisp asdf、Common Lisp 中调用 R等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

什么是Common Lisp中使用的最佳SQL库?(common lisp gui)

什么是Common Lisp中使用的最佳SQL库?(common lisp gui)

理想情况下,可以与Oracle,MS SQL Server,MySQL和Posgress一起使用的工具。

apache-commons commons-pool2整合 commons-net 自定 FTPClient对象池

apache-commons commons-pool2整合 commons-net 自定 FTPClient对象池

commons-net 包介绍

commons-net 是 apachecommons 用于网络的工具包,它实现了一些常见的网络工具,如 smtppop3telnetftpudp 等,本文主要使用它的 ftp 工具。

使用 FTP 工具时的问题

在使用 commons-net 提供的 ftp 工具的时候 ,发现每次都要走一遍完整的连接,登录流程。每次都创建连接的话,很快就会把连接耗光,如果使用单例,则效率过低,因为只有一个连接,所以考虑用对象池的方式。

自已定义对象池的话,我之前有弄过,但要考虑好多的问题。像线程池一样,需要考虑核心对象数、最大对象数、何时创建对象 、及队列等,这时可以使用 apache 的 commons-pool2 来做一个对象池。

重要说明 : FTPClient 每次使用都需要重新连接,不然它会自动断开连接,使用会直接返回 421 ,本文章只是给个使用 commons-pool2 对象池的示例。

如何使用 commons-pool2

可以这么想,如果我要做个对象池的工具给别人用,首先要考虑的是池子里装的什么,用户要如何创建池子里的对象,然后提供方法借对象和回收对象,我可以把池子中的对象抽象出来,由一个工厂统一管理,用户的对象从我的通用对象继承或实现,或使用聚合方式 。

其实 spring-data-redis 已经给我们一个完整的使用 commons-pool2 的例子,它就是用的 commons-pool2 ,它的池中对象是 redis 连接,有兴趣可以去瞧瞧。

定义池中对象 FTPClient 的扩展对象

因为 FTPClient 的功能太过简单,连多层目录时自己创建目录都不会,所以有必要给它包装一下,这里你可以扩展常用到的方法。

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

@Slf4j
public class FtpClientExtend {
    private FTPClient ftpClient ;

    public FtpClientExtend(FTPClient ftpClient) {
        this.ftpClient = ftpClient;
    }

    /**
     * 列出文件列表
     * @param filePath
     * @return
     * @throws IOException
     */
    public FTPFile[] listFiles(String filePath) throws IOException {
        return ftpClient.listFiles(filePath);
    }

    /**
     * 下载文件
     * @param filePath
     * @return
     */
    public InputStream downloadFile(String filePath) throws IOException {
        return ftpClient.retrieveFileStream(filePath);
    }

    /**
     * 存储文件
     * @param s
     * @param inputStream
     */
    public void uploadFile(String filePath, InputStream inputStream) throws IOException {
        File targetFilePath = new File(filePath);
        Path path = targetFilePath.getParentFile().toPath();
        Iterator<Path> iterator = path.iterator();
        StringBuffer root = new StringBuffer("");
        while (iterator.hasNext()){
            Path next = iterator.next();
            root.append("/").append(next);

            //尝试切入目录
            boolean success = ftpClient.changeWorkingDirectory(root.toString());
            if(!success){
                int mkd = ftpClient.mkd(next.toString());
                ftpClient.changeWorkingDirectory(root.toString());
            }
        }

        ftpClient.enterLocalPassiveMode();
        ftpClient.setControlEncoding("UTF-8");
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        boolean storeFileResult = ftpClient.storeFile(targetFilePath.getName(), inputStream);
        if (storeFileResult) {
            log.debug("上传文件:" + filePath + ",到目录:" + ftpClient.printWorkingDirectory() + " 成功");
        }else{
            log.debug("上传文件:" + filePath + ",到目录:" + ftpClient.printWorkingDirectory() + " 失败");
        }
    }
}

使用聚合包裹池中对象

这个包裹对象的类才是工厂真正产生在池中的类,文末给出图示

import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

public class FtpClientPool extends GenericObjectPool<FtpClientExtend> {

    public FtpClientPool(PooledObjectFactory<FtpClientExtend> factory) {
        super(factory);
    }

    public FtpClientPool(PooledObjectFactory<FtpClientExtend> factory, GenericObjectPoolConfig config) {
        super(factory, config);
    }
}

建立创建对象的工厂

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class FtpClientFactory extends BasePooledObjectFactory<FtpClientExtend> {
    @Value("${ftp.host:localhost}")
    private String host;
    @Value("${ftp.port:21}")
    private int port;
    @Value("${ftp.username:ftpadmin}")
    private String username;
    @Value("${ftp.password:salt202}")
    private String password;

    @Override
    public FtpClientExtend create() throws Exception {
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect(host,port);
        boolean login = ftpClient.login(username, password);
        if(!login){
            throw new RuntimeException("ftp 登录失败,检查用户名密码是否正确["+host+":"+port+"]["+username+"]["+password+"]");
        }
        return new FtpClientExtend(ftpClient);
    }

    @Override
    public PooledObject<FtpClientExtend> wrap(FtpClientExtend ftpClientExtend) {
        return new DefaultPooledObject(ftpClientExtend);
    }
}

使用方法

@Autowired
private FtpClientPool ftpClientPool;

public void method(){
    FtpClientExtend ftpClientExtend = null;
    try{
        ftpClientExtend = ftpClientPool.borrowObject();
    }finally{
         if(ftpClientExtend != null) {
          ftpClientPool.returnObject(ftpClientExtend);
        }
    }
}

原理图示

在这里插入图片描述

common lisp

common lisp

大神。请问Write a recursive function, equivalence, of the predicate that tests whether two sets contain the same elements. Note that the two lists representing the sets may be arranged in different orders, so you cannot just use EQUAL. You will need to make use of “REMOVE” for the definition of the recursive function.

不只用equal应该怎么做?

common lisp asdf

common lisp asdf

use asdf/ detail

environment: linux/sbcl/gvim/slimv

[root @archlinux asdf]# pwd
/home/root/test/cl/asdf

[root @archlinux asdf]# ls -l
-rw-r--r-- 1 root root 214 11月 10 00:33 config.lisp
-rw-r--r-- 1 root root 343 11月 10 00:36 demo-control.asd
-rw-r--r-- 1 root root   72 11月   9 23:47 packages.lisp
-rw-r--r-- 1 root root 184 11月 10 00:49 source.lisp

*****demo-control.asd *****
(defpackage :asdf-control (:use #:cl #:asdf))
(in-package :asdf-control)

(defsystem :demo-control
  :description "asdf test"
  :version "0.1"
  :author "tskshy"
  :depends-on ()
  :components (
               (:file "packages")
               (:file "config" :depends-on ("packages"))
               (:file "source" :depends-on ("config"))))

*****packages.lisp*****
(defpackage :demo.asdf
  (:use :cl)
  (:export
    :print-config-info))

*****config.lisp*****
(in-package :demo.asdf)

;;next is test info
(defvar *username* "test name")
(defparameter *config-path* "/etc")
(defparameter *config-name* "file-name")
(defparameter *information* "OK, ASDF test successfully!")

*****source.lisp*****
(in-package :demo.asdf)

(defun print-config-info ()
  (progn
    (format t "myconfig information ~A | ~A | ~A ~%~%~%~A~%~%~%" *username* *config-path* *config-name* *information*)))

*****test code*****
;;;;test asdf ok?
(require :asdf)
(progn
  (format t "asdf version: ~A~%" (asdf:asdf-version))
 
  (if (eql asdf:*central-registry* nil)
    (progn
      (format t "Now, set asdf path~%")
      (push #p"/home/root/test/cl/asdf/" asdf:*central-registry*)))
 
  (format t "asdf config ok~%")
  (format t "load begin ... ~%")
  (asdf:load-system :demo-control))
(demo.asdf:print-config-info)








Common Lisp 中调用 R

Common Lisp 中调用 R

R 是功能强大的统计软件,和 Lisp 一样也有一个交互式的命令行环境,还有众多的扩展库,可以用来进行专业的统计分析。要在 Common Lisp 中方便的调用 R 的功能,可以试用 rcl 这个库。安装方法很简单,因为它已经纳入到 quicklisp 库中了:

(ql:quickload “rcl”)

使用:

Source code    
* (use-package :rcl)                                                                 T    
* (r-init)                                                                           T
* (r "R.Version")  ("x86_64-pc-linux-gnu" "x86_64" "linux-gnu" "x86_64, linux-gnu" "" "2" "12.1" "2010" "12" "16" "53855" "R" "R version 2.12.1 (2010-12-16)") ((:NAMES "platform" "arch" "os" "system" "status" "major" "minor" "year" "month" "day" "svn rev" "language" "version.string")) 
* (r "seq" 1 5)                                                                      (1 2 3 4 5) 
* (r "*" 2 (r "seq" 1 5))                                                            (2 4 6 8 10) 
* (r "summary" ''(123 543 3242 8934 234 643))                                         (123.0d0 311.2d0 593.0d0 2286.0d0 2592.0d0 8934.0d0)

今天关于什么是Common Lisp中使用的最佳SQL库?common lisp gui的介绍到此结束,谢谢您的阅读,有关apache-commons commons-pool2整合 commons-net 自定 FTPClient对象池、common lisp、common lisp asdf、Common Lisp 中调用 R等更多相关知识的信息可以在本站进行查询。

本文标签: