I do not know how I can generate or create Cube with Olap4j/Olap connection, when I have Cube I can load it and work with it, but I have database and I want from code generate Cube and save it as xml. So how many ways we have for it?
Connection connection = DriverManager.getConnection(
String.format(
"jdbc:mondrian:Jdbc=%s; Catalog=file:%s",
"jdbc:mysql://localhost:3306/network?user=root&password=root",
"C:\\Users\\John\\Documents\\pivot4j-web\\src\\java\\org\\pivot4j\\analytics\\test\\FoodMartX.xml"
)
);
OlapConnection olapConnection = connection.unwrap(OlapConnection.class);
Schema s = olapConnection.getOlapSchema();
System.out.println("Schema: " + s.getName());
for (Cube cube : s.getCubes()) {
System.out.println("Cube: " + cube.getName());
for (Dimension dimension : cube.getDimensions()) {
System.out.println("Dimension: " + dimension.getName());
}
for (Measure measure : cube.getMeasures()) {
System.out.println("Measure: " + measure.getName());
}
}
Pivot4J or Olap4J is used to browse an existing OLAP schema, so you'll need to rely on using another tool to create cubes which is usually provided by the vendor of the respective OLAP backend you're using.
As to Mondrian, there's a GUI application called Schema Workbench which allows you to manipulate Mondrian schema files.
Hope this helps!
Xavier
Related
We are trying to integrate SAP Business One DI Server with JAVA. Checked help documents in SDK for DI Server but it is available for .NET only.
Don't want to use B1WS as we came to know that B1WS is not stable and has lots of bugs. Also checked for Python flask RESTful application but it has limited functionality.
The following code should allow you to connect to a "Company" object and from there perform your tasks (DI - NOT UI).
import com.sap.smb.sbo.api.*;
public static void main(String[] args)
{
ICompany company;
IDocuments document;
SBOCOMUtil util = new SBOCOMUtil();
company = util.newCompany();
try
{
company.setServer( "sqlservername" );
company.setCompanyDB( "dbname" );
company.setUserName( "manager" );
company.setPassword( "manager" );
company.setLanguage(com.sap.smb.sbo.api.SBOCOMConstants.BoSuppLangs_ln_English);
company.setDbUserName("sa");
company.setDbPassword("pwd");
company.setUseTrusted( new Boolean(false) );
int result = company.connect();
System.out.println("Company: " + company.getCompanyName());
// analyze connection result
if ( result != 0 )
{
System.out.println("Connection error: " + result);
}
else
{
System.out.println("Connection success, company name: " + company.getCompanyName() );
}
}
catch(SBOCOMException ex)
{
System.out.println(ex.getStackTraceString());
}
finally
{
company.disconnect();
}
}
Also take a look at the following path; "C:\Program Files (x86)\SAP\SAP Business One DI API\JCO\LIB" where you can find the wrapper for DI API also "C:\Program Files (x86)\SAP\SAP Business One SDK\Help" there should be a JCO zip with more details regarding the JAVA Approach. Generally, documentation is very poor regarding Java. Your best approach would be either the B1i or the COM solutions.
Regards,
enshadowed_
Hi how can I use database stored GString definitions for dynamically generated data. I was able to use GString for pick and choose row attributes if format is defined in the code
code_format = "${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}"
However if same definition is extracted from database my code is not working.
Sql sql = Sql.newInstance(url, login, password, driver);
sql.eachRow(SQL) { row ->
code_format = "${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}"
database_format = "${-> row.REPORT_ATTRIBUTES}"
println "1- " + code_format
println "2- " + database_format
println "CODE : " + code_format.dump()
println "DB : " + database_format.dump()
}
When I run this code I am getting following output;
1- FlowerHouse Joe
2- ${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}
CODE : <org.codehaus.groovy.runtime.GStringImpl#463cf024 strings=[, , ] values=[GString$_run_closure1_closure2#44f289ee, GString$_run_closure1_closure3#f3d8b9f]>
DB : org.codehaus.groovy.runtime.GStringImpl#4f5e9da9 strings=[, ] values=[GString$_run_closure1_closure4#11997b8a]
row.REPORT_ATTRIBUTES returns String because database doesn't know groovy stings format.
GString is template, which can be created from string.
So you can do something like:
def engine = new groovy.text.SimpleTemplateEngine()
println engine.createTemplate(row.REPORT_ATTRIBUTES).make([row:row]).toString()
In my machine, base/data directory contains multiple repositories. But when I access this data directory from java program it gives me only SYSTEM repository record.
Code to retrieve the repositories :
String dataDir = "D:\\SesameStorage\\data\\"
LocalRepositoryManager localManager = new LocalRepositoryManager(new File(dataDir));
localManager.initialize();
// Get all repositories
Collection<Repository> repos = localManager.getAllRepositories();
System.out.println("LocalRepositoryManager All repositories : "
+ repos.size());
for (Repository repo : repos) {
System.out.println("This is : " + repo.getDataDir());
RepositoryResult<Statement> idStatementIter = repo
.getConnection().getStatements(null,
RepositoryConfigSchema.REPOSITORYID, null,
true, new Resource[0]);
Statement idStatement;
try {
while (idStatementIter.hasNext()) {
idStatement = (Statement) idStatementIter.next();
if ((idStatement.getObject() instanceof Literal)) {
Literal idLiteral = (Literal) idStatement
.getObject();
System.out.println("idLiteral.getLabel() : "
+ idLiteral.getLabel());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Output :
LocalRepositoryManager All repositories : 1
This is : D:\SemanticStorage\data\repositories\SYSTEM
idLiteral.getLabel() : SYSTEM
Adding repository to LocalRepositoryManager :
String repositoryName = "data.ttl";
RepositoryConfig repConfig = new RepositoryConfig(repositoryName);
SailRepositoryConfig config = new SailRepositoryConfig(new MemoryStoreConfig());
repConfig.setRepositoryImplConfig(config);
manager.addRepositoryConfig(repConfig);
Getting the repository object :
Repository repository = manager.getRepository(repositoryName);
repository.initialize();
I have successfully added new repository to LocalRepositoryManager and it shows me the repository count to 2. But when I restart the application it shows me only one repository and that is the SYSTEM repository.
My SYSTEM repository is not getting updated, Please suggest me, how should I load that data directory in my LocalRepositoryManager object.
You haven't provided a comprehensive test case, just individual snippets of code with no clear indication of the order in which they get executed, which makes it somewhat hard to figure out what exactly is going wrong.
I would hazard a guess, however, that the problem is that you don't properly close and shut down resources. First of all you are obtaining a RepositoryConnection without ever closing it:
RepositoryResult<Statement> idStatementIter = repo
.getConnection().getStatements(null,
RepositoryConfigSchema.REPOSITORYID, null,
true, new Resource[0]);
You will need to change this to something like this:
RepositoryConnection conn = repo.getConnection();
try {
RepositoryResult<Statement> idStatementIter =
conn.getStatements(null,
RepositoryConfigSchema.REPOSITORYID, null,
true, new Resource[0]);
(... do something with the result here ...)
}
finally {
conn.close();
}
As an aside: if your goal is retrieve repository meta-information (id, title, location), the above code is far too complex. There is no need to open a connection to the SYSTEM repository to read this information at all, you can obtain this stuff directly from the RepositoryManager. For example, you can retrieve a list of repository identifiers simply by doing:
List<String> repoIds = localManager.getRepositoryIDs();
for (String id: repoIds) {
System.out.println("repository id: " + id);
}
Or if you want to also get the file location and/or description, use:
Collection<RepositoryInfo> infos = localManager.getAllRepositoryInfos();
for (RepositoryInfo info: infos) {
System.out.println("id: " + info.getId());
System.out.println("description: " + info.getDescription());
System.out.println("location: " + info.getLocation());
}
Another problem with your code is that I suspect you never properly call manager.shutDown() nor repository.shutDown(). Calling these when your program exits allows the manager and the repository to properly close resources, save state, and exit gracefully. Since you are creating a RepositoryManager object yourself, you need to care to do this on program exit yourself as well.
An alternative to creating your own RepositoryManager object is to use a RepositoryProvider instead (see also the relevant section in the Sesame Programmers Manual). This is a utility class that comes with a built-in shutdown hook, saving you from having to deal with these manager/repository shutdown issues.
So instead of this:
LocalRepositoryManager localManager = new LocalRepositoryManager(new File(dataDir));
localManager.initialize();
Do this:
LocalRepositoryManager localManager =
RepositoryProvider.getRepositoryManager(new File(datadir));
Using the "Network Updates API" example at the following link I am able to post network updates with no problem using client.postNetworkUpdate(updateText).
http://code.google.com/p/linkedin-j/wiki/GettingStarted
So posting works great.. However posting an update does not return an "UpdateKey" which is used to retrieve stats for post itself such as comments, likes, etc. Without the UpdateKey I cannot retrieve stats. So what I would like to do is post, then retrieve the last post using the getNetworkUpdates() function, and in that retrieval will be the UpdateKey that I need to use later to retrieve stats. Here's a sample script in Java on how to get network updates, but I need to do this in Coldfusion instead of Java.
Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.STATUS_UPDATE));
System.out.println("Total updates fetched:" + network.getUpdates().getTotal());
for (Update update : network.getUpdates().getUpdateList()) {
System.out.println("-------------------------------");
System.out.println(update.getUpdateKey() + ":" + update.getUpdateContent().getPerson().getFirstName() + " " + update.getUpdateContent().getPerson().getLastName() + "->" + update.getUpdateContent().getPerson().getCurrentStatus());
if (update.getUpdateComments() != null) {
System.out.println("Total comments fetched:" + update.getUpdateComments().getTotal());
for (UpdateComment comment : update.getUpdateComments().getUpdateCommentList()) {
System.out.println(comment.getPerson().getFirstName() + " " + comment.getPerson().getLastName() + "->" + comment.getComment());
}
}
}
Anyone have any thoughts on how to accomplish this using Coldfusion?
Thanks
I have not used that api, but I am guessing you could use the first two lines to grab the number of updates. Then use the overloaded client.getNetworkUpdates(start, end) method to retrieve the last update and obtain its key.
Totally untested, but something along these lines:
<cfscript>
...
// not sure about accessing the STATUS_UPDATE enum. One of these should work:
// method 1
STATUS_UPDATE = createObject("java", "com.google.code.linkedinapi.client.enumeration.NetworkUpdateType$STATUS_UPDATE");
// method 2
NetworkUpdateType = createObject("java", "com.google.code.linkedinapi.client.enumeration.NetworkUpdateType");
STATUS_UPDATE = NetworkUpdateType.valueOf("STATUS_UPDATE");
enumSet = createObject("java", "java.util.EnumSet");
network = yourClientObject.getNetworkUpdates(enumSet.of(STATUS_UPDATE));
numOfUpdates = network.getUpdates().getTotal();
// Add error handling in case numOfUpdates = 0
result = yourClientObject.getNetworkUpdates(numOfUpdates, numOfUpdates);
lastUpdate = result.getUpdates().getUpdateList().get(0);
key = lastUpdate.getUpdateKey();
</cfscript>
You can also use socialauth library to retrieve updates and post status on linkedin.
http://code.google.com/p/socialauth
I'm familiar with the java.sql.DatabaseMetaData interface, but I find it quite clunky to use. For example, in order to find out the table names, you have to call getTables and loop through the returned ResultSet, using well-known literals as the column names.
Is there an easier way to obtain database metadata?
It's easily done using DdlUtils:
import javax.sql.DataSource;
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
public void readMetaData(final DataSource dataSource) {
final Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
final Database database = platform.readModelFromDatabase("someName");
// Inspect the database as required; has objects like Table/Column/etc.
}
Take a look at SchemaCrawler (free and open source), which is another API designed for this purpose. Some sample SchemaCrawler code:
// Create the options
final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
// Set what details are required in the schema - this affects the
// time taken to crawl the schema
options.setSchemaInfoLevel(SchemaInfoLevel.standard());
options.setShowStoredProcedures(false);
// Sorting options
options.setAlphabeticalSortForTableColumns(true);
// Get the schema definition
// (the database connection is managed outside of this code snippet)
final Database database = SchemaCrawlerUtility.getDatabase(connection, options);
for (final Catalog catalog: database.getCatalogs())
{
for (final Schema schema: catalog.getSchemas())
{
System.out.println(schema);
for (final Table table: schema.getTables())
{
System.out.print("o--> " + table);
if (table instanceof View)
{
System.out.println(" (VIEW)");
}
else
{
System.out.println();
}
for (final Column column: table.getColumns())
{
System.out.println(" o--> " + column + " (" + column.getType()
+ ")");
}
}
}
}
http://schemacrawler.sourceforge.net/