Dm框架-1

Basic Structures

Linux Device Model provides a number of structures to ensure the interaction between a hardware device and a device driver. The whole model is based on kobject structure. Hierarchies are built using this structure and the following structures are implemented:

    struct bus_type
    struct device
    struct device_driver

在这里插入图片描述

The kobject structure

A kobject structure does not perform a single function. This structure is usually integrated into a larger one. A kobject structure actually incorporates a set of features that will be offered to a higher abstraction object in the Linux Device Model hierarchy.

For example, the cdev structure has the following definition:

struct cdev {
        struct kobject kob;
        struct module *owner;
        const struct file_operations *ops;
        struct list_head list;
        dev_t dev;
        unsigned int count;
};

Note that this structure includes a kobject structure field.

A kobject structure is defined as follows:

struct kobject {
        const char              *name;
        struct list_head        entry;
        struct kobject          *parent;
        struct kset             *kset;
        struct kobj_type        *ktype;
        struct sysfs_dirent     *sd;
        struct kref             kref;
        unsigned int state_initialized:1;
        unsigned int state_in_sysfs:1;
        unsigned int state_add_uevent_sent:1;
        unsigned int state_remove_uevent_sent:1;
        unsigned int uevent_suppress:1;
};

As we can see, the kobject structures are in a hierarchy: an object has a parent and holds a kset member, which contains objects on the same level.

Working with the structure involves initializing it with the kobject_init() function. Also in the initialization process it is necessary to set the name of the kobject structure, which will appear in sysfs, using the kobject_set_name() function.

Any operation on a kobject is done by incrementing its internal counter using kobject_get(), or decrementing if it is no longer used using kobject_put(). Thus, a kobject object will only be released when its internal counter reaches 0. A method of notifying this is needed so that the resources associated with the device structure which included the kobject structure are released (for example, cdev). The method is called release and is associated with the object via the ktype field (struct kobj_type).

The kobject structure is the basic structure of the Linux Device Model. The structures in the higher levels of the model are struct bus_type, struct device and struct device_driver.

下回介绍Buses、device、driver、classes

### 如何在 Spring Boot 中配置 DM (达梦数据库) 连接 #### 数据源配置 为了使Spring Boot应用程序能够连接到DM数据库,需要正确配置`application.properties`文件中的数据源属性。这包括指定驱动程序类名、JDBC URL以及认证凭证。 对于DM数据库的数据源配置如下所示: ```properties # 数据源配置 spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver spring.datasource.url=jdbc:dm://<host>:<port>/<database>?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf-8 spring.datasource.username=<username> spring.datasource.password=<password> ``` 其中 `<host>` 是服务器地址, `<port>` 是端口号(默认可能是5236), `<database>` 是要连接的具体库名称, 而`<username>` 和 `<password>` 则分别是用于登录该数据库的用户名和密码[^3]。 #### 使用 Druid 数据源池优化性能 推荐采用Druid作为连接池管理工具以提高效率并监控SQL执行情况。当使用Druid时,在`pom.xml`中加入依赖项: ```xml <!-- pom.xml --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.8</version> </dependency> ``` 接着修改 `application.properties`, 添加更多参数来启用Druid特性: ```properties # Druid 配置 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.initialSize=5 spring.datasource.minIdle=5 spring.datasource.maxActive=20 ... ``` 以上设置可以调整初始大小(`initialSize`)、最小空闲连接数(`minIdle`)及最大活动连接数量(`maxActive`)等参数,从而更好地控制资源利用率。 #### 整合 MyBatis 实现 ORM 映射 若希望进一步简化持久层编码工作,则可考虑引入MyBatis框架完成对象关系映射(ORM)。通过添加相应starter包至构建文件内实现集成: ```xml <!-- pom.xml --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> ``` 之后按照标准流程编写Mapper接口及其XML映射文档即可轻松操作DM内的表结构,比如针对SYSTEM模式下的Student表创建CRUD方法[^2]。 最后验证连接状态的方法是在控制器里定义一个测试API,尝试查询一条记录返回给前端页面显示;或者像之前提到那样简单输出提示信息确认连通性正常[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值