-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.casbin.adapter; | ||
|
||
import org.springframework.dao.EmptyResultDataAccessException; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2019年4月23日 | ||
* @version V1.0 | ||
* | ||
*/ | ||
public class DB2Adapter extends JdbcAdapter{ | ||
|
||
private static final String CHECK_TABLE_SQL = "select 1 from syscat.tables where tabname = upper('CASBIN_RULE')"; | ||
|
||
private final static String DROP_TABLE_SQL = "DROP TABLE CASBIN_RULE"; | ||
|
||
private static final String INIT_TABLE_SQL = "CREATE TABLE CASBIN_RULE (" + | ||
" PTYPE VARCHAR(255) NOT NULL ," + | ||
" V0 VARCHAR(255) DEFAULT NULL ," + | ||
" V1 VARCHAR(255) DEFAULT NULL ," + | ||
" V2 VARCHAR(255) DEFAULT NULL ," + | ||
" V3 VARCHAR(255) DEFAULT NULL ," + | ||
" V4 VARCHAR(255) DEFAULT NULL ," + | ||
" V5 VARCHAR(255) DEFAULT NULL" + | ||
")"; | ||
|
||
/** | ||
* @param jdbcTemplate | ||
* @param autoCreateTable | ||
*/ | ||
public DB2Adapter(JdbcTemplate jdbcTemplate, boolean autoCreateTable) { | ||
super(jdbcTemplate, autoCreateTable); | ||
} | ||
|
||
@Override | ||
protected void initTable() { | ||
try { | ||
jdbcTemplate.queryForObject(CHECK_TABLE_SQL, Integer.class); | ||
} catch (EmptyResultDataAccessException e) { | ||
super.initTable(); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getInitTableSql() { | ||
return INIT_TABLE_SQL; | ||
} | ||
|
||
@Override | ||
protected String getDropTableSql() { | ||
return DROP_TABLE_SQL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters