Example usage for org.apache.commons.lang StringUtils startsWithIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils startsWithIgnoreCase.

Prototype

public static boolean startsWithIgnoreCase(String str, String prefix) 

Source Link

Document

Case insensitive check if a String starts with a specified prefix.

Usage

From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java

@SuppressWarnings("StringBufferReplaceableByString")
public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable)
        throws SQLException {
    ResultSet resultSet = null;/*from  w  w w . ja  v a  2s .c  o m*/
    VitessStatement vitessStatement = new VitessStatement(this.connection);

    if (null == table) {
        throw new SQLException("Table Parameter cannot be null in getBestRowIdentifier");
    }

    String[] columnName = new String[] { "SCOPE", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE",
            "BUFFER_LENGTH", "DECIMAL_DIGITS", "PSEUDO_COLUMN" };

    Query.Type[] columnType = new Query.Type[] { Query.Type.INT16, Query.Type.CHAR, Query.Type.INT32,
            Query.Type.CHAR, Query.Type.INT32, Query.Type.INT32, Query.Type.INT16, Query.Type.INT16 };

    ArrayList<ArrayList<String>> data = new ArrayList<>();

    try {
        resultSet = vitessStatement.executeQuery("SHOW COLUMNS FROM " + this.quotedId + table + this.quotedId
                + "" + " FROM " + this.quotedId + catalog + this.quotedId);

        while (resultSet.next()) {
            ArrayList<String> row = new ArrayList<>();
            String keyType = resultSet.getString("Key");
            if (keyType != null && StringUtils.startsWithIgnoreCase(keyType, "PRI")) {
                row.add(Integer.toString(DatabaseMetaData.bestRowSession));
                row.add(resultSet.getString("Field"));
                String type = resultSet.getString("Type");
                int size = this.maxBufferSize;
                int decimals = 0;
                if (type.indexOf("enum") != -1) {
                    String temp = type.substring(type.indexOf("("), type.indexOf(")"));
                    StringTokenizer tokenizer = new StringTokenizer(temp, ",");

                    int maxLength;
                    for (maxLength = 0; tokenizer.hasMoreTokens(); maxLength = Math.max(maxLength,
                            tokenizer.nextToken().length() - 2))
                        ;

                    size = maxLength;
                    decimals = 0;
                    type = "enum";
                } else if (type.indexOf("(") != -1) {
                    if (type.indexOf(",") != -1) {
                        size = Integer.parseInt(type.substring(type.indexOf("(") + 1, type.indexOf(",")));
                        decimals = Integer.parseInt(type.substring(type.indexOf(",") + 1, type.indexOf(")")));
                    } else {
                        size = Integer.parseInt(type.substring(type.indexOf("(") + 1, type.indexOf(")")));
                    }

                    type = type.substring(0, type.indexOf("("));
                }

                row.add(Integer.toString(MysqlDefs.mysqlToJavaType(type)));
                row.add(type);
                row.add(Integer.toString(size + decimals));
                row.add(Integer.toString(size + decimals));
                row.add(Integer.toString(decimals));
                row.add(Integer.toString(DatabaseMetaData.bestRowNotPseudo));
                data.add(row);
            }
        }
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
        vitessStatement.close();
    }
    return new VitessResultSet(columnName, columnType, data, this.connection);
}

From source file:com.sfs.whichdoctor.dao.onlineapplication.BasicTrainingOnlineApplicationHandler.java

/**
 * Load the assessment.//from  w w  w  .j  a  v  a 2s . c  o m
 *
 * @param record the record
 * @param division the division
 * @param preferences the preferences
 * @return the collection
 */
private Collection<AssessmentBean> loadAssessment(final Element record, final String division,
        final PreferencesBean preferences) {

    Collection<AssessmentBean> assessments = new ArrayList<AssessmentBean>();

    // A basic rotation has one set of assessments associated to it
    AssessmentBean assessment = new AssessmentBean();
    assessment.setAssessmentType("Standard");
    assessment.setApproved("Not reviewed");
    assessment.setStatus("Not accredited");

    // Build the notes
    StringBuffer sb = new StringBuffer();
    sb.append(processNote(record, "StaffNotes", "Staff notes"));
    sb.append(processNote(record, "DPTNotes", "DPT notes"));
    sb.append(processNote(record, "StaffTraineeNotes", "Trainee notes"));

    assessment.setAccreditationComment(sb.toString());

    if (preferences != null) {
        assessment.setCommitteeSpecialty(preferences.getOption("specialty", "adult"));

        if (StringUtils.startsWithIgnoreCase(division, "P")) {
            assessment.setCommitteeSpecialty(preferences.getOption("specialty", "paediatric"));
        }
    }
    assessments.add(assessment);

    return assessments;
}

