Java, hibernate + oracle. Users are stored in datababase and have national characters in their names (ü, ß etc). Now I need to create a convenient search function. Example: when user type 'do', 'dö' or 'doe' then entry 'Fidörner' should be found. Currently there are only 3 rules like above one defined by business but I expect there will more.
what are the recommended solutions? google search appliance? lucene? hibernate search? solr? custom text normalization (can it be done quickly)? any other tools?
Take a look at Oracle Text. It's a free option installed by default on your database.
For example:
create table users(name varchar2(100));
insert into users values ('Fidörner');
insert into users values ('Fido');
insert into users values ('Smith');
commit;
begin
ctx_ddl.drop_preference('mylex');
ctx_ddl.create_preference('mylex', 'basic_lexer');
ctx_ddl.set_attribute('mylex', 'base_letter', 'YES');
ctx_ddl.set_attribute('mylex','alternate_spelling','german');
end;
/
create index users_index on users(name)
indextype is ctxsys.ctxcat parameters ('LEXER mylex');
select * from users where catsearch(name, '**do*', null) > 0;
select * from users where catsearch(name, '**dö*', null) > 0;
select * from users where catsearch(name, '**doe*', null) > 0;
All return:
Name
----
Fidörner
Fido
Related
I have a table named users in which there is accountlocked field ... the possible values of that field are Y and N ... if the user from frontend logs in with 3attempts of wrong password then accountlocked will be Y which means account is locked... but I have a specific user that I don’t want the accountlocked to be updated to Y... I created a trigger which can update it to N once it is Y... but I just don’t want the field to be updated to Y atall in the first for that specific user
CREATE OR REPLACE TRIGGER traccountunlock AFTER
UPDATE OF accountlocked ON users
FOR EACH ROW
WHEN (new.username=‘Testuser ’)
BEGIN
IF :new.accountlocked = 'Y' THEN
UPDATE users
SET
accountlocked = 'N'
WHERE
username IN (
'Testuser'
);
END IF;
END;
This works but it does it after the field is updated to Y,but I don’t want it to update to Y at the first place something like instead of ... but instead of works only for views not tables in oracle
Note: I can do it through java code but, I’m not looking for that solution as it needs deploy and future issues
What are constraints for?
create table t (
username varchar2(30),
accountlocked varchar2(1) check( accountlocked in ('Y','N') ),
constraint not_lock_testuser check( (username,accountlocked) != (('Testuser', 'Y')) )
);
Done!
Best regards,
Stew Ashton
It would be this one. However, I think you should solve it better on application level.
CREATE OR REPLACE TRIGGER traccountunlock
BEFORE UPDATE OF accountlocked ON users
FOR EACH ROW
WHEN (new.username = 'Testuser')
BEGIN
IF :new.accountlocked = 'Y' THEN
:new.accountlocked := 'N';
END IF;
END;
--Just Updated with the working version
Can we change content of Power BI report using Power BI REST API, say in
some report 'Col A' has been used and I want to change it to 'Col
B'. 'Col A' and 'Col B' are in same dataset and same table.
In updatereportcontent API, what can be the possible value of
sourcetypeenum apart from 'ExistingReport'?
https://learn.microsoft.com/en-us/rest/api/power-bi/reports/updatereportcontent#sourcetypeenum
I am using Power BI native application to do this task.
First about question #2 - as you can see in the link you gave, ExistingReport is the only possible value.
About your first question - you can't do this directly using the API. However, you can use a text value parameter (let's name it ColName) to hold the name of the column you want to select. Modify the M query for fetching the data from the database by changing it from:
let
Source = Sql.Database(ServerName, DatabaseName, [Query="select Col1, Col2, ColA from Sales.Orders"])
in
Source
to:
let
Source = Sql.Database(ServerName, DatabaseName, [Query="select Col1, Col2, " & ColName & " as ColA from Sales.Orders"])
in
Source
Then use Update Parameters or Update Parameters In Group API to change the value of ColName parameter (to let's say ColB). If this is imported dataset, you must refresh it using Refresh Dataset or Refresh Dataset In Group after that.
I'm going crazy with all possible query syntaxes used on IBM Notes (old Lotus) databases for searching documents.
I just need all documents (i.e. emails) created (or delivered, which seems to be the same) between a given range of dates, using lotus.domino.Database.search(query) method in Java package for IBM Notes. Consider that I already know the dates format in my system ("dd/MM/yyyy").
Which should be the query?
First of all: To find out about the syntax just create a view in Domino Designer or check the views that are there (e.g. in your own mail database) and check the "Selection"- formula. Then remove the "SELECT" statement in front of it and use that as query.
Your query would be quite simple:
Form = "Memo" : "Reply" & #Date(#Created) >= [2018/01/01] & #Date(#Created) <= [2018/05/04]
if you are not sure, which date format your server uses, then just use this query instead:
Form = "Memo" : "Reply" &
#Date(#Created) >= #Date( 2018 ; 1 ; 1 ) &
#Date(#Created) <= #Date( 2018 ; 5 ; 4 )
This is the right formula for all mail- types. If you need alle calendar- type- documents, then use Form = "Appointment" : "Notice".
As a rule of thumb: Just go to the items- tab in the properties of any document you want to return and examine all items in the left hand site. Then simply use the item name in your formula as variable (except Body: That one would need special treatment).
How do you implement automatically generated database (let it be SQL) requests?
Let us have offline shop with filters:
The database is standalone offline.
SO if I want to filter items by Price the request would be something like:
select Snowboard.Name
from Snowboard
where Snowboard.Price between 400 and 600;
And if I filter by two characteristics e.g. Price from and Camber. There would be:
select s.Name, s.Camber
from Snowboard s
where s.Price between 400 and 600
and s.Camber in ('Rocker', 'Hybrid');
The question is how could it be implemented in Java so that these requests are generated automatically from any combination of filters selected?
Quick and dirty solution #1
Generate a query at run time & make clever use of WHERE 1=1 condition as the number of where clause are unknown. (This sample is in C# but works more or less the same with JAVA as well)
string sql= #"select Snowboard.Name
from Snowboard
where 1=1";
Now you can build your query based on the UI element selections like
string whereClause="";
if(yourCheckBoxPrice.Checked)
{
whereClause+= " AND Price BETWEEN "+ txtPriceFrom.Text + " AND "+ txtPriceTo.Text;
}
if(yourCheckBoxCamber.Checked)
{
whereClause+= " AND Camber IN ("+ /* your list of values go here */ +")";
}
sql += whereClause;
2nd Solution (Use SQL CASE)
You can use SQL CASE inside your query for each where clause to check for nulls or specific values. But beware, dynamic SQL will make your code pretty messy & hard to read (Can be done via a stored procedure as well)
SQL- CASE Statement
I advise you to use a stored procedure with a mix of both options 1 and 2. Implementing Dynamic SQL Where Clause. Keep it simple and you are good to go.
I'm working on a webapp served by Tomcat and Apache httpd the uses Struts 1.3.6 and Tomcat 6.
This app talks to Oracle and MySQL databases. The Oracle DB has 14 different schemas and I have a select query that I want to put into an hbm.xml file that uses 8 tables from 3 of the Oracle schemas. The intent is to dynamically add addition where clauses based on user input from the DynaActionForm.
I'm not allowed to build the select as an ad-hoc query and put it in the factory or action as shown in Hibernate - Complex Query from multiple Tables to one object.
Is this possible? If so, examples of this being done would be helpful.
Thanks
EDIT: I should have noted that the is a Hibernate session manager for the MySQL DB plus another for each of the Oracle schemas.
EDIT: The query in quesion...
select distinct
ca.addr_no as customer_number, decode(max(ctn.telephone_no),min(ctn.telephone_no),max(ctn.telephone_no),max(ctn.telephone_no)||', '||min(ctn.telephone_no)) as phone, ca.secondary_addressable_object||' '||ca.primary_addressable_object||' '||ca.street_name as street,
ca.primary_addressable_object, ca.street_name, ca.town_name as suburb, ca.postcode, ii.incident_ref, rd.report_ref, ii.description, ii.inc_category_id, ii.oz_name,
isl.look_up_description as status, ii.group_id, rlu.look_up_description as cause, to_char(ii.creation_date,'dd/mm/yyyy hh24:mi') as creation_date, nvl(cpa.link_reference,'VACANT') as nmi,
rc.report_id, ii.creation_date, ii.primary_ref, (ii.completed_date - ii.creation_date) as duration
from
tcs.inc_incident ii, pbr.rpt_details rd, enmac.look_up_list isl,
pbr.rpt_incident ri, pbr.rpt_reason rr, pbr.rpt_look_up rlu,
pbr.rpt_restoration_customers rc, tcs.cd_telephone_no ctn, tcs.cd_addresses ca,
tcs.cd_cust_property_assoc cpa, pbr.rpt_restoration_stages rs
where
ii.incident_id(+) = ri.incident_id||''
and ri.report_id||'' = rd.report_id(+)
and ii.status+0 = isl.look_up_reference(+)
and isl.look_up_name(+)||'' = 'Incident Status'
and ri.report_id||'' = rr.report_id(+)
and rr.cause_group||'' = rlu.look_up_code(+)
and rlu.look_up_field(+)||'' = 'CAUSE_GROUP'
and ri.report_id(+) = rc.report_id||''
and rc.pro_number(+) = ca.addr_no+0
and rc.stage_id||'' = rs.stage_id(+)
and rc.report_id||'' = rs.report_id(+)
and cpa.customer_no+0 = ctn.pro_number(+)
and cpa.customer_no(+) = ca.addr_no+0
and rs.status(+) = 0
optionally:
and ri.storm_flag(+) != 1 and rd.status(+) != -6
Continuing:
and ca.addr_no in (
With a while bunch more sub selects which vary depending on user input in the form.
I know that I'll need to convert from the old Oracle join style to the ANSI standard as part of this...