1

I have an EntityCondition and I want to get SQL from it. For example

EntityCondition: partyId = 'admin'
-> SQL:  party_id = 'admin'

I have tried to find in OFBiz project, but I have not found anything.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
  • I'm not sure what you want to achieve, please be more specific. For the above, there is at least the entity you want to select missing. For Party it would be: SELECT * FROM PARTY WHERE PARTY_ID = 'admin'; – Michael Brohl Jul 24 '15 at 10:32
  • @MichaelBrohl When we use EntityCondition#toString(), we will get `partyId = 'admin'`, but to query to database i must be `party_id` not `partyId`. – Rong Nguyen Jul 24 '15 at 10:36

2 Answers2

3

There's a general rule in OFBiz: entities and fields are defined in CamelCase, like PartyAttribute or productId. Entities begin with an uppercase letter (like a Java class) and fields begin with a lowercase letter (like a Java class attribute).

An uppercase letter inside the entity or field is converted to "_[lowercase]".

So

EntityCondition: partyId = 'admin'
-> SQL:  party_id = 'admin'

A full select for entity PartyAttribute would be

SELECT * FROM PARTY_ATTRIBUTE WHERE PARTY_ID = 'admin'

You may try

makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo)

to achieve this programmatically, but I haven't tried it.

Michael Brohl
  • 782
  • 5
  • 21
2

In

\ofbiz_src\framework\entity\src\org\ofbiz\entity\datasource\GenericDAO.java you will see something like (In Apache Ofbiz 13, it stand about in about line 808 or nearby)

makeOffsetString(sqlBuffer, findOptions);
String sql = sqlBuffer.toString();

Add a line of code for printing query

makeOffsetString(sqlBuffer, findOptions);
String sql = sqlBuffer.toString();
System.out.println("SQL query: >>>" + sql);

By this way, you just able see query with parameter ?, you cannot see value of parameter ? in real world, like HQL query log in Hibernate.

Vy Do
  • 46,709
  • 59
  • 215
  • 313