From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java

@VisibleForTesting
void extractForeignKeyForTable(List<ArrayList<String>> rows, String createTableString, String catalog,
        String table) throws SQLException {
    StringTokenizer lineTokenizer = new StringTokenizer(createTableString, "\n");

    while (lineTokenizer.hasMoreTokens()) {
        String line = lineTokenizer.nextToken().trim();
        String constraintName = null;
        if (StringUtils.startsWithIgnoreCase(line, "CONSTRAINT")) {
            boolean usingBackTicks = true;
            int beginPos = io.vitess.util.StringUtils.indexOfQuoteDoubleAware(line, this.quotedId, 0);
            if (beginPos == -1) {
                beginPos = line.indexOf("\"");
                usingBackTicks = false;/*from w  w w . j a v a2 s.  co m*/
            }
            if (beginPos != -1) {
                int endPos;
                if (usingBackTicks) {
                    endPos = io.vitess.util.StringUtils.indexOfQuoteDoubleAware(line, this.quotedId,
                            beginPos + 1);
                } else {
                    endPos = io.vitess.util.StringUtils.indexOfQuoteDoubleAware(line, "\"", beginPos + 1);
                }
                if (endPos != -1) {
                    constraintName = line.substring(beginPos + 1, endPos);
                    line = line.substring(endPos + 1, line.length()).trim();
                }
            }
        }

        if (line.startsWith("FOREIGN KEY")) {
            if (line.endsWith(",")) {
                line = line.substring(0, line.length() - 1);
            }
            int indexOfFK = line.indexOf("FOREIGN KEY");
            String localColumnName = null;
            String referencedCatalogName = io.vitess.util.StringUtils.quoteIdentifier(catalog, this.quotedId);
            String referencedTableName = null;
            String referencedColumnName = null;
            if (indexOfFK != -1) {
                int afterFk = indexOfFK + "FOREIGN KEY".length();

                int indexOfRef = io.vitess.util.StringUtils.indexOfIgnoreCase(afterFk, line, "REFERENCES",
                        this.quotedId, this.quotedId);
                if (indexOfRef != -1) {
                    int indexOfParenOpen = line.indexOf('(', afterFk);
                    int indexOfParenClose = io.vitess.util.StringUtils.indexOfIgnoreCase(indexOfParenOpen, line,
                            ")", this.quotedId, this.quotedId);
                    localColumnName = line.substring(indexOfParenOpen + 1, indexOfParenClose);

                    int afterRef = indexOfRef + "REFERENCES".length();
                    int referencedColumnBegin = io.vitess.util.StringUtils.indexOfIgnoreCase(afterRef, line,
                            "(", this.quotedId, this.quotedId);

                    if (referencedColumnBegin != -1) {
                        referencedTableName = line.substring(afterRef, referencedColumnBegin);
                        int referencedColumnEnd = io.vitess.util.StringUtils.indexOfIgnoreCase(
                                referencedColumnBegin + 1, line, ")", this.quotedId, this.quotedId);
                        if (referencedColumnEnd != -1) {
                            referencedColumnName = line.substring(referencedColumnBegin + 1,
                                    referencedColumnEnd);
                        }
                        int indexOfCatalogSep = io.vitess.util.StringUtils.indexOfIgnoreCase(0,
                                referencedTableName, ".", this.quotedId, this.quotedId);
                        if (indexOfCatalogSep != -1) {
                            referencedCatalogName = referencedTableName.substring(0, indexOfCatalogSep);
                            referencedTableName = referencedTableName.substring(indexOfCatalogSep + 1);
                        }
                    }
                }
            }
            if (constraintName == null) {
                constraintName = "not_available";
            }
            List<String> localColumnsList = io.vitess.util.StringUtils.split(localColumnName, ",",
                    this.quotedId, this.quotedId);
            List<String> referColumnsList = io.vitess.util.StringUtils.split(referencedColumnName, ",",
                    this.quotedId, this.quotedId);
            if (localColumnsList.size() != referColumnsList.size()) {
                throw new SQLException("Mismatch columns list for foreign key local and reference columns");
            }
            // Report a separate row for each column in the foreign key. All values the same except the column name.
            for (int i = 0; i < localColumnsList.size(); i++) {
                String localColumn = localColumnsList.get(i);
                String referColumn = referColumnsList.get(i);
                ArrayList<String> row = new ArrayList<>(14);
                row.add(io.vitess.util.StringUtils.unQuoteIdentifier(referencedCatalogName, this.quotedId)); // PKTABLE_CAT
                row.add(null); // PKTABLE_SCHEM
                row.add(io.vitess.util.StringUtils.unQuoteIdentifier(referencedTableName, this.quotedId)); // PKTABLE_NAME
                row.add(io.vitess.util.StringUtils.unQuoteIdentifier(referColumn, this.quotedId)); // PKCOLUMN_NAME
                row.add(catalog); // FKTABLE_CAT
                row.add(null); // FKTABLE_SCHEM
                row.add(table); // FKTABLE_NAME
                row.add(io.vitess.util.StringUtils.unQuoteIdentifier(localColumn, this.quotedId)); // FKCOLUMN_NAME
                row.add(Integer.toString(i + 1)); // KEY_SEQ
                int[] actions = getForeignKeyActions(line);
                row.add(Integer.toString(actions[1])); // UPDATE_RULE
                row.add(Integer.toString(actions[0])); // DELETE_RULE
                row.add(constraintName); // FK_NAME
                row.add(null); // PK_NAME
                row.add(Integer.toString(java.sql.DatabaseMetaData.importedKeyNotDeferrable)); // DEFERRABILITY
                rows.add(row);
            }
        }
    }
}

