rolapconnection.java
来自「数据仓库展示程序」· Java 代码 · 共 525 行 · 第 1/2 页
JAVA
525 行
return RolapConnectionPool.instance().getPoolingDataSource(
dataSourceName, connectionFactory);
} catch (Exception e) {
throw Util.newInternal(e,
"Error while creating connection pool (with URI " +
dataSourceName + ")");
}
}
}
/**
* Creates a {@link Properties} object containing all of the JDBC
* connection properties present in the
* {@link Util.PropertyList connectInfo}.
*
* @param connectInfo
* @return The JDBC connection properties.
*/
private static Properties getJDBCProperties(Util.PropertyList connectInfo) {
Properties jdbcProperties = new Properties();
Iterator iterator = connectInfo.iterator();
while (iterator.hasNext()) {
String[] entry = (String[]) iterator.next();
if (entry[0].startsWith(RolapConnectionProperties.JdbcPropertyPrefix)) {
jdbcProperties.put(entry[0].substring(RolapConnectionProperties.JdbcPropertyPrefix.length()), entry[1]);
}
}
return jdbcProperties;
}
public Util.PropertyList getConnectInfo() {
return connectInfo;
}
public void close() {
}
public Schema getSchema() {
return schema;
}
public String getConnectString() {
return connectInfo.toString();
}
public String getCatalogName() {
return catalogName;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public SchemaReader getSchemaReader() {
return schemaReader;
}
public Result execute(Query query) {
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(query.getQueryString());
}
Result result = new RolapResult(query);
for (int i = 0; i < query.axes.length; i++) {
QueryAxis axis = query.axes[i];
if (axis.nonEmpty) {
result = new NonEmptyResult(result, query, i);
}
}
if (LOGGER.isDebugEnabled()) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
result.print(pw);
pw.flush();
LOGGER.debug(sw.toString());
}
return result;
} catch (Throwable e) {
String queryString;
try {
queryString = query.getQueryString();
} catch (Exception e1) {
queryString = "?";
}
throw Util.newError(e, "Error while executing query [" +
queryString + "]");
}
}
public void setRole(Role role) {
Util.assertPrecondition(role != null, "role != null");
Util.assertPrecondition(!role.isMutable(), "!role.isMutable()");
this.role = role;
this.schemaReader = new RolapSchemaReader(role, schema) {
public Cube getCube() {
throw new UnsupportedOperationException();
}
};
}
public Role getRole() {
Util.assertPostcondition(role != null, "role != null");
Util.assertPostcondition(!role.isMutable(), "!role.isMutable()");
return role;
}
/**
* Implementation of {@link DataSource} which calls the good ol'
* {@link java.sql.DriverManager}.
*/
private static class DriverManagerDataSource implements DataSource {
private final String jdbcConnectString;
private PrintWriter logWriter;
private int loginTimeout;
private Properties jdbcProperties;
public DriverManagerDataSource(String jdbcConnectString,
Properties properties) {
this.jdbcConnectString = jdbcConnectString;
this.jdbcProperties = properties;
}
public Connection getConnection() throws SQLException {
return new org.apache.commons.dbcp.DelegatingConnection(
java.sql.DriverManager.getConnection(
jdbcConnectString, jdbcProperties));
}
public Connection getConnection(String username, String password)
throws SQLException {
if (jdbcProperties == null) {
return java.sql.DriverManager.getConnection(jdbcConnectString,
username, password);
} else {
Properties temp = (Properties)jdbcProperties.clone();
temp.put("user", username);
temp.put("password", password);
return java.sql.DriverManager.getConnection(jdbcConnectString, temp);
}
}
public PrintWriter getLogWriter() throws SQLException {
return logWriter;
}
public void setLogWriter(PrintWriter out) throws SQLException {
logWriter = out;
}
public void setLoginTimeout(int seconds) throws SQLException {
loginTimeout = seconds;
}
public int getLoginTimeout() throws SQLException {
return loginTimeout;
}
}
public DataSource getDataSource() {
return dataSource;
}
/**
* A <code>NonEmptyResult</code> filters a result by removing empty rows
* on a particular axis.
*/
class NonEmptyResult extends ResultBase {
private final Result underlying;
private final int axis;
private final Map map;
/** workspace. Synchronized access only. **/
private final int[] pos;
NonEmptyResult(Result result, Query query, int axis) {
super(query, (Axis[]) result.getAxes().clone());
this.underlying = result;
this.axis = axis;
this.map = new HashMap();
int axisCount = underlying.getAxes().length;
this.pos = new int[axisCount];
this.slicerAxis = underlying.getSlicerAxis();
Position[] positions = underlying.getAxes()[axis].positions;
ArrayList positionsList = new ArrayList();
for (int i = 0, count = positions.length; i < count; i++) {
Position position = positions[i];
if (isEmpty(i, axis)) {
continue;
} else {
map.put(new Integer(positionsList.size()), new Integer(i));
positionsList.add(position);
}
}
this.axes[axis] = new RolapAxis(
(Position[]) positionsList.toArray(new Position[0]));
}
protected Logger getLogger() {
return LOGGER;
}
/**
* Returns true if all cells at a given offset on a given axis are
* empty. For example, in a 2x2x2 dataset, <code>isEmpty(1,0)</code>
* returns true if cells <code>{(1,0,0), (1,0,1), (1,1,0),
* (1,1,1)}</code> are all empty. As you can see, we hold the 0th
* coordinate fixed at 1, and vary all other coordinates over all
* possible values.
*/
private boolean isEmpty(int offset, int fixedAxis) {
int axisCount = getAxes().length;
pos[fixedAxis] = offset;
return isEmptyRecurse(fixedAxis, axisCount - 1);
}
private boolean isEmptyRecurse(int fixedAxis, int axis) {
if (axis < 0) {
RolapCell cell = (RolapCell) underlying.getCell(pos);
return cell.isNull();
} else if (axis == fixedAxis) {
return isEmptyRecurse(fixedAxis, axis - 1);
} else {
Position[] positions = getAxes()[axis].positions;
for (int i = 0, count = positions.length; i < count; i++) {
pos[axis] = i;
if (!isEmptyRecurse(fixedAxis, axis - 1)) {
return false;
}
}
return true;
}
}
// synchronized because we use 'pos'
public synchronized Cell getCell(int[] externalPos) {
System.arraycopy(externalPos, 0, this.pos, 0, externalPos.length);
int offset = externalPos[axis];
int mappedOffset = mapOffsetToUnderlying(offset);
this.pos[axis] = mappedOffset;
return underlying.getCell(this.pos);
}
private int mapOffsetToUnderlying(int offset) {
return ((Integer) map.get(new Integer(offset))).intValue();
}
public void close() {
underlying.close();
}
}
}
// End RolapConnection.java
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?