use of mondrian.util.ByteString in project mondrian by pentaho.
the class RolapSchemaTest method createSchema.
private RolapSchema createSchema() {
SchemaKey key = new SchemaKey(mock(SchemaContentKey.class), mock(ConnectionKey.class));
ByteString md5 = new ByteString("test schema".getBytes());
// noinspection deprecation
// mock rolap connection to eliminate calls for cache loading
MondrianServer mServerMock = mock(MondrianServer.class);
RolapConnection rolapConnectionMock = mock(RolapConnection.class);
AggregationManager aggManagerMock = mock(AggregationManager.class);
SegmentCacheManager scManagerMock = mock(SegmentCacheManager.class);
when(rolapConnectionMock.getServer()).thenReturn(mServerMock);
when(mServerMock.getAggregationManager()).thenReturn(aggManagerMock);
when(aggManagerMock.getCacheMgr()).thenReturn(scManagerMock);
return new RolapSchema(key, md5, rolapConnectionMock);
}
use of mondrian.util.ByteString in project mondrian by pentaho.
the class RolapSchema method load.
/**
* Method called by all constructors to load the catalog into DOM and build
* application mdx and sql objects.
*
* @param catalogUrl URL of catalog
* @param catalogStr Text of catalog, or null
* @param connectInfo Mondrian connection properties
*/
protected void load(String catalogUrl, String catalogStr, PropertyList connectInfo) {
try {
final Parser xmlParser = XOMUtil.createDefaultParser();
final DOMWrapper def;
if (catalogStr == null) {
InputStream in = null;
try {
in = Util.readVirtualFile(catalogUrl);
def = xmlParser.parse(in);
} finally {
if (in != null) {
in.close();
}
}
// Md5 hash.
if (getLogger().isDebugEnabled() || md5Bytes == null) {
try {
catalogStr = Util.readVirtualFileAsString(catalogUrl);
} catch (java.io.IOException ex) {
getLogger().debug("RolapSchema.load: ex=" + ex);
catalogStr = "?";
}
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("RolapSchema.load: content: \n" + catalogStr);
}
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("RolapSchema.load: catalogStr: \n" + catalogStr);
}
def = xmlParser.parse(catalogStr);
}
if (md5Bytes == null) {
// computed it above by re-reading the catalog URL.
assert catalogStr != null;
md5Bytes = new ByteString(Util.digestMd5(catalogStr));
}
// throw error if we have an incompatible schema
checkSchemaVersion(def);
xmlSchema = new MondrianDef.Schema(def);
if (getLogger().isDebugEnabled()) {
StringWriter sw = new StringWriter(4096);
PrintWriter pw = new PrintWriter(sw);
pw.println("RolapSchema.load: dump xmlschema");
xmlSchema.display(pw, 2);
pw.flush();
getLogger().debug(sw.toString());
}
load(xmlSchema);
} catch (XOMException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
} catch (FileSystemException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
} catch (IOException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
}
aggTableManager.initialize(connectInfo);
setSchemaLoadDate();
}
use of mondrian.util.ByteString in project mondrian by pentaho.
the class SegmentHeader method getUniqueID.
/**
* Returns a unique identifier for this header. The identifier
* can be used for storage and will be the same across segments
* which have the same schema name, cube name, measure name,
* and for each constrained column, the same column name, table name,
* and predicate values.
* @return A unique identification string.
*/
public ByteString getUniqueID() {
if (this.uniqueID == null) {
StringBuilder hashSB = new StringBuilder();
hashSB.append(this.schemaName);
hashSB.append(this.schemaChecksum);
hashSB.append(this.cubeName);
hashSB.append(this.measureName);
for (SegmentColumn c : getSortedColumns()) {
hashSB.append(c.columnExpression);
if (c.values != null) {
for (Object value : c.values) {
hashSB.append(String.valueOf(value));
}
}
}
for (SegmentColumn c : getSortedRegions()) {
hashSB.append(c.columnExpression);
if (c.values != null) {
for (Object value : c.values) {
hashSB.append(String.valueOf(value));
}
}
}
for (String c : compoundPredicates) {
hashSB.append(c);
}
this.uniqueID = new ByteString(Util.digestSha256(hashSB.toString()));
}
return uniqueID;
}
use of mondrian.util.ByteString in project mondrian by pentaho.
the class RolapSchema method load.
/**
* Method called by all constructors to load the catalog into DOM and build
* application mdx and sql objects.
*
* @param catalogUrl URL of catalog
* @param catalogStr Text of catalog, or null
*/
protected void load(String catalogUrl, String catalogStr) {
try {
final Parser xmlParser = XOMUtil.createDefaultParser();
final DOMWrapper def;
if (catalogStr == null) {
InputStream in = null;
try {
in = Util.readVirtualFile(catalogUrl);
def = xmlParser.parse(in);
} finally {
if (in != null) {
in.close();
}
}
// Md5 hash.
if (getLogger().isDebugEnabled() || md5Bytes == null) {
try {
catalogStr = Util.readVirtualFileAsString(catalogUrl);
} catch (java.io.IOException ex) {
getLogger().debug("RolapSchema.load: ex=" + ex);
catalogStr = "?";
}
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("RolapSchema.load: content: \n" + catalogStr);
}
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("RolapSchema.load: catalogStr: \n" + catalogStr);
}
def = xmlParser.parse(catalogStr);
}
if (md5Bytes == null) {
// computed it above by re-reading the catalog URL.
assert catalogStr != null;
md5Bytes = new ByteString(Util.digestMd5(catalogStr));
}
// throw error if we have an incompatible schema
checkSchemaVersion(def);
xmlSchema = new MondrianDef.Schema(def);
if (getLogger().isDebugEnabled()) {
StringWriter sw = new StringWriter(4096);
PrintWriter pw = new PrintWriter(sw);
pw.println("RolapSchema.load: dump xmlschema");
xmlSchema.display(pw, 2);
pw.flush();
getLogger().debug(sw.toString());
}
load(xmlSchema);
} catch (XOMException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
} catch (FileSystemException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
} catch (IOException e) {
throw Util.newError(e, "while parsing catalog " + catalogUrl);
}
aggTableManager.initialize();
setSchemaLoadDate();
}
use of mondrian.util.ByteString in project mondrian by pentaho.
the class RolapSchemaPoolConcurrencyTest method answer.
@Override
public RolapSchema answer(InvocationOnMock invocation) throws Throwable {
SchemaKey key = (SchemaKey) invocation.getArguments()[4];
ByteString md5 = (ByteString) invocation.getArguments()[5];
RolapConnection connection = mock(RolapConnection.class);
// noinspection deprecation
return new RolapSchema(key, md5, connection);
}
Aggregations