Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master (#11) #12

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions framework/service/org/moqui/impl/EntitySyncServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,10 @@ along with this software (see the LICENSE.md file). If not, see
// ec.logger.warn("=========== get#EntitySyncData entityName=${entryMap.entityName} count=${currentCount} find=${find}")

if (currentCount > 0) {
EntityListIterator resultEli = find.iterator()
try {
find.iterator().withCloseable ({resultEli ->
int levels = entryMap.dependents ? 2 : 0
resultEli.writeXmlText((Writer) entityWriter, null, levels)
} finally {
resultEli.close()
}
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import org.moqui.BaseArtifactException
import org.moqui.Moqui
import org.moqui.context.ExecutionContext
import org.moqui.context.NotificationMessage
import org.moqui.context.NotificationMessage.NotificationType
import org.moqui.entity.EntityFacade
import org.moqui.entity.EntityList
import org.moqui.entity.EntityListIterator
import org.moqui.entity.EntityValue
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -93,20 +91,17 @@ class NotificationMessageImpl implements NotificationMessage, Externalizable {

// notify by group, skipping users already notified
if (userGroupId) {
EntityListIterator eli = ef.find("moqui.security.UserGroupMember")
ef.find("moqui.security.UserGroupMember")
.conditionDate("fromDate", "thruDate", new Timestamp(System.currentTimeMillis()))
.condition("userGroupId", userGroupId).disableAuthz().iterator()
try {
.condition("userGroupId", userGroupId).disableAuthz().iterator().withCloseable ({eli ->
EntityValue nextValue
while ((nextValue = (EntityValue) eli.next()) != null) {
String userId = (String) nextValue.userId
if (checkedUserIds.contains(userId)) continue
checkedUserIds.add(userId)
if (checkUserNotify(userId, ef)) notifyUserIds.add(userId)
}
} finally {
eli.close();
}
})
}

// add all users subscribed to all messages on the topic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ class EntityDataDocument {
// do the one big query
String lastDocId = null
int docCount = 0
EntityListIterator mainEli = mainFind.iterator()
try {
try (EntityListIterator mainEli = mainFind.iterator()) {
logger.info("Feed dataDocumentId ${dataDocumentId} query complete (cursor opened) in ${System.currentTimeMillis() - startTimeMillis}ms")
EntityValue ev
while ((ev = (EntityValue) mainEli.next()) != null) {
Expand Down Expand Up @@ -345,7 +344,6 @@ class EntityDataDocument {
efi.ecfi.serviceFacade.sync().name(feedReceiveServiceName).parameter("documentList", documentMapList).call()
}
} finally {
mainEli.close()
logger.info("Feed dataDocumentId ${dataDocumentId} feed complete and cursor closed in ${System.currentTimeMillis() - startTimeMillis}ms")
}

Expand All @@ -366,16 +364,14 @@ class EntityDataDocument {
ArrayList<Map> documentMapList = ddi.hasAllPrimaryPks ? null : new ArrayList<Map>()

// do the one big query
EntityListIterator mainEli = mainFind.iterator()
try {

mainFind.iterator().withCloseable ({mainEli->
EntityValue ev
while ((ev = (EntityValue) mainEli.next()) != null) {
// logger.warn("=========== DataDocument query result for ${dataDocumentId}: ${ev}")
mergeValueToDocMap(ev, ddi, documentMapMap, documentMapList, docTsString)
}
} finally {
mainEli.close()
}
})

// make the actual list and return it
if (ddi.hasAllPrimaryPks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.moqui.impl.entity

import groovy.json.JsonBuilder
import groovy.transform.CompileStatic
import org.moqui.entity.EntityValue
import org.moqui.util.ObjectUtilities

Expand All @@ -35,6 +36,7 @@ import java.time.format.DateTimeFormatter
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

@CompileStatic
class EntityDataWriterImpl implements EntityDataWriter {
private final static Logger logger = LoggerFactory.getLogger(EntityDataWriterImpl.class)

Expand Down Expand Up @@ -170,9 +172,9 @@ class EntityDataWriterImpl implements EntityDataWriter {
EntityDefinition ed = efi.getEntityDefinition(en)
boolean useMaster = masterName != null && masterName.length() > 0 && ed.getMasterDefinition(masterName) != null
EntityFind ef = makeEntityFind(en)
EntityListIterator eli = ef.iterator()

try {

try (EntityListIterator eli = ef.iterator()) {
if (!eli.hasNext()) continue

String filename = path + '/' + en + '.' + fileType.name().toLowerCase()
Expand Down Expand Up @@ -200,8 +202,6 @@ class EntityDataWriterImpl implements EntityDataWriter {
} finally {
pw.close()
}
} finally {
eli.close()
}
}
} catch (Throwable t) {
Expand Down Expand Up @@ -248,8 +248,7 @@ class EntityDataWriterImpl implements EntityDataWriter {
EntityDefinition ed = efi.getEntityDefinition(en)
boolean useMaster = masterName != null && masterName.length() > 0 && ed.getMasterDefinition(masterName) != null
EntityFind ef = makeEntityFind(en)
EntityListIterator eli = ef.iterator()
try {
try (EntityListIterator eli = ef.iterator()) {
if (!eli.hasNext()) continue

String filenameBase = tableColumnNames ? ed.getTableName() : en
Expand All @@ -274,8 +273,6 @@ class EntityDataWriterImpl implements EntityDataWriter {
} finally {
out.closeEntry()
}
} finally {
eli.close()
}
}
} finally {
Expand All @@ -289,7 +286,13 @@ class EntityDataWriterImpl implements EntityDataWriter {
int writer(Writer writer) {
if (dependentLevels > 0) efi.createAllAutoReverseManyRelationships()

LinkedHashSet<String> activeEntityNames = skipEntityNames.size() > 0 ? entityNames - skipEntityNames : entityNames
LinkedHashSet<String> activeEntityNames
if (skipEntityNames.size() == 0) {
activeEntityNames = entityNames
} else {
activeEntityNames = new LinkedHashSet<>(entityNames)
activeEntityNames.removeAll(skipEntityNames)
}
EntityDefinition singleEd = null
if (activeEntityNames.size() == 1) singleEd = efi.getEntityDefinition(activeEntityNames.first())

Expand All @@ -305,15 +308,11 @@ class EntityDataWriterImpl implements EntityDataWriter {
for (String en in activeEntityNames) {
EntityDefinition ed = efi.getEntityDefinition(en)
boolean useMaster = masterName != null && masterName.length() > 0 && ed.getMasterDefinition(masterName) != null
EntityFind ef = makeEntityFind(en)
EntityListIterator eli = ef.iterator()
try {
try (EntityListIterator eli = makeEntityFind(en).iterator()) {
EntityValue ev
while ((ev = eli.next()) != null) {
valuesWritten+= writeValue(ev, writer, useMaster)
}
} finally {
eli.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,19 +1149,18 @@ abstract class EntityFindBase implements EntityFind {
}

// call the abstract method
EntityListIterator eli
try { eli = iteratorExtended(queryWhereCondition, havingCondition, orderByExpanded, fieldInfoArray, fieldOptionsArray) }
try (EntityListIterator eli = iteratorExtended(queryWhereCondition, havingCondition, orderByExpanded, fieldInfoArray, fieldOptionsArray)) {
MNode databaseNode = this.efi.getDatabaseNode(ed.getEntityGroupName())
if (limit != null && databaseNode != null && "cursor".equals(databaseNode.attribute("offset-style"))) {
el = (EntityListImpl) eli.getPartialList(offset != null ? offset : 0, limit, false)
} else {
el = (EntityListImpl) eli.getCompleteList(false);
}
}
catch (SQLException e) { throw new EntitySqlException(makeErrorMsg("Error finding list of", LIST_ERROR, queryWhereCondition, ed, ec), e) }
catch (ArtifactAuthorizationException e) { throw e }
catch (Exception e) { throw new EntityException(makeErrorMsg("Error finding list of", LIST_ERROR, queryWhereCondition, ed, ec), e) }

MNode databaseNode = this.efi.getDatabaseNode(ed.getEntityGroupName())
if (limit != null && databaseNode != null && "cursor".equals(databaseNode.attribute("offset-style"))) {
el = (EntityListImpl) eli.getPartialList(offset != null ? offset : 0, limit, true)
} else {
el = (EntityListImpl) eli.getCompleteList(true)
}

// register lock after because we can't before, don't know which records will be returned
if (forUpdate && !isViewEntity && efi.ecfi.transactionFacade.getUseLockTrack()) {
int elSize = el.size()
Expand Down Expand Up @@ -1446,9 +1445,7 @@ abstract class EntityFindBase implements EntityFind {

this.useCache(false)
long totalUpdated = 0
EntityListIterator eli = (EntityListIterator) null
try {
eli = iterator()
iterator().withCloseable ({eli ->
EntityValue value
while ((value = eli.next()) != null) {
value.putAll(fieldsToSet)
Expand All @@ -1458,9 +1455,7 @@ abstract class EntityFindBase implements EntityFind {
totalUpdated++
}
}
} finally {
if (eli != null) eli.close()
}
})
return totalUpdated
}

Expand Down Expand Up @@ -1495,33 +1490,27 @@ abstract class EntityFindBase implements EntityFind {
}
} else {
this.resultSetConcurrency(ResultSet.CONCUR_UPDATABLE)
EntityListIterator eli = (EntityListIterator) null
try {
eli = iterator()
iterator().withCloseable ({eli->

while (eli.next() != null) {
// no longer need to clear cache, eli.remove() does that
eli.remove()
totalDeleted++
}
} finally {
if (eli != null) eli.close()
}
})
}
return totalDeleted
}

@Override
void extract(SimpleEtl etl) {
EntityListIterator eli = iterator()
try {
try (EntityListIterator eli = iterator()) {
EntityValue ev
while ((ev = eli.next()) != null) {
etl.processEntry(ev)
}
} catch (StopException e) {
logger.warn("EntityFind extract stopped on: " + (e.getCause()?.toString() ?: e.toString()))
} finally {
eli.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public EntityValueBase currentEntityValueBase() {
} catch (SQLException e) {
throw new EntityException("Error getting all results", e);
} finally {
//TODO: Remove closeAfter with respect to try-with-resource implementation
if (closeAfter) close();
}
}
Expand Down
10 changes: 3 additions & 7 deletions framework/src/test/groovy/EntityNoSqlCrud.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,19 @@ class EntityNoSqlCrud extends Specification {

def "ELI find TestNoSqlEntity"() {
when:
EntityListIterator eli
EntityList partialEl = null
EntityValue first = null
try {
eli = ec.entity.find("moqui.test.TestNoSqlEntity")
.orderBy("-testNumberInteger").iterator()
try (EntityListIterator eli = ec.entity.find("moqui.test.TestNoSqlEntity")
.orderBy("-testNumberInteger").iterator()) {


partialEl = eli.getPartialList(0, 100, false)

eli.beforeFirst()
first = eli.next()
} catch (Exception e) {
logger.error("partialEl error", e)
} finally {
if (eli != null) eli.close()
}

// logger.warn("partialEl.size() ${partialEl.size()} first value ${first}")

then:
Expand Down
Loading