I am developing a software that has to transform a dataset in a graph database.
So far I have developed the dataset import. Basically, I open the file and afterward it is displayed in the tab1 and stored in a matrix of Objects.
Now, I don't have any idea on how to convert it in a graph database, and above all, I don't know how to map the dataset to the following ontology:
To be clearer I want to give a semantic to the dataset, mapping it to the specific ontology (for example, each element of the first column has to be under the node "elements" and the property that links each field of the first column to each field of the second column is under the node of "tuple"). In a nutshell, I have to link each field with the element of the same row. The first element, the second element, and the property that link both of them have to be linked to the specific part of the ontology.
How can I implement it, and which Java constructs I should study in order to implement it?
For the actual import you would create Cypher statements and run those on the database to create the nodes and relationships. For semantically correct node, relationship and property names, you just have to build the Cypher statements with those desired labels.
Also, you could use http://gist.neo4j.org/ to prototype your thoughts?
Related
I am trying to create a multi-layer menu with no restriction on how far it can branch out - e.g. Food->Fruits->Round Shape->color etc...
I am not sure how to represent the relationship in SQL and also am not sure how to query the data.
I thought about doing:
MainMenu:
ID:ChildID:Name:URL:PermissionID:etc.
SubMenu:
PID:ChildID:Name:URL:PermissionID:etc.
I think if the submenu has additional submenus, its children would be another item in the SubMenu table, and that should work? The PermissionID is used to determine if the Menu item can be accessed by a UserGroup.
I am not sure about the SQL query since i am a little green on it. I know in the end I am feeding UserGroup's PermissionIDs to the SQL to get all the Menu and Submenu from the tables.
Storing hierachical data in RDBMS is not a good idea. Either you can use document based frameworks like Elastic https://www.elastic.co/ which stores data in JSON document format or you can use hierachical JSON in varchar column in RDBMS.
I have three tables:
Department :
Designation :
Department Designations :
DesignationID and ReportTo are foreign keys of table designation, which shows that a specific designation report to a specific designation. i.e. Manager(Which is designation) Report to CEO(Which is also a designation )
Now I want to generate a tree, like...
I manually enter the entries to shows above tree . i.e
Now My Problem is that, I am not able to write a function in a way that generate this tree, automatically.
In short, After fetching records from database, I want to generate tree as shown above.
Any Solution ?
NOTE: LEVEL OF TREE IS NOT FIX, THERE MAY BE UNLIMITED LEVEL OF TREE
It's Java, so you can make that tree as deep as it needs to be.
Separate the query from the population of the tree from the UI rendering and you'll have no problem. Query the database, populate the tree and give it to the UI to render.
You'll have issues if you try to mingle one part with another.
You can use a Tree structure like this, and then populate it from the query.
Then, you will have different choices, for example:
1) You convert your tree to JSON and iterate it recursively with jQuery;
2) You iterate it directly in Java (recursively), building the output server-side (let's say a big String containing your HTML). Then you simply inject the result in the page (not that good because of coupling between server and client side)
etc...
Here's an hint.
It's a tree you need to iterate recursively over the tree items till
you reach the leaf level in order to populate it and as mentioned in
answer give by #duffymo you should separate logic of tree population
from your query.
Link if you still are unable to solve
Best luck :-)
i think you could use php for drawing this tree.
example.
write the join query for selecting data to row
<li>
while(!empty($row))
{
echo'<li><ul>$row[designation name]';
while(!empty($next))
{echo'<li><ul>$next[designation name]';
//next sentence must be a select query
}
echo'</ul></li>'
}
echo'</ul><li>'
}
this is not ur answer but a hint that can tell the logic.
Here is the problem that i am currently stuck with for the past few days. And I am looking for guidance / approaches on how to handle.Hints & suggestions welcome.
so here is the problem.The database has a table "group" which has two columns : group_id on parent_group_id.group_id is the primary key for the table .All entries in this table represent groups/sub-groups.If one adds a sub-group from the front end ,then an entry gets inserted in to the group table with an auto-generated group_id which MySQL generates.the parent_group_id corresponds to the group_id of the group on which a sub-group was added.So in essence it's acting like a foreign key to the group_id column.My task cut out here is to generate an XML in java using the data from the group table. So this is where i am stuck.I know it's gonna be a recursive function which needs to be written but cant figure out a way how to dynamically create the nodes and fill the data from the Db at the same time.The end XML needs to be sent as json data to the front end.
A group can have n-sub groups and the hierarchy can go on.For ex- Say Vehicle is root node with group_id =1.It can have cars & bikes as sub-groups.so the parent_group_id will be 1 for car and bike and group id say will be 2& 3 respectively.
P.S: this is the first time i am posting here having had used this site for the past one year.Please let me know if any more info is needed or whether you are able to comprehend my problem.
If you split the task into two, it will be more manageable.
Here are some useful links on querying hierarchical data in relational databases and specifically in MySQL:
What are the options for storing hierarchical data in a relational database?
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
http://www.slideshare.net/billkarwin/models-for-hierarchical-data
http://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression
As long as you have the query result properly sorted, you will be able to traverse it recursively, building the XML tree step by step.
Was able to solve it by using recursive functions :). Loaded all the data using the entity class and then iterated over the data using recursive functions to build the tree like structure.I didn't try and take the sql way.
In my Java application I want to create a table whose data field will be updated dynamically. The table is not linked with any database. The tables' data fields are ArrayList or List type data so I want to update the fields when they are changing. I was looking into the jtable but was unable to find the way to do that. Anyone knows the solution is highly appreciated..
I think you should do the following
Create a class for each table
to create dynamic fields implement a map which stores name of the field as key and its value as the value of the map
create one object for each row and store them, in List(or map if you want to do indexing)
Implement search functions
Update it as and when required.
Jtable is the component for UI, You can easily use it and if there is some problem in displaying the data, you are always welcome to ask.
I am currently working with a Java based web application (JSF) backed by Hibernate that has a variety of different search pages for different areas.
A search page contains a search fields section, which a user can customize the search fields that they are interested in. There are a range of different search field types that can be added (exact text, starts with, contains, multi-select list boxes, comma separated values, and many more). Search fields are not required to be filled in and are ignored, where as some other search fields require a different search field to have a value for this search field to work.
We currently use a custom search object per area that is specific to that area and has hard coded getter and setter search fields.
public interface Search {
SearchFieldType getSearchPropertyOne();
void setSearchPropertyOne(SearchFieldType searchPropertyOne);
AnotherSearchFieldType getSearchPropertyTwo();
void setSearchPropertyTwo(AnotherSearchFieldType searchPropertyTwo);
...
}
In this example, SearchFieldType and AnotherSearchFieldType represent different search types like a TextSearchField or a NumericSearchField which has a search type (Starts with, Contains, etc.) or (Greater Than, Equals, Less Than, etc.) respectively and a search value that they can enter or leave empty (to ignore the search field).
We use this search object to prepare a Criteria object
The search results section is a table that can also be customized by the user to contain only columns of the result object that they are interested in. Most columns can be ordered ascending or descending.
We back our results in a Result object per result which also hard codes the columns that can be displayed. This table is backed by hibernate annotations, but we are trying to use flat data instead of allowing other hibernate backed objects to minimize lazy joining data.
#Entity(table = "result_view")
public interface Result {
#Column(name = "result_field_one")
Long getResultFieldOne();
void setResultFieldOne(Long resultFieldOne);
#Column(name = "result_field_two")
String getResultFieldTwo();
void setResultFieldTwo(String resultFieldTwo);
...
}
The search page is backed by a view in our database which handles the joining to all the tables needed for every possible outcome. This view has gotten pretty massive and we take a huge performance hit for every search, even when a user only really wants to search on one field and display a few columns because we have upwards of thirty search field options and thirty different columns they can display and this is all backed by the one view.
On top of this, users request new search fields and columns all the time that they would like added to the page. We end up having to alter the search and result objects as well as the backing view to make these changes.
We are trying to look into this matter and find alternatives to this. One approach mentioned was to create different views that we dynamically choose based on the fields searched on or displayed in the results table. The different views might join different columns and we pick and choose which view we need for any given search.
I'm trying to think about the problem a different way. I think it might be better to not use a view and instead dynamically join tables we need based on what search fields and result columns are requested. I also feel that the search and result objects should not contain hard coded getters/setters and should instead be a collection of search fields and a collection (or map) of result columns. I have yet to completely flesh out my idea.
Would hibernate still be a valid solution to this issue? I wouldn't want to have to create a Result object used in a hibernate criteria since they result columns can be different. Both search fields and/or result columns might require joining tables.
Is there a framework I could use that might help solve the problem? I've been trying to look for something, and the closest thing I have found is SqlBuilder.
Has anyone else solved a similar problem dynamically?
I would prefer not to reinvent the wheel if a solution already exists.
I apologize that this ended up as a wall of text. This is my first stackoverflow post, and I wanted to make sure I thoroughly defined my problem.
Thanks in advance for your answers!
I don't fully understand the problem. But JPA Criteria API seems very flexible, which can be used to build query based on user-submitted filtering conditions.