Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

In this page you can find the example usage for java.util ListIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:com.emc.ecs.sync.target.S3Target.java

@Override
public void filter(SyncObject obj) {
    try {/*from  w w  w. ja  v a 2 s.c om*/
        // skip the root of the bucket since it obviously exists
        if ("".equals(rootKey + obj.getRelativePath())) {
            log.debug("Target is bucket root; skipping");
            return;
        }

        // some sync objects lazy-load their metadata (i.e. AtmosSyncObject)
        // since this may be a timed operation, ensure it loads outside of other timed operations
        if (!(obj instanceof S3ObjectVersion) || !((S3ObjectVersion) obj).isDeleteMarker())
            obj.getMetadata();

        // Compute target key
        String targetKey = getTargetKey(obj);
        obj.setTargetIdentifier(AwsS3Util.fullPath(bucketName, targetKey));

        if (includeVersions) {
            ListIterator<S3ObjectVersion> sourceVersions = s3Source.versionIterator((S3SyncObject) obj);
            ListIterator<S3ObjectVersion> targetVersions = versionIterator(obj);

            boolean newVersions = false, replaceVersions = false;
            if (force) {
                replaceVersions = true;
            } else {

                // special workaround for bug where objects are listed, but they have no versions
                if (sourceVersions.hasNext()) {

                    // check count and etag/delete-marker to compare version chain
                    while (sourceVersions.hasNext()) {
                        S3ObjectVersion sourceVersion = sourceVersions.next();

                        if (targetVersions.hasNext()) {
                            S3ObjectVersion targetVersion = targetVersions.next();

                            if (sourceVersion.isDeleteMarker()) {

                                if (!targetVersion.isDeleteMarker())
                                    replaceVersions = true;
                            } else {

                                if (targetVersion.isDeleteMarker())
                                    replaceVersions = true;

                                else if (!sourceVersion.getETag().equals(targetVersion.getETag()))
                                    replaceVersions = true; // different checksum
                            }

                        } else if (!replaceVersions) { // source has new versions, but existing target versions are ok
                            newVersions = true;
                            sourceVersions.previous(); // back up one
                            putIntermediateVersions(sourceVersions, targetKey); // add any new intermediary versions (current is added below)
                        }
                    }

                    if (targetVersions.hasNext())
                        replaceVersions = true; // target has more versions

                    if (!newVersions && !replaceVersions) {
                        log.info("Source and target versions are the same. Skipping {}", obj.getRelativePath());
                        return;
                    }
                }
            }

            // something's off; must delete all versions of the object
            if (replaceVersions) {
                log.info(
                        "[{}]: version history differs between source and target; re-placing target version history with that from source.",
                        obj.getRelativePath());

                // collect versions in target
                List<DeleteObjectsRequest.KeyVersion> deleteVersions = new ArrayList<>();
                while (targetVersions.hasNext())
                    targetVersions.next(); // move cursor to end
                while (targetVersions.hasPrevious()) { // go in reverse order
                    S3ObjectVersion version = targetVersions.previous();
                    deleteVersions.add(new DeleteObjectsRequest.KeyVersion(targetKey, version.getVersionId()));
                }

                // batch delete all versions in target
                log.debug("[{}]: deleting all versions in target", obj.getRelativePath());
                s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(deleteVersions));

                // replay version history in target
                while (sourceVersions.hasPrevious())
                    sourceVersions.previous(); // move cursor to beginning
                putIntermediateVersions(sourceVersions, targetKey);
            }

        } else { // normal sync (no versions)
            Date sourceLastModified = obj.getMetadata().getModificationTime();
            long sourceSize = obj.getMetadata().getContentLength();

            // Get target metadata.
            ObjectMetadata destMeta = null;
            try {
                destMeta = s3.getObjectMetadata(bucketName, targetKey);
            } catch (AmazonS3Exception e) {
                if (e.getStatusCode() != 404)
                    throw new RuntimeException("Failed to check target key '" + targetKey + "' : " + e, e);
            }

            if (!force && obj.getFailureCount() == 0 && destMeta != null) {

                // Check overwrite
                Date destLastModified = destMeta.getLastModified();
                long destSize = destMeta.getContentLength();

                if (destLastModified.equals(sourceLastModified) && sourceSize == destSize) {
                    log.info("Source and target the same.  Skipping {}", obj.getRelativePath());
                    return;
                }
                if (destLastModified.after(sourceLastModified)) {
                    log.info("Target newer than source.  Skipping {}", obj.getRelativePath());
                    return;
                }
            }
        }

        // at this point we know we are going to write the object
        // Put [current object version]
        if (obj instanceof S3ObjectVersion && ((S3ObjectVersion) obj).isDeleteMarker()) {

            // object has version history, but is currently deleted
            log.debug("[{}]: deleting object in target to replicate delete marker in source.",
                    obj.getRelativePath());
            s3.deleteObject(bucketName, targetKey);
        } else {
            putObject(obj, targetKey);

            // if object has new metadata after the stream (i.e. encryption checksum), we must update S3 again
            if (obj.requiresPostStreamMetadataUpdate()) {
                log.debug("[{}]: updating metadata after sync as required", obj.getRelativePath());
                CopyObjectRequest cReq = new CopyObjectRequest(bucketName, targetKey, bucketName, targetKey);
                cReq.setNewObjectMetadata(AwsS3Util.s3MetaFromSyncMeta(obj.getMetadata()));
                s3.copyObject(cReq);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to store object: " + e, e);
    }
}

From source file:org.powertac.householdcustomer.customers.Household.java

/**
 * This is the function utilized to show the information regarding the
 * household in question, its variables values etc.
 * //from  www .j av  a  2s  . c  om
 * @return
 */
void showStatus() {

    // Printing basic variables
    log.info("HouseHold Name : " + name);
    log.info("Number of Persons : " + members.size());

    // Printing daily load
    log.info(" Daily Load = ");
    for (int i = 0; i < VillageConstants.DAYS_OF_COMPETITION + VillageConstants.DAYS_OF_BOOTSTRAP; i++) {
        log.info("Day " + i);
        ListIterator<Integer> iter2 = weeklyBaseLoad.get(i).listIterator();
        ListIterator<Integer> iter3 = weeklyControllableLoad.get(i).listIterator();
        ListIterator<Integer> iter4 = weeklyWeatherSensitiveLoad.get(i).listIterator();
        for (int j = 0; j < VillageConstants.QUARTERS_OF_DAY; j++)
            log.info("Quarter : " + j + " Base Load : " + iter2.next() + " Controllable Load: " + iter3.next()
                    + " WeatherSensitive Load: " + iter4.next());
    }

    // Printing daily load in hours
    log.info(" Load In Hours = ");
    for (int i = 0; i < VillageConstants.DAYS_OF_COMPETITION + VillageConstants.DAYS_OF_BOOTSTRAP; i++) {
        log.info("Day " + i);
        ListIterator<Integer> iter2 = weeklyBaseLoadInHours.get(i).listIterator();
        ListIterator<Integer> iter3 = weeklyControllableLoadInHours.get(i).listIterator();
        ListIterator<Integer> iter4 = weeklyWeatherSensitiveLoadInHours.get(i).listIterator();
        for (int j = 0; j < VillageConstants.HOURS_OF_DAY; j++)
            log.info("Hours : " + j + " Base Load : " + iter2.next() + " Controllable Load: " + iter3.next()
                    + " WeatherSensitive Load: " + iter4.next());
    }
}

From source file:de.unisb.cs.st.javaslicer.tracer.instrumentation.TracingMethodInstrumenter.java

private boolean followedByJumpLabel(final ListIterator<AbstractInsnNode> iterator) {
    if (!iterator.hasNext())
        return false;
    final AbstractInsnNode nextInsn = iterator.next();
    iterator.previous();/*ww  w.  j  av  a2 s  .c  o  m*/
    for (AbstractInsnNode insn = nextInsn; insn != null; insn = insn.getNext()) {
        if (insn instanceof LabelNode && this.jumpTargetLabels.contains(insn))
            return true;
        if (!(insn instanceof FrameNode || insn instanceof LineNumberNode))
            break;
    }
    return false;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMySql.CFAsteriskMySqlVersionTable.java

public CFInternetVersionBuff[] readDerivedByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//ww  w.  j av a 2  s. c  o  m
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_verndef_cc_by_tenantidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadClassCodeByTenantIdx == null) {
            stmtReadClassCodeByTenantIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++, TenantId);
        try {
            resultSet = stmtReadClassCodeByTenantIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        while ((resultSet != null) && resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
    List<CFInternetVersionBuff> resultList = new LinkedList<CFInternetVersionBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("VERN")) {
            CFInternetVersionBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MJVR")) {
            CFInternetMajorVersionBuff[] subList = schema.getTableMajorVersion()
                    .readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MNVR")) {
            CFInternetMinorVersionBuff[] subList = schema.getTableMinorVersion()
                    .readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    int idx = 0;
    CFInternetVersionBuff[] retBuff = new CFInternetVersionBuff[resultList.size()];
    Iterator<CFInternetVersionBuff> iter = resultList.iterator();
    while (iter.hasNext()) {
        retBuff[idx++] = iter.next();
    }
    return (retBuff);

}

From source file:org.powertac.officecomplexcustomer.customers.OfficeComplex.java

/**
 * This function is creating a certain number of random days that will be
 * public vacation for the people living in the environment.
 * /*w  w w  .ja  v  a  2s .c om*/
 * @param days
 * @param gen
 * @return
 */
Vector<Integer> createPublicVacationVector(int days) {
    // Creating auxiliary variables
    Vector<Integer> v = new Vector<Integer>(days);

    for (int i = 0; i < days; i++) {
        int x = gen
                .nextInt(OfficeComplexConstants.DAYS_OF_COMPETITION + OfficeComplexConstants.DAYS_OF_BOOTSTRAP);
        ListIterator<Integer> iter = v.listIterator();
        while (iter.hasNext()) {
            int temp = (int) iter.next();
            if (x == temp) {
                x = x + 1;
                iter = v.listIterator();
            }
        }
        v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMySql.CFAsteriskMySqlRealProjectTable.java

public CFInternetRealProjectBuff[] readDerivedByTenantIdx(CFSecurityAuthorization Authorization,
        long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from  w w  w. ja  v  a2s  .c  om*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_rprjdef_cc_by_tenantidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadClassCodeByTenantIdx == null) {
            stmtReadClassCodeByTenantIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++, TenantId);
        try {
            resultSet = stmtReadClassCodeByTenantIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        while ((resultSet != null) && resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
    List<CFInternetRealProjectBuff> resultList = new LinkedList<CFInternetRealProjectBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("RPRJ")) {
            CFInternetRealProjectBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("TPRJ")) {
            CFInternetTopProjectBuff[] subList = schema.getTableTopProject().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("SPRJ")) {
            CFInternetSubProjectBuff[] subList = schema.getTableSubProject().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    int idx = 0;
    CFInternetRealProjectBuff[] retBuff = new CFInternetRealProjectBuff[resultList.size()];
    Iterator<CFInternetRealProjectBuff> iter = resultList.iterator();
    while (iter.hasNext()) {
        retBuff[idx++] = iter.next();
    }
    return (retBuff);

}

From source file:com.ibm.asset.trails.service.impl.ReconWorkspaceServiceImpl.java

@Transactional(readOnly = false, propagation = Propagation.NOT_SUPPORTED)
public List<Long> findAffectedAlertUnlicensedSwList(Account pAccount, List<ReconWorkspace> plReconWorkspace,
        String psRunOn) {/*w w  w  . j a v  a2  s. c  o  m*/
    ListIterator<ReconWorkspace> lliReconWorkspace = plReconWorkspace.listIterator();
    ReconWorkspace lrwTemp = null;
    List<Long> results;

    if (psRunOn.equalsIgnoreCase("SELECTED")) {
        List<Long> llAlertUnlicensedSwId = new ArrayList<Long>();

        while (lliReconWorkspace.hasNext()) {
            lrwTemp = lliReconWorkspace.next();
            llAlertUnlicensedSwId.add(lrwTemp.getAlertId());
        }
        results = alertDAO.findAffectedAlertList(llAlertUnlicensedSwId);
    } else {
        List<Long> llProductInfoId = new ArrayList<Long>();
        Map<Long, Long> lmProductInfoId = new HashMap<Long, Long>();

        while (lliReconWorkspace.hasNext()) {
            lrwTemp = lliReconWorkspace.next();

            if (!lmProductInfoId.containsKey(lrwTemp.getProductInfoId())) {
                llProductInfoId.add(lrwTemp.getProductInfoId());
            }
        }

        if (psRunOn.equalsIgnoreCase("ALL")) {
            results = alertDAO.findAffectedAlertList(pAccount, llProductInfoId);
        } else {
            results = alertDAO.findAffectedAlertList(pAccount, llProductInfoId, psRunOn);
        }
    }

    return results;
}

From source file:FastArrayList.java

/**
 * Compare the specified object with this list for equality.  This
 * implementation uses exactly the code that is used to define the
 * list equals function in the documentation for the
 * <code>List.equals</code> method.
 *
 * @param o Object to be compared to this list
 *//*from  w  w  w.jav a 2s.  co m*/
public boolean equals(Object o) {

    // Simple tests that require no synchronization
    if (o == this)
        return (true);
    else if (!(o instanceof List))
        return (false);
    List lo = (List) o;

    // Compare the sets of elements for equality
    if (fast) {
        ListIterator li1 = list.listIterator();
        ListIterator li2 = lo.listIterator();
        while (li1.hasNext() && li2.hasNext()) {
            Object o1 = li1.next();
            Object o2 = li2.next();
            if (!(o1 == null ? o2 == null : o1.equals(o2)))
                return (false);
        }
        return (!(li1.hasNext() || li2.hasNext()));
    } else {
        synchronized (list) {
            ListIterator li1 = list.listIterator();
            ListIterator li2 = lo.listIterator();
            while (li1.hasNext() && li2.hasNext()) {
                Object o1 = li1.next();
                Object o2 = li2.next();
                if (!(o1 == null ? o2 == null : o1.equals(o2)))
                    return (false);
            }
            return (!(li1.hasNext() || li2.hasNext()));
        }
    }

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlVersionTable.java

public CFAccVersionBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//from w  w  w  .  j av a 2 s  .com
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_verndef_cc_by_tenantidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadClassCodeByTenantIdx == null) {
            stmtReadClassCodeByTenantIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++, TenantId);
        try {
            resultSet = stmtReadClassCodeByTenantIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        while ((resultSet != null) && resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
    List<CFAccVersionBuff> resultList = new LinkedList<CFAccVersionBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("VERN")) {
            CFAccVersionBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MJVR")) {
            CFAccMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MNVR")) {
            CFAccMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    int idx = 0;
    CFAccVersionBuff[] retBuff = new CFAccVersionBuff[resultList.size()];
    Iterator<CFAccVersionBuff> iter = resultList.iterator();
    while (iter.hasNext()) {
        retBuff[idx++] = iter.next();
    }
    return (retBuff);

}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlVersionTable.java

public CFAstVersionBuff[] readDerivedByTenantIdx(CFAstAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//w  ww .  ja  v  a  2s.com
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_verndef_cc_by_tenantidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadClassCodeByTenantIdx == null) {
            stmtReadClassCodeByTenantIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadClassCodeByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadClassCodeByTenantIdx.setLong(argIdx++, TenantId);
        try {
            resultSet = stmtReadClassCodeByTenantIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        while ((resultSet != null) && resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
    List<CFAstVersionBuff> resultList = new LinkedList<CFAstVersionBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("VERN")) {
            CFAstVersionBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MJVR")) {
            CFAstMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MNVR")) {
            CFAstMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    int idx = 0;
    CFAstVersionBuff[] retBuff = new CFAstVersionBuff[resultList.size()];
    Iterator<CFAstVersionBuff> iter = resultList.iterator();
    while (iter.hasNext()) {
        retBuff[idx++] = iter.next();
    }
    return (retBuff);

}