Skip to content

Commit 49333df

Browse files
authored
Merge pull request #17 from nodece/master
Bump to v2.0.0
2 parents fc2c3de + dee622c commit 49333df

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ For Maven:
3636
<dependency>
3737
<groupId>org.casbin</groupId>
3838
<artifactId>jdbc-adapter</artifactId>
39-
<version>1.1.4</version>
39+
<version>2.0.0</version>
4040
</dependency>
4141
```
4242

@@ -48,24 +48,30 @@ package com.company.test;
4848
import org.casbin.jcasbin.main.Enforcer;
4949
import org.casbin.jcasbin.util.Util;
5050
import org.casbin.adapter.JDBCAdapter;
51+
import com.mysql.cj.jdbc.MysqlDataSource;
5152

5253
public class Test {
5354
public static void main() {
54-
// Initialize a JDBC adapter and use it in a jCasbin enforcer:
55-
// The adapter will use the MySQL database named "casbin".
56-
// If it doesn't exist, the adapter will create it automatically.
57-
JDBCAdapter a = new JDBCAdapter("com.mysql.cj.jdbc.Driver", "jdbc:mysql://localhost:3306/db_name", "root", "123"); // Your driver and URL.
55+
String driver = "com.mysql.cj.jdbc.Driver";
56+
String url = "jdbc:mysql://localhost:3306/db_name";
57+
String username = "root";
58+
String password = "123456";
5859

59-
// Or you can use an existing DB "abc" like this:
6060
// The adapter will use the table named "casbin_rule".
61-
// If it doesn't exist, the adapter will create it automatically.
62-
// JDBCAdapter a = new JDBCAdapter("com.mysql.cj.jdbc.Driver", "jdbc:mysql://localhost:3306/casbin", "root", "123", true);
61+
// Use driver, url, username and password to initialize a JDBC adapter.
62+
JDBCAdapter a = new JDBCAdapter(driver, url, username, password);
63+
64+
// Recommend use DataSource to initialize a JDBC adapter.
65+
// Implementer of DataSource interface, such as hikari, c3p0, durid, etc.
66+
MysqlDataSource dataSource = new MysqlDataSource();
67+
dataSource.setURL(url);
68+
dataSource.setUser(username);
69+
dataSource.setPassword(password);
70+
71+
a = JDBCAdapter(dataSource);
6372

6473
Enforcer e = new Enforcer("examples/rbac_model.conf", a);
6574

66-
// Load the policy from DB.
67-
e.loadPolicy();
68-
6975
// Check the permission.
7076
e.enforce("alice", "data1", "read");
7177

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.casbin</groupId>
88
<artifactId>jdbc-adapter</artifactId>
9-
<version>1.1.4</version>
9+
<version>2.0.0</version>
1010

1111
<name>JDBC Adapter for JCasbin</name>
1212
<description>Load policy from JDBC supported database or save policy to it</description>

0 commit comments

Comments
 (0)