Search in sources :

Example 1 with ByteString

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);
}
Also used : SegmentCacheManager(mondrian.rolap.agg.SegmentCacheManager) AggregationManager(mondrian.rolap.agg.AggregationManager) ByteString(mondrian.util.ByteString)

Example 2 with ByteString

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();
}
Also used : java.io(java.io) ByteString(mondrian.util.ByteString) Parser(org.eigenbase.xom.Parser) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 3 with ByteString

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;
}
Also used : ByteString(mondrian.util.ByteString) ByteString(mondrian.util.ByteString)

Example 4 with ByteString

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();
}
Also used : java.io(java.io) ByteString(mondrian.util.ByteString) Parser(org.eigenbase.xom.Parser) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 5 with ByteString

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);
}
Also used : ByteString(mondrian.util.ByteString)

Aggregations

ByteString (mondrian.util.ByteString)6 java.io (java.io)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 Parser (org.eigenbase.xom.Parser)2 RolapSchema (mondrian.rolap.RolapSchema)1 RolapStar (mondrian.rolap.RolapStar)1 AggregationManager (mondrian.rolap.agg.AggregationManager)1 SegmentCacheManager (mondrian.rolap.agg.SegmentCacheManager)1