Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cadastroweb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Participatorio
cadastroweb
Commits
84f2df55
Commit
84f2df55
authored
10 years ago
by
Bruno Nocera Zanette
Browse files
Options
Downloads
Patches
Plain Diff
Fix municipio query & optimize query construction
Fix municipio query & optimize query construction
parent
5fc7fd33
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/br/ufpr/c3sl/estacaojuventude/Programa.java
+24
-43
24 additions, 43 deletions
src/main/java/br/ufpr/c3sl/estacaojuventude/Programa.java
with
24 additions
and
43 deletions
src/main/java/br/ufpr/c3sl/estacaojuventude/Programa.java
+
24
−
43
View file @
84f2df55
...
...
@@ -133,32 +133,19 @@ public class Programa {
*
*/
public
static
List
<
Programa
>
findWithParameters
(
String
nomeOficial
,
String
nomeMunicipio
,
Set
<
Tematica
>
tematicas
)
{
String
querySelectFrom
=
"SELECT distinct p.* FROM programa p, ocorrencia_municipal o"
;
String
queryWhere
=
" WHERE p.status = 'Efetivo' AND o.status = 'Efetivo'"
;
String
querySelect
=
"SELECT distinct p.*"
;
String
queryFrom
=
" FROM programa p"
;
String
queryWhere
=
" WHERE p.status = 'Efetivo'"
;
String
query
=
""
;
if
(
tematicas
.
isEmpty
())
{
if
(
nomeOficial
!=
null
&&
nomeMunicipio
==
null
){
queryWhere
+=
" AND LOWER(p.nome_oficial) LIKE LOWER('%"
+
nomeOficial
+
"%')"
;
}
else
if
(
nomeOficial
==
null
&&
nomeMunicipio
!=
null
){
querySelectFrom
+=
", municipio m"
;
queryWhere
+=
" AND o.municipio = m.id"
;
queryWhere
+=
" AND p.id = o.programa_vinculado AND LOWER(m.nome) LIKE LOWER('%"
+
nomeMunicipio
+
"%')"
;
}
else
if
(
nomeOficial
!=
null
&&
nomeMunicipio
!=
null
)
{
querySelectFrom
+=
", municipio m"
;
queryWhere
+=
" AND o.municipio = m.id"
;
queryWhere
+=
" AND LOWER(p.nome_oficial) LIKE LOWER('%"
+
nomeOficial
+
"%')"
;
queryWhere
+=
" AND p.id = o.programa_vinculado AND LOWER(m.nome) LIKE LOWER('%"
+
nomeMunicipio
+
"%')"
;
}
}
else
{
//(!tematicas.isEmpty())
querySelectFrom
+=
" ,programa_tematicas pt, tematica t"
;
if
(!
tematicas
.
isEmpty
())
{
queryFrom
+=
" ,programa_tematicas pt, tematica t"
;
queryWhere
+=
" AND p.id = pt.programa AND t.id = pt.tematicas"
;
String
strTemas
=
"("
;
Integer
i
=
0
;
Integer
tam
=
tematicas
.
size
();
String
strTemas
=
"("
;
for
(
Iterator
<
Tematica
>
t
=
tematicas
.
iterator
();
t
.
hasNext
();)
{
strTemas
+=
"t.nome = '"
+
t
.
next
().
getNome
()+
"'"
;
i
++;
...
...
@@ -166,28 +153,22 @@ public class Programa {
strTemas
+=
" OR "
;
}
strTemas
+=
")"
;
if
(
nomeOficial
==
null
&&
nomeMunicipio
==
null
){
queryWhere
+=
" AND "
+
strTemas
;
}
else
if
(
nomeOficial
!=
null
&&
nomeMunicipio
==
null
)
{
queryWhere
+=
" AND LOWER(p.nome_oficial) LIKE LOWER('%"
+
nomeOficial
+
"%')"
;
queryWhere
+=
" AND "
+
strTemas
;
}
else
if
(
nomeOficial
==
null
&&
nomeMunicipio
!=
null
)
{
querySelectFrom
+=
", municipio m"
;
queryWhere
+=
" AND o.municipio = m.id"
;
queryWhere
+=
" AND p.id = o.programa_vinculado AND LOWER(m.nome) LIKE LOWER('%"
+
nomeMunicipio
+
"%')"
;
queryWhere
+=
" AND "
+
strTemas
;
}
else
if
(
nomeOficial
!=
null
&&
nomeMunicipio
!=
null
)
{
querySelectFrom
+=
", municipio m"
;
queryWhere
+=
" AND o.municipio = m.id"
;
if
(
nomeOficial
!=
null
){
queryWhere
+=
" AND LOWER(p.nome_oficial) LIKE LOWER('%"
+
nomeOficial
+
"%')"
;
queryWhere
+=
" AND p.id = o.programa_vinculado AND LOWER(m.nome) LIKE LOWER('%"
+
nomeMunicipio
+
"%')"
;
queryWhere
+=
" AND "
+
strTemas
;
}
if
(
nomeMunicipio
!=
null
){
queryFrom
+=
", ocorrencia_municipal o, ocorrencia_municipal_municipios om, municipio m"
;
queryWhere
+=
" AND o.status = 'Efetivo'"
;
queryWhere
+=
" AND p.id = o.programa_vinculado AND o.id = om.ocorrencia_municipal AND om.municipios = m.id"
;
queryWhere
+=
" AND LOWER(m.nome) LIKE LOWER('%"
+
nomeMunicipio
+
"%')"
;
}
query
=
querySelectFrom
+
queryWhere
;
query
=
querySelect
+
queryFrom
+
queryWhere
;
return
entityManager
().
createNativeQuery
(
query
,
Programa
.
class
).
getResultList
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment