java


Is it possible to retrieve an object that is split into three tables with only one query?


EDIT: The answers works, but slow down the query a lot. Is there another solution?
I have the following object in my program.
Page haves various TextBlock that haves various Token.
The three are stored in the database in three tables with the same namas of the objects.
I want to know if is possible to recover all the data needed to fill the object in the program with only one query.
I want only one query because I'm using a CURSOR to iterate over all the objects stored in the database.
The database scheme is this:
Page(id, someAttributes)
TextBlock(id,pageId, someAttributes)
Token(textblockId, someAttributes)
Assuming that every Page has at least one Textblock with at least one Token each try
SELECT * FROM
Page AS P
INNER JOIN TextBlock T ON T.pageId = P.id
INNER JOIN Token TK ON TK.textblockId = T.id;
Alternatively (old syntax):
SELECT * FROM
Page AS P, TextBlock T, Token TK WHERE
T.pageId = P.id AND
TK.textblockId = T.id;
IF it is possible that the above condition is not always true then you need to use OUTER JOIN instead of INNER JOIN.
Yes it is possible with a 3 way join.
You'll get one row per Token in this case.
So you'll need to loop and fetch all rows from the cursor and appropriately create the objects as you see new Page ids, TextBlock ids, etc.
NOTE: You'll need to use outer joins, in case a TextBlock has no Tokens, so the TextBlock would still be retrieved (with null values for Token attributes). Same for Pages with no TextBlock.
Select
Page.someAttributes,
TextBlock.someAttributes,
Token.someAttributes
From
Page,
TextBlock,
Token
Where
Page.id = TextBlock.pageId
AND
TextBlock.id = Token.textblockId
Group By
Page.id

Related Links

How to upload multiple files in Play Framework using Java
java.lang.ExceptionInitializerError while reading xlsx file in Java/liferay
How to insert random integers in a binary search tree
What is the appropriate date formatting so the lexicographic ordering is the same as time ordering?
Deserializing Objects in Java
How to remove the two digit or one digit after the comma and the remaining character after that? -Regex [closed]
Setting the context-root in Spring Restdocs
How to add a method to JOptionPane
How to clear cache of other applications in android M (6.0) programmatically
There's some way to get value through especific gettter in JSF? [duplicate]
How to align panels with BoxLayout and FlowLayout
parsing XML file in MapReduce
If Statement dependent on what command line arugment is passed? [duplicate]
Trouble passing directories into java application via command line
Type mismatch: cannot convert from int to int[] error in Java code
Add/Inject Agent to Queue in Anylogic

Categories

HOME
cakephp
sendgrid
client
blogger
webpack
isabelle
single-sign-on
layout
adb
google-oauth
react-redux
blueprintjs
wamp
timeout
moonmail
commonmark
decimal
designer
caml
database-replication
normalizr
samoa
karma-jasmine
visual-composer
jprofiler
autocad-plugin
kryo
java-3d
graphicsmagick
qhull
poltergeist
chromebook
elasticsearch-ruby
gitignore
google-cloud-nl
noraui
copying
kendo-ui-grid
lxd
repo
environment-modules
bower-install
plsql-psp
dynamics-crm-2013
abstract-class
jna
g-code
janrain
google-closure
http-live-streaming
node-sass
angular2-meteor
babel-core
dandelion
lift-json
python-cryptography
gcsfuse
parallel-data-warehouse
nxt
database-optimization
mongocsharpdriver
firebaseui
hill-climbing
javax.sound.midi
vhd
cartesian-product
t4mvc
ionic
microbenchmark
dia
codeigniter-routing
preferences
openexr
elliptic-curve
didselectrowatindexpath
industrial
c18
cdc
jmapviewer
batterylevel
sharp-repository
manchester-syntax
subscript
zpt
coercion
pyinotify
sortable-tables
multi-tier
substrings
noscript
nerddinner
.net-1.0
commodore
signal-handling

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App