From source file:adalid.commons.velocity.Writer.java

private String getTemplate(File propertiesFile) {
    String slashedPath;// ww w .  j a va 2  s .c  o m
    String shortestPath = null;
    String propertiesFilePath = propertiesFile.getPath().replace(FILE_SEPARATOR, SLASH);
    String[] velocityFileResourceLoaderPathArray = VelocityEngineer.getFileResourceLoaderPathArray();
    if (velocityFileResourceLoaderPathArray != null && velocityFileResourceLoaderPathArray.length > 0) {
        for (String path : velocityFileResourceLoaderPathArray) {
            //              slashedPath = path.replace(FILE_SEPARATOR, SLASH);
            slashedPath = StringUtils.removeEnd(path.replace(FILE_SEPARATOR, SLASH), SLASH) + SLASH;
            if (StringUtils.startsWithIgnoreCase(propertiesFilePath, slashedPath)) {
                if (shortestPath == null || slashedPath.length() < shortestPath.length()) {
                    shortestPath = slashedPath;
                }
            }
        }
    }
    if (shortestPath == null) {
        return propertiesFile.getName();
    }
    String template = StringUtils.removeStartIgnoreCase(propertiesFilePath, shortestPath);
    //      return StringUtils.removeStartIgnoreCase(template, SLASH);
    return template;
}

From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java

