JDO + GoogleAppEngine - search class by value in collection - java

I'm making application running on Google App Engine and I'm having problem with getting data using JDO. I have class Message, which has property private List<String> labels;. Now I want to have some search function which takes one string (label) as a parameter and searches all messages to get messages with given label. The problem is with the JDO query, right now I have
this (string this.label is a search parameter):
String query = "select from " + Message.class.getName() + " where (labels.contains('" + this.label + "')) ";
It works on localhost, but not in GAE (returns NULL). Another (and naive) attempt was
query = "select from " + Note.class.getName() + " where labels=='" + this.label + "'";
And it also worked only on localhost, not GAE
Does anybody have an idea how to do that? Thanks for any help

Basically your statement is wrong. It should be something like:
String query = "SELECT FROM " + Message.class.getName() +
" WHERE labels.contains(i) && i.label == labelParam " +
" VARIABLES " + Labels.class.getName() + " i " +
" PARAMETER java.lang.String labelParam "
Good Luck

Related

Issue with JPQL request take long time to execute with more then 600000 registrations

I have a query in jpql that normally walk with a reduced data count, the problem is when the table to them over 600000 data records.
I use spring data, with an entity that contains no relation (no OneToMany, OneToOne, ManyToOne .....)with oracle as database..
I used JpaRepository, crudRepository, I even tried with JDBC directly, the return takes between 8 min up to 30 min.
I thought the problem was coming from the request, so I tried a findAll () and the processing time remained the same.
I changed the settings of the JVM -Xmx and -Xms to give more memory, but nothing helps.
Here is the request that I make:
public interface TestRepository extends CrudRepository {
#Query(value = "select new Test(CONCAT(t.date1, t.stringTarget, t.numInfo), t.name, t.phone, t.numInfo, t.date1, t.cotations, t.stringTarget, p.code, p.design)"
+ " from Test t, PointVente p"
+ " WHERE t.ePdv = p.numero"
+ " AND t.date1 BETWEEN :dateBegin AND :dateEnd"
+ " AND (t.state <> 'ANCL' or t.state is null)"
+ " AND t.game in :game"
+ " AND t.type in :type"
+ " AND t.participe = 1"
+ " AND NOT EXISTS (select t2.numInfo, t2.date1"
+ " from Test t2"
+ " WHERE t2.date1 BETWEEN :dateBegin AND :dateEnd"
+ " AND (t2.state <> 'ANCL' or t2.state is null)"
+ " AND t2.game in :game"
+ " AND t2.type in :type"
+ " AND t2.participe = 1"
+ " AND t2.numInfo = t.numInfo"
+ " AND t2.date1 = t.date1"
+ " AND (t2.phone is null or t2.phone NOT IN (select b.phone from BlacklistTest b))"
+ " group by CONCAT(t2.date1, t2.numInfo), t2.name, t2.phone, t2.numInfo, t2.date1, t2.ePdv"
+ " having sum(t2.cotations) <= :target)"
+ " AND t.cotations > :target"
+ " AND (t.phone is null or t.phone NOT IN (select b.phone from BlacklistTest b))")
List<TestResult> findTest(#Param("dateBegin") Date dateBegin, #Param("dateEnd") Date dateEnd, #Param("game") List<String> game, #Param("type") List<String> type, #Param("target") BigDecimal target);
}
is it possible to reduce the response time?
May I have your help please.

Hibernate Query, how to use like or = on where clause depend on value passed

