📄 abstractdbsource.java
字号:
/*
* Copyright 2006-2007 Queplix Corp.
*
* Licensed under the Queplix Public License, Version 1.1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.queplix.tools.fkchecker.kernel.sources;
import com.queplix.tools.fkchecker.kernel.exceptions.SourceException;
import com.queplix.tools.fkchecker.kernel.types.ForeignKey;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/**
* @author dmitry.antonov
*/
public abstract class AbstractDBSource implements ForeignKeysSource {
private Connection con;
private final String url;
private final String user;
private final String passwd;
private final String driverName;
protected ResultSet fkeys;
public AbstractDBSource(Properties properties) {
url = properties.getProperty("url");
user = properties.getProperty("user");
passwd = properties.getProperty("password");
driverName = properties.getProperty("driver");
}
public final void closeSource() {
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
throw new RuntimeException("Couldn't close DB connection", e);
}
}
public final void openSource() {
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, user, passwd);
prepareParsing(con);
} catch (Exception e) {
throw new RuntimeException("Couldn't open DB source", e);
}
}
protected abstract void prepareParsing(Connection con) throws SQLException;
public final boolean hasNextForeignKey() throws SourceException {
try {
return hasNext();
}
catch(SQLException e) {
throw new SourceException(e);
}
}
protected abstract boolean hasNext() throws SQLException;
public ForeignKey nextForeignKey() {
try {
return nextForeignKey(con);
} catch (SQLException e) {
throw new RuntimeException("Couldn't get next foreign key", e);
}
}
protected abstract ForeignKey nextForeignKey(Connection con) throws SQLException;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -