-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Isolate
DatabaseLibrary::connectToORM
- Loading branch information
1 parent
0b7a4eb
commit 2df6155
Showing
2 changed files
with
119 additions
and
8 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
99 changes: 99 additions & 0 deletions
99
src/main/java/net/elytrium/limboauth/dependencies/IsolatedDriver.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,99 @@ | ||
/* | ||
* Copyright (C) 2021 - 2024 Elytrium | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.elytrium.limboauth.dependencies; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Driver; | ||
import java.sql.DriverPropertyInfo; | ||
import java.sql.SQLException; | ||
import java.sql.SQLFeatureNotSupportedException; | ||
import java.util.Properties; | ||
import java.util.logging.Logger; | ||
|
||
public class IsolatedDriver implements Driver { | ||
|
||
private final String initializer; | ||
private Driver original; | ||
|
||
public IsolatedDriver(String initializer) { | ||
this.initializer = initializer; | ||
} | ||
|
||
public String getInitializer() { | ||
return this.initializer; | ||
} | ||
|
||
public Driver getOriginal() { | ||
return this.original; | ||
} | ||
|
||
public void setOriginal(Driver driver) { | ||
this.original = driver; | ||
} | ||
|
||
@Override | ||
public Connection connect(String url, Properties info) throws SQLException { | ||
if (url.startsWith(this.initializer)) { | ||
return this.original.connect(url.substring(this.initializer.length()), info); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public boolean acceptsURL(String url) throws SQLException { | ||
if (url.startsWith(this.initializer)) { | ||
if (this.original == null) { | ||
return false; | ||
} | ||
|
||
return this.original.acceptsURL(url.substring(this.initializer.length())); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { | ||
if (url.startsWith(this.initializer)) { | ||
return this.original.getPropertyInfo(url.substring(this.initializer.length()), info); | ||
} | ||
|
||
return new DriverPropertyInfo[0]; | ||
} | ||
|
||
@Override | ||
public int getMajorVersion() { | ||
return this.original.getMajorVersion(); | ||
} | ||
|
||
@Override | ||
public int getMinorVersion() { | ||
return this.original.getMinorVersion(); | ||
} | ||
|
||
@Override | ||
public boolean jdbcCompliant() { | ||
return this.original.jdbcCompliant(); | ||
} | ||
|
||
@Override | ||
public Logger getParentLogger() throws SQLFeatureNotSupportedException { | ||
return this.original.getParentLogger(); | ||
} | ||
} |