I have the following code and query :
String kodeCustomer, kodeDropship, kodeSales, kodePengirim;
kodeCustomer = kodeCustomerTextField.getText().trim();
kodeDropship = kodeDropshipTextField.getText().trim();
kodeSales = kodeSalesTextField.getText().trim();
kodePengirim = pengirimTextField.getText().trim();
... some other code ...
record = session.createQuery("from PenjualanTableDb where"
+ " dtanggalpenjualan >= :dawalParm"
+ " and dtanggalpenjualan < :dakhirParm"
+ " and coalesce(ckodecustomer,'') like :custParm"
+ " and coalesce(ckodedropship,'') like :dropshipParm"
+ " and coalesce(ckodesalesperson,'') like :salesParm"
+ " and coalesce(ckodepengirim,'') like :pengirimParm")
.setParameter("dawalParm", tanggalMulaiTrx)
.setParameter("dakhirParm", tanggalAkhirTrx)
.setParameter("custParm", kodeCustomer + "%")
.setParameter("dropshipParm", kodeDropship + "%")
.setParameter("salesParm", kodeSales + "%")
.setParameter("pengirimParm", kodePengirim + "%")
.list();
how to modify the query so it can give the correct output based on user input.
if textfield empty then the query using like, but if textfield not empty then query using =
Is there an easy way to handle that?
Thanks in advance
I think you should construct the hql query (including parameters) dynamically according to the parameters present instead of using "a like%".
record = session.createQuery("from PenjualanTableDb where"
+ " dtanggalpenjualan >= :dawalParm"
+ " and dtanggalpenjualan < :dakhirParm"
+ " and coalesce(ckodecustomer,'') like '%:custParm%'"
+ " and coalesce(ckodedropship,'') like '%:dropshipParm%'"
+ " and coalesce(ckodesalesperson,'') like '%:salesParm%'"
+ " and coalesce(ckodepengirim,'') like '%:pengirimParm%'")
.setParameter("dawalParm", tanggalMulaiTrx)
.setParameter("dakhirParm", tanggalAkhirTrx)
.setParameter("custParm", kodeCustomer)
.setParameter("dropshipParm", kodeDropship)
.setParameter("salesParm", kodeSales)
.setParameter("pengirimParm", kodePengirim)
.list();

How to put a sum in a String and print it

I'm currently working on a receipt of an Java application and I can't seem to get the sum on the screen. When is use the following query I get the sum in PHPMyAdmin but can't seem to find it in Java. I just can't print it because Java tells me all the column names I try are wrong. Does anyone know how to fix this?
If you want more code than this I can provide that but I'm kinda sure there is something faulty in the query and Java can't read it out. Help will be appreciated.
String sql = "SELECT sum((`barorder_drink`.`quantity` * `drink`.`price`)) + sum((`kitchenorder_dish`.`quantity` * `dish`.`price`))"
+ "FROM `barorder`, `barorder_drink`, `drink`, `kitchenorder`, `kitchenorder_dish`, `dish`, `restaurantorder`"
+ "WHERE `barorder`.`restaurantOrderId` = `restaurantorder`.`id`"
+ "AND `kitchenorder`.`restaurantOrderId` = `restaurantorder`.`id`"
+ "AND `barorder_drink`.`barorderId` = `barorder`.`id`"
+ "AND `barorder_drink`.`drinkId` = `drink`.`id`"
+ "AND `kitchenorder_dish`.`kitchenOrderId` = `kitchenorder`.`id`"
+ "AND `kitchenorder_dish`.`dishId` = `dish`.`id`"
+ "AND `restaurantorder`.`id` = '" + ID + "' ;";
Put your sum as a val and get this value like this
String sql = "SELECT sum(myattributes) AS val";
and when you want to get the result
int som = getInt("val");
Maybe when you do ))"
+ "FROM ...
The result is: ))FROM
and it sould be )) FROM

Is there any way to search in the properties of google drive files?

I want to search files like this but I am getting exception.
query = "mimeType ='application/pdf' and properties has { key="+ "'" + agency + "'" +"and value contains"+ "'" + someValue + "'" + " and visibility='PUBLIC'} ";
request = service.files().list().setQ(query);
Do we need to search by exact value?
query = "mimeType ='application/pdf' and properties has { key="+ "'" + agency + "'" +"and value = "+ "'" + someValue + "'" + " and visibility='PUBLIC'} ";
request = service.files().list().setQ(query);
The second one is working, but is there any feature to support wildcard characters?
Yes, for custom properties you have to seach with exact values
properties has { key='additionalID' and value='8e8aceg2af2ge72e78' and visibility='PRIVATE' }
https://developers.google.com/drive/web/search-parameters#properties
Yes, its in official docs (thou last year they werent searchable).
https://developers.google.com/drive/web/search-parameters#properties to search by exact value.

how to pass positional parameters to createnativequery jpa java

