11package ru .nukkit .dblib ;
22
3+ import com .j256 .ormlite .db .DatabaseType ;
4+ import com .j256 .ormlite .db .DatabaseTypeUtils ;
5+ import com .j256 .ormlite .db .SqliteDatabaseType ;
6+ import com .j256 .ormlite .jdbc .DataSourceConnectionSource ;
37import com .j256 .ormlite .jdbc .JdbcConnectionSource ;
48import com .j256 .ormlite .jdbc .JdbcPooledConnectionSource ;
9+ import com .j256 .ormlite .jdbc .JdbcSingleConnectionSource ;
510import com .j256 .ormlite .logger .LocalLog ;
611import com .j256 .ormlite .support .ConnectionSource ;
12+ import com .j256 .ormlite .support .DatabaseConnection ;
713import org .sql2o .Sql2o ;
14+ import ru .nukkit .dblib .connectionsource .LockedJdbcSingleConnectionSource ;
815import ru .nukkit .dblib .core .M ;
916import ru .nukkit .dblib .nukkit .ConfigNukkit ;
1017
@@ -43,7 +50,7 @@ public static void init(ConfigNukkit cfg, File dataFolder) {
4350 * Get DbLib's default ORMLite connection source.
4451 * All plugins used this method will share same database
4552 *
46- * @return - ConnectionSource (ORMlite)
53+ * @return - {@link ConnectionSource}
4754 */
4855 public static ConnectionSource getConnectionSource () {
4956 return connectionSource ;
@@ -54,18 +61,21 @@ public static ConnectionSource getConnectionSource() {
5461 * Allows plugins to use custom connection source
5562 *
5663 * @param url - database url (including database protocol). Examples:
57- * jdbc:sqlite:c:\server\plugins\MyPugin \data.db
64+ * jdbc:sqlite:c:\server\plugins\MyPlugin \data.db
5865 * jdbc:mysql://localhost:3306/db
5966 * @param userName - Database user name, will be ignored for sqlite
6067 * @param password - Database user password, will be ignored for sqlite
61- * @return - ConnectionSource (ORMlite)
68+ * @return - {@link ConnectionSource}
6269 */
6370 public static ConnectionSource getConnectionSource (String url , String userName , String password ) {
71+ DatabaseType type = DatabaseTypeUtils .createDatabaseType (url );
6472 try {
65- if (config .ormLiteKeepAlive () <= 0 ) {
73+ if (type instanceof SqliteDatabaseType ) {
74+ return new LockedJdbcSingleConnectionSource (url , userName , password , type );
75+ } else if (config .ormLiteKeepAlive () <= 0 ) {
6676 return new JdbcConnectionSource (url , userName , password );
6777 } else {
68- JdbcPooledConnectionSource jdbcCon = new JdbcPooledConnectionSource (url , userName , password );
78+ JdbcPooledConnectionSource jdbcCon = new JdbcPooledConnectionSource (url , userName , password , type );
6979 jdbcCon .setCheckConnectionsEveryMillis (config .ormLiteKeepAlive ());
7080 return jdbcCon ;
7181 }
@@ -80,7 +90,7 @@ public static ConnectionSource getConnectionSource(String url, String userName,
8090 * Get custom SQLite ORMLite connection source.
8191 *
8292 * @param fileName - database file name
83- * @return - ConnectionSource (ORMlite)
93+ * @return - {@link ConnectionSource}
8494 */
8595 public static ConnectionSource getConnectionSourceSQLite (String fileName ) {
8696 File f = new File (folder + File .separator + fileName );
@@ -98,7 +108,7 @@ public static ConnectionSource getConnectionSourceSQLite(String fileName) {
98108 * @param database - MySQL database
99109 * @param user - MySQL user name
100110 * @param password - MySQL password
101- * @return - ConnectionSource (ORMlite)
111+ * @return - {@link ConnectionSource}
102112 */
103113 public static ConnectionSource getConnectionSourceMySql (String host , int port , String database , String user , String password ) {
104114 return getConnectionSource (getMySqlUrl (host , port , database ), user , password );
@@ -122,7 +132,7 @@ public static Connection getDefaultConnection() {
122132 * @param url - MySQL url, example: localhost:3306/db
123133 * @param user - MySQL user name
124134 * @param password - MySQL password
125- * @return - Connection (SQL)
135+ * @return - {@link Connection}
126136 */
127137 public static Connection getMySqlConnection (String url , String user , String password ) {
128138 try {
0 commit comments