1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix class not found

This commit is contained in:
dengchao@xgtl 2020-04-17 15:15:51 +08:00
parent e463139cc2
commit 4f8e19ba2f

View File

@ -8,24 +8,27 @@
*/ */
package mondrian.rolap; package mondrian.rolap;
import mondrian.olap.*; import mondrian.olap.MondrianProperties;
import mondrian.olap.Util;
import mondrian.olap.Util.Functor1; import mondrian.olap.Util.Functor1;
import mondrian.server.Execution; import mondrian.server.Execution;
import mondrian.server.Locus; import mondrian.server.Locus;
import mondrian.server.monitor.*; import mondrian.server.monitor.SqlStatementEndEvent;
import mondrian.server.monitor.SqlStatementEvent;
import mondrian.server.monitor.SqlStatementEvent.Purpose; import mondrian.server.monitor.SqlStatementEvent.Purpose;
import mondrian.util.*; import mondrian.server.monitor.SqlStatementExecuteEvent;
import mondrian.server.monitor.SqlStatementStartEvent;
import mondrian.util.Counters;
import mondrian.util.DelegatingInvocationHandler;
import javax.sql.DataSource;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.sql.*; import java.sql.*;
import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import javax.sql.DataSource;
/** /**
* SqlStatement contains a SQL statement and associated resources throughout * SqlStatement contains a SQL statement and associated resources throughout
@ -42,9 +45,9 @@ import javax.sql.DataSource;
* *
* <p>There are a few obligations on the caller. The caller must:<ul> * <p>There are a few obligations on the caller. The caller must:<ul>
* <li>call the {@link #handle(Throwable)} method if one of the contained * <li>call the {@link #handle(Throwable)} method if one of the contained
* objects (say the {@link java.sql.ResultSet}) gives an error; * objects (say the {@link java.sql.ResultSet}) gives an error;
* <li>call the {@link #close()} method if all operations complete * <li>call the {@link #close()} method if all operations complete
* successfully. * successfully.
* <li>increment the {@link #rowCount} field each time a row is fetched. * <li>increment the {@link #rowCount} field each time a row is fetched.
* </ul> * </ul>
* *
@ -63,11 +66,9 @@ public class SqlStatement {
private static final AtomicLong ID_GENERATOR = new AtomicLong(); private static final AtomicLong ID_GENERATOR = new AtomicLong();
private static final Semaphore querySemaphore = new Semaphore( private static final Semaphore querySemaphore = new Semaphore(
MondrianProperties.instance().QueryLimit.get(), true); MondrianProperties.instance().QueryLimit.get(), true);
private final DataSource dataSource; private final DataSource dataSource;
private Connection jdbcConnection;
private ResultSet resultSet;
private final String sql; private final String sql;
private final List<Type> types; private final List<Type> types;
private final int maxRows; private final int maxRows;
@ -75,40 +76,41 @@ public class SqlStatement {
private final Locus locus; private final Locus locus;
private final int resultSetType; private final int resultSetType;
private final int resultSetConcurrency; private final int resultSetConcurrency;
private boolean haveSemaphore; private final List<Accessor> accessors = new ArrayList<Accessor>();
private final long id;
public int rowCount; public int rowCount;
private final Functor1<Void, Statement> callback;
private Connection jdbcConnection;
private ResultSet resultSet;
private long startTimeNanos; private long startTimeNanos;
private long startTimeMillis; private long startTimeMillis;
private final List<Accessor> accessors = new ArrayList<Accessor>();
private State state = State.FRESH; private State state = State.FRESH;
private final long id; private boolean haveSemaphore;
private Functor1<Void, Statement> callback;
/** /**
* Creates a SqlStatement. * Creates a SqlStatement.
* *
* @param dataSource Data source * @param dataSource Data source
* @param sql SQL * @param sql SQL
* @param types Suggested types of columns, or null; * @param types Suggested types of columns, or null;
* if present, must have one element for each SQL column; * if present, must have one element for each SQL column;
* each not-null entry overrides deduced JDBC type of the column * each not-null entry overrides deduced JDBC type of the column
* @param maxRows Maximum rows; <= 0 means no maximum * @param maxRows Maximum rows; <= 0 means no maximum
* @param firstRowOrdinal Ordinal of first row to skip to; <= 0 do not skip * @param firstRowOrdinal Ordinal of first row to skip to; <= 0 do not skip
* @param locus Execution context of this statement * @param locus Execution context of this statement
* @param resultSetType Result set type * @param resultSetType Result set type
* @param resultSetConcurrency Result set concurrency * @param resultSetConcurrency Result set concurrency
*/ */
public SqlStatement( public SqlStatement(
DataSource dataSource, DataSource dataSource,
String sql, String sql,
List<Type> types, List<Type> types,
int maxRows, int maxRows,
int firstRowOrdinal, int firstRowOrdinal,
Locus locus, Locus locus,
int resultSetType, int resultSetType,
int resultSetConcurrency, int resultSetConcurrency,
Util.Functor1<Void, Statement> callback) Util.Functor1<Void, Statement> callback) {
{
this.callback = callback; this.callback = callback;
this.id = ID_GENERATOR.getAndIncrement(); this.id = ID_GENERATOR.getAndIncrement();
this.dataSource = dataSource; this.dataSource = dataSource;
@ -139,21 +141,23 @@ public class SqlStatement {
querySemaphore.acquire(); querySemaphore.acquire();
haveSemaphore = true; haveSemaphore = true;
// Trace start of execution. // Trace start of execution.
if (RolapUtil.SQL_LOGGER.isDebugEnabled()) { //region org.apache.log4j.Logger is no longer exists
StringBuilder sqllog = new StringBuilder(); // if (RolapUtil.SQL_LOGGER.isDebugEnabled()) {
sqllog.append(id) // StringBuilder sqllog = new StringBuilder();
.append(": ") // sqllog.append(id)
.append(locus.component) // .append(": ")
.append(": executing sql ["); // .append(locus.component)
if (sql.indexOf('\n') >= 0) { // .append(": executing sql [");
// SQL appears to be formatted as multiple lines. Make it // if (sql.indexOf('\n') >= 0) {
// start on its own line. // // SQL appears to be formatted as multiple lines. Make it
sqllog.append("\n"); // // start on its own line.
} // sqllog.append("\n");
sqllog.append(sql); // }
sqllog.append(']'); // sqllog.append(sql);
RolapUtil.SQL_LOGGER.debug(sqllog.toString()); // sqllog.append(']');
} // RolapUtil.SQL_LOGGER.debug(sqllog.toString());
// }
//endregion
// Execute hook. // Execute hook.
RolapUtil.ExecuteQueryHook hook = RolapUtil.getHook(); RolapUtil.ExecuteQueryHook hook = RolapUtil.getHook();
@ -171,8 +175,8 @@ public class SqlStatement {
statement = jdbcConnection.createStatement(); statement = jdbcConnection.createStatement();
} else { } else {
statement = jdbcConnection.createStatement( statement = jdbcConnection.createStatement(
resultSetType, resultSetType,
resultSetConcurrency); resultSetConcurrency);
} }
if (maxRows > 0) { if (maxRows > 0) {
statement.setMaxRows(maxRows); statement.setMaxRows(maxRows);
@ -188,13 +192,13 @@ public class SqlStatement {
} }
locus.getServer().getMonitor().sendEvent( locus.getServer().getMonitor().sendEvent(
new SqlStatementStartEvent( new SqlStatementStartEvent(
startTimeMillis, startTimeMillis,
id, id,
locus, locus,
sql, sql,
getPurpose(), getPurpose(),
getCellRequestCount())); getCellRequestCount()));
this.resultSet = statement.executeQuery(sql.replaceAll("\"", "")); this.resultSet = statement.executeQuery(sql.replaceAll("\"", ""));
@ -223,13 +227,13 @@ public class SqlStatement {
status = ", exec " + executeMillis + " ms"; status = ", exec " + executeMillis + " ms";
locus.getServer().getMonitor().sendEvent( locus.getServer().getMonitor().sendEvent(
new SqlStatementExecuteEvent( new SqlStatementExecuteEvent(
timeMillis, timeMillis,
id, id,
locus, locus,
sql, sql,
getPurpose(), getPurpose(),
executeNanos)); executeNanos));
// Compute accessors. They ensure that we use the most efficient // Compute accessors. They ensure that we use the most efficient
// method (e.g. getInt, getDouble, getObject) for the type of the // method (e.g. getInt, getDouble, getObject) for the type of the
@ -251,12 +255,14 @@ public class SqlStatement {
// Now handle this exception. // Now handle this exception.
throw handle(e); throw handle(e);
} finally { } finally {
RolapUtil.SQL_LOGGER.debug(id + ": " + status); //region org.apache.log4j.Logger is no longer exists
// RolapUtil.SQL_LOGGER.debug(id + ": " + status);
if (RolapUtil.LOGGER.isDebugEnabled()) { //
RolapUtil.LOGGER.debug( // if (RolapUtil.LOGGER.isDebugEnabled()) {
locus.component + ": executing sql [" + sql + "]" + status); // RolapUtil.LOGGER.debug(
} // locus.component + ": executing sql [" + sql + "]" + status);
// }
//endregion
} }
} }
@ -293,47 +299,50 @@ public class SqlStatement {
if (ex != null) { if (ex != null) {
throw Util.newError( throw Util.newError(
ex, ex,
locus.message + "; sql=[" + sql + "]"); locus.message + "; sql=[" + sql + "]");
} }
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
long totalMs = endTime - startTimeMillis; long totalMs = endTime - startTimeMillis;
String status = String status =
", exec+fetch " + totalMs + " ms, " + rowCount + " rows"; ", exec+fetch " + totalMs + " ms, " + rowCount + " rows";
locus.execution.getQueryTiming().markFull( locus.execution.getQueryTiming().markFull(
TIMING_NAME + locus.component, totalMs); TIMING_NAME + locus.component, totalMs);
RolapUtil.SQL_LOGGER.debug(id + ": " + status); // org.apache.log4j.Logger is no longer exists
// RolapUtil.SQL_LOGGER.debug(id + ": " + status);
Counters.SQL_STATEMENT_CLOSE_COUNT.incrementAndGet(); Counters.SQL_STATEMENT_CLOSE_COUNT.incrementAndGet();
boolean remove = Counters.SQL_STATEMENT_EXECUTING_IDS.remove(id); boolean remove = Counters.SQL_STATEMENT_EXECUTING_IDS.remove(id);
status += ", ex=" + Counters.SQL_STATEMENT_EXECUTE_COUNT.get() status += ", ex=" + Counters.SQL_STATEMENT_EXECUTE_COUNT.get()
+ ", close=" + Counters.SQL_STATEMENT_CLOSE_COUNT.get() + ", close=" + Counters.SQL_STATEMENT_CLOSE_COUNT.get()
+ ", open=" + Counters.SQL_STATEMENT_EXECUTING_IDS; + ", open=" + Counters.SQL_STATEMENT_EXECUTING_IDS;
if (RolapUtil.LOGGER.isDebugEnabled()) { //region org.apache.log4j.Logger is no longer exists
RolapUtil.LOGGER.debug( // if (RolapUtil.LOGGER.isDebugEnabled()) {
locus.component + ": done executing sql [" + sql + "]" // RolapUtil.LOGGER.debug(
+ status); // locus.component + ": done executing sql [" + sql + "]"
} // + status);
// }
//endregion
if (!remove) { if (!remove) {
throw new AssertionError( throw new AssertionError(
"SqlStatement closed that was never executed: " + id); "SqlStatement closed that was never executed: " + id);
} }
locus.getServer().getMonitor().sendEvent( locus.getServer().getMonitor().sendEvent(
new SqlStatementEndEvent( new SqlStatementEndEvent(
endTime, endTime,
id, id,
locus, locus,
sql, sql,
getPurpose(), getPurpose(),
rowCount, rowCount,
false, false,
null)); null));
} }
public ResultSet getResultSet() { public ResultSet getResultSet() {
@ -350,7 +359,7 @@ public class SqlStatement {
*/ */
public RuntimeException handle(Throwable e) { public RuntimeException handle(Throwable e) {
RuntimeException runtimeException = RuntimeException runtimeException =
Util.newError(e, locus.message + "; sql=[" + sql + "]"); Util.newError(e, locus.message + "; sql=[" + sql + "]");
try { try {
close(); close();
} catch (Throwable t) { } catch (Throwable t) {
@ -362,50 +371,50 @@ public class SqlStatement {
private Accessor createAccessor(int column, Type type) { private Accessor createAccessor(int column, Type type) {
final int columnPlusOne = column + 1; final int columnPlusOne = column + 1;
switch (type) { switch (type) {
case OBJECT: case OBJECT:
return new Accessor() { return new Accessor() {
public Object get() throws SQLException { public Object get() throws SQLException {
return resultSet.getObject(columnPlusOne); return resultSet.getObject(columnPlusOne);
}
};
case STRING:
return new Accessor() {
public Object get() throws SQLException {
return resultSet.getString(columnPlusOne);
}
};
case INT:
return new Accessor() {
public Object get() throws SQLException {
final int val = resultSet.getInt(columnPlusOne);
if (val == 0 && resultSet.wasNull()) {
return null;
} }
return val; };
} case STRING:
}; return new Accessor() {
case LONG: public Object get() throws SQLException {
return new Accessor() { return resultSet.getString(columnPlusOne);
public Object get() throws SQLException {
final long val = resultSet.getLong(columnPlusOne);
if (val == 0 && resultSet.wasNull()) {
return null;
} }
return val; };
} case INT:
}; return new Accessor() {
case DOUBLE: public Object get() throws SQLException {
return new Accessor() { final int val = resultSet.getInt(columnPlusOne);
public Object get() throws SQLException { if (val == 0 && resultSet.wasNull()) {
final double val = resultSet.getDouble(columnPlusOne); return null;
if (val == 0 && resultSet.wasNull()) { }
return null; return val;
} }
return val; };
} case LONG:
}; return new Accessor() {
default: public Object get() throws SQLException {
throw Util.unexpected(type); final long val = resultSet.getLong(columnPlusOne);
if (val == 0 && resultSet.wasNull()) {
return null;
}
return val;
}
};
case DOUBLE:
return new Accessor() {
public Object get() throws SQLException {
final double val = resultSet.getDouble(columnPlusOne);
if (val == 0 && resultSet.wasNull()) {
return null;
}
return val;
}
};
default:
throw Util.unexpected(type);
} }
} }
@ -417,12 +426,12 @@ public class SqlStatement {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
final Type suggestedType = final Type suggestedType =
this.types == null ? null : this.types.get(i); this.types == null ? null : this.types.get(i);
// There might not be a schema constructed yet, // There might not be a schema constructed yet,
// so watch out here for NPEs. // so watch out here for NPEs.
RolapSchema schema = locus.execution.getMondrianStatement() RolapSchema schema = locus.execution.getMondrianStatement()
.getMondrianConnection() .getMondrianConnection()
.getSchema(); .getSchema();
if (suggestedType != null) { if (suggestedType != null) {
types.add(suggestedType); types.add(suggestedType);
@ -451,9 +460,9 @@ public class SqlStatement {
*/ */
public ResultSet getWrappedResultSet() { public ResultSet getWrappedResultSet() {
return (ResultSet) Proxy.newProxyInstance( return (ResultSet) Proxy.newProxyInstance(
null, null,
new Class<?>[] {ResultSet.class}, new Class<?>[]{ResultSet.class},
new MyDelegatingInvocationHandler(this)); new MyDelegatingInvocationHandler(this));
} }
private SqlStatementEvent.Purpose getPurpose() { private SqlStatementEvent.Purpose getPurpose() {
@ -489,22 +498,29 @@ public class SqlStatement {
public Object get(ResultSet resultSet, int column) throws SQLException { public Object get(ResultSet resultSet, int column) throws SQLException {
switch (this) { switch (this) {
case OBJECT: case OBJECT:
return resultSet.getObject(column + 1); return resultSet.getObject(column + 1);
case STRING: case STRING:
return resultSet.getString(column + 1); return resultSet.getString(column + 1);
case INT: case INT:
return resultSet.getInt(column + 1); return resultSet.getInt(column + 1);
case LONG: case LONG:
return resultSet.getLong(column + 1); return resultSet.getLong(column + 1);
case DOUBLE: case DOUBLE:
return resultSet.getDouble(column + 1); return resultSet.getDouble(column + 1);
default: default:
throw Util.unexpected(this); throw Util.unexpected(this);
} }
} }
} }
private enum State {
FRESH,
ACTIVE,
DONE,
CLOSED
}
public interface Accessor { public interface Accessor {
Object get() throws SQLException; Object get() throws SQLException;
} }
@ -517,8 +533,7 @@ public class SqlStatement {
*/ */
// must be public for reflection to work // must be public for reflection to work
public static class MyDelegatingInvocationHandler public static class MyDelegatingInvocationHandler
extends DelegatingInvocationHandler extends DelegatingInvocationHandler {
{
private final SqlStatement sqlStatement; private final SqlStatement sqlStatement;
/** /**
@ -534,8 +549,8 @@ public class SqlStatement {
final ResultSet resultSet = sqlStatement.getResultSet(); final ResultSet resultSet = sqlStatement.getResultSet();
if (resultSet == null) { if (resultSet == null) {
throw new InvocationTargetException( throw new InvocationTargetException(
new SQLException( new SQLException(
"Invalid operation. Statement is closed.")); "Invalid operation. Statement is closed."));
} }
return resultSet; return resultSet;
} }
@ -550,28 +565,20 @@ public class SqlStatement {
} }
} }
private enum State {
FRESH,
ACTIVE,
DONE,
CLOSED
}
public static class StatementLocus extends Locus { public static class StatementLocus extends Locus {
private final SqlStatementEvent.Purpose purpose; private final SqlStatementEvent.Purpose purpose;
private final int cellRequestCount; private final int cellRequestCount;
public StatementLocus( public StatementLocus(
Execution execution, Execution execution,
String component, String component,
String message, String message,
SqlStatementEvent.Purpose purpose, SqlStatementEvent.Purpose purpose,
int cellRequestCount) int cellRequestCount) {
{
super( super(
execution, execution,
component, component,
message); message);
this.purpose = purpose; this.purpose = purpose;
this.cellRequestCount = cellRequestCount; this.cellRequestCount = cellRequestCount;
} }