I have the following SQL query in my j2ee web app that I am unable to get to work, as-is. The named parameters sourceSystem and sourceClientId do not appear to get passed to the query, and therefore it does not return any records. I added a watch to the Query object querySingleView and it maintained a value of null as the debugger ran through the code. I also inserted a System.out.println statement just under the method declaration and confirmed that the correct values sourceSystem and sourceClientId are being passed to the method signature. I am using NetBeans 8.0, JPA 2.1, running on a JBoss EAP 6.21 server. I have multiple Entities mapped to several tables in an Oracle database.
Here is the query (I should note that the items in the query follow a schema.table.column format - not sure if that is part of the problem, but it does work in one test, see my comment and sample below the main query below):
public List<String> searchSingleView (String sourceSystem, String sourceClientId) {
//Change the underscore character in the source system value to a dash, and make it uppercase. This is what single view accepts
if (!sourceSystem.equals("")) {
sourceSystemSingleView = sourceSystem.replace('_', '-').toUpperCase();
}
String sqlSingleViewQuery = "SELECT DISTINCT " +
"MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM AS POLICY_SYSTEM, " +
"MDMCUST_ORS.C_BO_CONTRACT.SRC_POLICY_ID AS POLICY_ID, " +
"MDMCUST_ORS.C_BO_CONTRACT.ISSUE_DT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID AS SRC_CLIENT_ID, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.PERS_FULL_NAME_TXT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.ORG_LEGAL_NAME_TXT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.ORG_LEGAL_SFX_TXT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.ORG_NAME_TXT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.SIN_BIN_TEXT, " +
"MDMCUST_ORS.C_BO_PARTY_XREF.PERS_BIRTH_DT, " +
"MDMCUST_ORS.C_LU_CODES.CODE_DESCR_EN AS ADDRESS_PURPOSE_CD, " +
"MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.COMPLETE_ADDRESS_TXT, " +
"MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.CITY_NAME, " +
"MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.COUNTRY_NAME, " +
"MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.POSTAL_CD, " +
"MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.STATE_PROVINCE_NAME " +
"FROM MDMCUST_ORS.C_BO_PARTY_XREF " +
"LEFT JOIN MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR ON MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.PARTY_ROWID = MDMCUST_ORS.C_BO_PARTY_XREF.ROWID_OBJECT " +
"LEFT JOIN MDMCUST_ORS.C_LU_CODES ON MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.POSTAL_ADDR_PURPOSE_CD = MDMCUST_ORS.C_LU_CODES.CODE " +
"LEFT JOIN MDMCUST_ORS.C_BO_PARTY_REL ON MDMCUST_ORS.C_BO_PARTY_XREF.ROWID_OBJECT = MDMCUST_ORS.C_BO_PARTY_REL.FROM_PARTY_ROWID " +
"LEFT JOIN MDMCUST_ORS.C_BO_CONTRACT ON MDMCUST_ORS.C_BO_PARTY_REL.CONTRACT_ROWID = MDMCUST_ORS.C_BO_CONTRACT.ROWID_OBJECT " +
"WHERE MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM = :sourceSystemSingleView " +
"AND MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID = :sourceClientId " +
"AND MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.POSTAL_ADDR_PURPOSE_CD = '56|07' " +
"AND MDMCUST_ORS.C_BO_PARTY_POSTAL_ADDR.LAST_ROWID_SYSTEM = MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM " +
"ORDER BY MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM";
querySingleView = emSingleView.createQuery(sqlSingleViewQuery);
querySingleView.setParameter("sourceSystemSingleView", sourceSystemSingleView);
querySingleView.setParameter("sourceClientId", sourceClientId);
querySingleViewResult = (List<String>) querySingleView.getResultList();
return querySingleViewResult;
}
}
However, if I put literal values in the SQL query in place of the positional parameters it works fine (without using the setParameter method).
WHERE MDMCUST_ORS.C_BO_CONTRACT.LAST_ROWID_SYSTEM = 'ADMIN' " +
"AND MDMCUST_ORS.C_BO_PARTY_XREF.SRC_CLIENT_ID = '0000001234' " +
I have looked online but haven't as yet found anything that seems to address this specific question. Any help would be greatly appreciated. Thank you!

Categories