-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b801d3
commit 03dff35
Showing
11 changed files
with
319 additions
and
205 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
17 changes: 17 additions & 0 deletions
17
pisi/unitedmeows/yystal/exception/impl/sql/YexMySQLDriverError.java
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,17 @@ | ||
package pisi.unitedmeows.yystal.exception.impl.sql; | ||
|
||
import pisi.unitedmeows.yystal.exception.YEx; | ||
|
||
public class YexMySQLDriverError extends YEx { | ||
|
||
private String message; | ||
|
||
public YexMySQLDriverError(String error) { | ||
message = error; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
pisi/unitedmeows/yystal/exception/impl/sql/YexSqlError.java
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,17 @@ | ||
package pisi.unitedmeows.yystal.exception.impl.sql; | ||
|
||
import pisi.unitedmeows.yystal.exception.YEx; | ||
|
||
public class YexSqlError extends YEx { | ||
|
||
private String message; | ||
|
||
public YexSqlError(final String _message) { | ||
message = _message; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
package pisi.unitedmeows.yystal.sql; | ||
|
||
import pisi.unitedmeows.yystal.clazz.HookClass; | ||
import pisi.unitedmeows.yystal.clazz.prop; | ||
import pisi.unitedmeows.yystal.exception.YExManager; | ||
import pisi.unitedmeows.yystal.exception.impl.sql.YexSqlError; | ||
import pisi.unitedmeows.yystal.hook.YString; | ||
|
||
import java.sql.*; | ||
|
||
public class YDatabaseWorker extends HookClass<YSQLClient> { | ||
|
||
// connection = DriverManager.getConnection("jdbc:mysql://" + _host + ":" + _port + "/" + database + "?characterEncoding=latin1&useConfigs=maxPerformance", _username, _password); | ||
|
||
public final prop<String> database; | ||
private Connection connection; | ||
private boolean connected; | ||
|
||
protected YDatabaseWorker(final YSQLClient owner, final String _database) { | ||
hooked = owner; | ||
database = new prop<String>(_database); | ||
|
||
try { | ||
/* not required */ synchronized (this) { | ||
if (connection != null && !connection.isClosed()) return; | ||
|
||
/* change this to ystring */ | ||
connection = DriverManager.getConnection("jdbc:mysql://" + owner.host + ":" + owner.port + "/" + database.get() + "?characterEncoding=latin1&useConfigs=maxPerformance", owner.username, owner.password); | ||
connected = true; | ||
} | ||
} catch (Exception e) { | ||
connected = false; | ||
YExManager.pop(new YexSqlError("YDatabaseWorker couldn't connect to database (" + database.get() + ")")); | ||
} | ||
} | ||
|
||
public YQueryResult createQuery(String query) { | ||
final String newQuery = query.startsWith("@") ? query : new YString(query).toString(); | ||
try { | ||
return new YQueryResult(connection.prepareStatement(newQuery)); | ||
} catch (SQLException e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.