📄 platformimplbase.java
字号:
}
}
/**
* {@inheritDoc}
*/
public void createTables(Connection connection, Database model,
CreationParameters params, boolean dropTablesFirst,
boolean continueOnError) throws DatabaseOperationException {
String sql = getCreateTablesSql(model, params, dropTablesFirst,
continueOnError);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getCreateTablesSql(Database model, CreationParameters params,
boolean dropTablesFirst, boolean continueOnError) {
String sql = null;
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().createTables(model, params, dropTablesFirst);
sql = buffer.toString();
} catch (IOException e) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void alterTables(Database desiredDb, boolean continueOnError)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
alterTables(connection, desiredDb, continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Database desiredDb)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
return getAlterTablesSql(connection, desiredDb);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public void alterTables(Database desiredDb, CreationParameters params,
boolean continueOnError) throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
alterTables(connection, desiredDb, params, continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Database desiredDb,
CreationParameters params) throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
return getAlterTablesSql(connection, desiredDb, params);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public void alterTables(Connection connection, Database desiredModel,
boolean continueOnError) throws DatabaseOperationException {
String sql = getAlterTablesSql(connection, desiredModel);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Connection connection, Database desiredModel)
throws DatabaseOperationException {
String sql = null;
Database currentModel = readModelFromDatabase(connection, desiredModel
.getName());
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().alterDatabase(currentModel, desiredModel, null);
sql = buffer.toString();
} catch (IOException ex) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void alterTables(Connection connection, Database desiredModel,
CreationParameters params, boolean continueOnError)
throws DatabaseOperationException {
String sql = getAlterTablesSql(connection, desiredModel, params);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Connection connection,
Database desiredModel, CreationParameters params)
throws DatabaseOperationException {
String sql = null;
Database currentModel = readModelFromDatabase(connection, desiredModel
.getName());
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().alterDatabase(currentModel, desiredModel, params);
sql = buffer.toString();
} catch (IOException ex) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void alterTables(String catalog, String schema, String[] tableTypes,
Database desiredModel, boolean continueOnError)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
alterTables(connection, catalog, schema, tableTypes, desiredModel,
continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(String catalog, String schema,
String[] tableTypes, Database desiredModel)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
return getAlterTablesSql(connection, catalog, schema, tableTypes,
desiredModel);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public void alterTables(String catalog, String schema, String[] tableTypes,
Database desiredModel, CreationParameters params,
boolean continueOnError) throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
alterTables(connection, catalog, schema, tableTypes, desiredModel,
params, continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(String catalog, String schema,
String[] tableTypes, Database desiredModel,
CreationParameters params) throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
return getAlterTablesSql(connection, catalog, schema, tableTypes,
desiredModel, params);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public void alterTables(Connection connection, String catalog,
String schema, String[] tableTypes, Database desiredModel,
boolean continueOnError) throws DatabaseOperationException {
String sql = getAlterTablesSql(connection, catalog, schema, tableTypes,
desiredModel);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Connection connection, String catalog,
String schema, String[] tableTypes, Database desiredModel)
throws DatabaseOperationException {
String sql = null;
Database currentModel = readModelFromDatabase(connection, desiredModel
.getName(), catalog, schema, tableTypes);
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().alterDatabase(currentModel, desiredModel, null);
sql = buffer.toString();
} catch (IOException ex) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void alterTables(Connection connection, String catalog,
String schema, String[] tableTypes, Database desiredModel,
CreationParameters params, boolean continueOnError)
throws DatabaseOperationException {
String sql = getAlterTablesSql(connection, catalog, schema, tableTypes,
desiredModel, params);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getAlterTablesSql(Connection connection, String catalog,
String schema, String[] tableTypes, Database desiredModel,
CreationParameters params) throws DatabaseOperationException {
String sql = null;
Database currentModel = readModelFromDatabase(connection, desiredModel
.getName(), catalog, schema, tableTypes);
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().alterDatabase(currentModel, desiredModel, params);
sql = buffer.toString();
} catch (IOException ex) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void dropTable(Connection connection, Database model, Table table,
boolean continueOnError) throws DatabaseOperationException {
String sql = getDropTableSql(model, table, continueOnError);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public void dropTable(Database model, Table table, boolean continueOnError)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
dropTable(connection, model, table, continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public String getDropTableSql(Database model, Table table,
boolean continueOnError) {
String sql = null;
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().dropTable(model, table);
sql = buffer.toString();
} catch (IOException e) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public void dropTables(Database model, boolean continueOnError)
throws DatabaseOperationException {
Connection connection = borrowConnection();
try {
dropTables(connection, model, continueOnError);
} finally {
returnConnection(connection);
}
}
/**
* {@inheritDoc}
*/
public void dropTables(Connection connection, Database model,
boolean continueOnError) throws DatabaseOperationException {
String sql = getDropTablesSql(model, continueOnError);
evaluateBatch(connection, sql, continueOnError);
}
/**
* {@inheritDoc}
*/
public String getDropTablesSql(Database model, boolean continueOnError) {
String sql = null;
try {
StringWriter buffer = new StringWriter();
getSqlBuilder().setWriter(buffer);
getSqlBuilder().dropTables(model);
sql = buffer.toString();
} catch (IOException e) {
// won't happen because we're using a string writer
}
return sql;
}
/**
* {@inheritDoc}
*/
public Iterator query(Database model, String sql)
throws DatabaseOperationException {
return query(model, sql, (Table[]) null);
}
/**
* {@inheritDoc}
*/
public Iterator query(Database model, String sql, Collection parameters)
throws DatabaseOperationException {
return query(model, sql, parameters, null);
}
/**
* {@inheritDoc}
*/
public Iterator query(Database model, String sql, Table[] queryHints)
throws DatabaseOperationException {
Connection connection = borrowConnection();
Statement statement = null;
ResultSet resultSet = null;
Iterator answer = null;
try {
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
answer = createResultSetIterator(model, resultSet, queryHints);
return answer;
} catch (SQLException ex) {
throw new DatabaseOperationException(
"Error while performing a query", ex);
} finally {
// if any exceptions are thrown, close things down
// otherwise we're leaving it open for the iterator
if (answer == null) {
closeStatement(statement);
returnConnection(connection);
}
}
}
/**
* {@inheritDoc}
*/
public Iterator query(Database model, String sql, Collection parameters,
Table[] queryHints) throws DatabaseOperationException {
Connection connection = borrowConnection();
PreparedStatement statement = null;
ResultSet resultSet = null;
Iterator answer = null;
try {
statement = connection.prepareStatement(sql);
int paramIdx = 1;
for (Iterator iter = parameters.iterator(); iter.hasNext(); paramIdx++) {
Object arg = iter.next();
if (arg instanceof BigDecimal) {
// to avoid scale problems because setObject assumes a scale
// of 0
statement.setBigDecimal(paramIdx, (BigDecimal) arg);
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -