Il supporto API del delegatore Apache ofBiz fa recuperare l'elenco dei record dal database per limite o offset

StackOverflow https://stackoverflow.com/questions/5410461

  •  29-10-2019
  •  | 
  •  

Domanda

Diciamo che dobbiamo recuperare solo 5 record da una tabella, ma la mia clausola Where corrisponde a 25K record nel database. Quindi c'è un modo in OFBiz Framework per selezionare solo 5 record anziché ottenere un elenco dal database e poi prendere solo 5 dall'elenco?

Se il limite non è possibile (poiché l'API OFBIZ è agnostico del database) Quali sono le mie altre alternative?

È stato utile?

Soluzione

Ti suggerirei di dare un'occhiata a questo Libro di cucina del motore di entità

Essenzialmente per ottenere un set limitato di righe dal database che faresti:

// first get a list iterator
productsELI = delegator.findListIteratorByCondition("Product", 
  new EntityExpr("productId", EntityOperator.NOT_EQUAL, null), 
                  UtilMisc.toList("productId"), null);

// then get a partial list by count TO RETURN first 5 records
productsELI.getPartialList(0, 5);

// and finally just close the iterator
productsELI.close();

Anche se preferisci inviare Diretti SQL al tuo database Allora fai così:

// gets the helper (localmysql, localpostgres, etc.) for your entity group org.ofbiz
String helperName = delegator.getGroupHelperName("org.ofbiz");
SQLProcessor sqlproc = new SQLProcessor(helperName);
sqlproc.prepareStatement("SELECT * FROM PARTY LMIT 0, 5");
ResultSet rs1 = sqlproc.executeQuery();

// and then get your data from ResultSet like regular JDBC
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top