protected Long createInstance(Long farmNo, String instanceName, Long platformNo, String comment, Long imageNo) {
    // ?//from ww  w  . j ava2  s . c  o m
    if (farmNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "farmNo");
    }
    if (instanceName == null || instanceName.length() == 0) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceName");
    }
    if (platformNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "platformNo");
    }
    if (imageNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "imageNo");
    }

    // ??
    if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", instanceName)) {
        throw new AutoApplicationException("ECOMMON-000012", "instanceName");
    }

    // ???
    Image image = imageDao.read(imageNo);
    Platform platform = platformDao.read(platformNo);
    if (platformNo.equals(image.getPlatformNo()) == false) {
        throw new AutoApplicationException("ESERVICE-000405", imageNo, platform.getPlatformName());
    }

    // TODO: ??

    // ?????
    Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(farmNo, instanceName);
    if (checkInstance != null) {
        // ???????
        throw new AutoApplicationException("ESERVICE-000401", instanceName);
    }

    // ?????
    LoadBalancer checkLoadBalancer = loadBalancerDao.readByFarmNoAndLoadBalancerName(farmNo, instanceName);
    if (checkLoadBalancer != null) {
        // ????????
        throw new AutoApplicationException("ESERVICE-000417", instanceName);
    }

    // ??
    Farm farm = farmDao.read(farmNo);
    if (farm == null) {
        throw new AutoApplicationException("ESERVICE-000406", farmNo);
    }

    // fqdn???
    String fqdn = instanceName + "." + farm.getDomainName();
    if (fqdn.length() > 63) {
        throw new AutoApplicationException("ESERVICE-000418", fqdn);
    }

    // TODO: ??

    // VMware??Windows???VMware??????Windows????????
    // TODO: OS??
    if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())
            && StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)) {
        List<Instance> allInstances = instanceDao.readAll();
        for (Instance instance2 : allInstances) {
            if (StringUtils.equals(instanceName, instance2.getInstanceName())) {
                Platform platform2 = platformDao.read(instance2.getPlatformNo());
                if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform2.getPlatformType())) {
                    Image image2 = imageDao.read(instance2.getImageNo());
                    if (StringUtils.startsWithIgnoreCase(image2.getOs(), PCCConstant.OS_NAME_WIN)) {
                        // VMware?????Windows???
                        throw new AutoApplicationException("ESERVICE-000419", instanceName);
                    }
                }
            }
        }
    }

    // ??
    String instanceCode = passwordGenerator.generate(20);

    // ??
    Instance instance = new Instance();
    instance.setFarmNo(farmNo);
    instance.setInstanceName(instanceName);
    instance.setPlatformNo(platformNo);
    instance.setImageNo(imageNo);
    instance.setEnabled(false);
    instance.setComment(comment);
    instance.setFqdn(fqdn);
    instance.setInstanceCode(instanceCode);
    instance.setStatus(InstanceStatus.STOPPED.toString());
    instanceDao.create(instance);

    // TODO: OS??
    if (!StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType()))
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType()))
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType()))) {
        // OpenStack?Puppet?????
        //if (!PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) {
        // Puppet??
        PuppetInstance puppetInstance = new PuppetInstance();
        puppetInstance.setInstanceNo(instance.getInstanceNo());
        puppetInstanceDao.create(puppetInstance);
        //}
    }

    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isTrue(useZabbix)) {
        // Zabbix??
        ZabbixInstance zabbixInstance = new ZabbixInstance();
        zabbixInstance.setInstanceNo(instance.getInstanceNo());
        zabbixInstanceDao.create(zabbixInstance);
    }

    return instance.getInstanceNo();
}

From source file:adalid.core.programmers.AbstractSqlProgrammer.java

private boolean isCase(String string) {
    if (StringUtils.isBlank(string)) {
        return false;
    }/* ww w  .  jav a  2s .  com*/
    String case$ = getCase() + SPC$;
    String end$ = SPC$ + getEnd();
    String s = StringUtils.trimToEmpty(string);
    return StringUtils.startsWithIgnoreCase(s, case$) && StringUtils.endsWithIgnoreCase(s, end$);
}

From source file:adalid.core.programmers.AbstractSqlProgrammer.java

private String removeStart(String string, String[] searchStrings) {
    String s = StringUtils.trimToEmpty(string);
    String p;/*from   www.  ja  v  a2  s . c  o  m*/
    for (String searchString : searchStrings) {
        if (StringUtils.isNotBlank(searchString)) {
            p = StringUtils.trimToEmpty(searchString);
            if (StringUtils.startsWithIgnoreCase(s, p)) {
                return StringUtils.trimToEmpty(StringUtils.removeStartIgnoreCase(s, p));
            }
        }
    }
    return s;
}

From source file:net.sourceforge.sqlexplorer.service.SqlexplorerService.java

/**
 * DOC xqliu Comment method "isNetezza".
 * //from w w w.  jav  a  2s . co m
 * @param url
 * @return
 */
private boolean isNetezza(String url) {
    return StringUtils.startsWithIgnoreCase(url, "jdbc:netezza");
}

From source file:net.sourceforge.sqlexplorer.service.SqlexplorerService.java

private boolean isExasol(String url) {
    return StringUtils.startsWithIgnoreCase(url, "jdbc:exa");
}

From source file:net.sourceforge.sqlexplorer.service.SqlexplorerService.java

private boolean isHive(String url) {
    return StringUtils.startsWithIgnoreCase(url, "jdbc:hive");
}