当前位置: 首页>>代码示例>>Java>>正文


Java StringUtil类代码示例

本文整理汇总了Java中wherehows.common.utils.StringUtil的典型用法代码示例。如果您正苦于以下问题:Java StringUtil类的具体用法?Java StringUtil怎么用?Java StringUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringUtil类属于wherehows.common.utils包,在下文中一共展示了StringUtil类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toUpdateDatabaseValue

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public String toUpdateDatabaseValue() {
  List<Object> allFields = fillAllFields();
  List<String> allFieldNames = fillAllFieldNames();
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < allFields.size(); i++) {
    Object o = allFields.get(i);
    if (o != null)   {
      String fieldName = allFieldNames.get(i);
      sb.append("`"+fieldName+"`");
      sb.append("=");
      sb.append(StringUtil.toDbString(o));
      sb.append(",");
    }
  }
  sb.deleteCharAt(sb.length() - 1);
  return sb.toString();

}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:19,代码来源:DatasetRecord.java

示例2: process

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * Process a Gobblin tracking event audit record
 * @param record
 * @param topic
 * @return null
 * @throws Exception
 */
public Record process(GenericData.Record record, String topic)
    throws Exception {

  if (record != null && record.get("name") != null) {
    final String name = record.get("name").toString();
    // only handle "DaliLimitedRetentionAuditor","DaliAutoPurgeAuditor" and "DsIgnoreIDPCAuditor"
    if (name.equals(DALI_LIMITED_RETENTION_AUDITOR)
        || name.equals(DALI_AUTOPURGED_AUDITOR)
        || name.equals(DS_IGNORE_IDPC_AUDITOR)) {
      Long timestamp = (Long) record.get("timestamp");
      Map<String, String> metadata = StringUtil.convertObjectMapToStringMap(record.get("metadata"));

      String hasError = metadata.get("HasError");
      if (!hasError.equalsIgnoreCase("true")) {
        String datasetPath = metadata.get("DatasetPath");
        String datasetUrn = DATASET_URN_PREFIX + (datasetPath.startsWith("/") ? "" : "/") + datasetPath;
        String ownerUrns = metadata.get("OwnerURNs");
        DatasetInfoDao.updateKafkaDatasetOwner(datasetUrn, ownerUrns, DATASET_OWNER_SOURCE, timestamp);
      }
    }
  }
  return null;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:31,代码来源:GobblinTrackingAuditProcessor.java

示例3: toUpdateDatabaseValue

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public String toUpdateDatabaseValue() {
  List<Object> allFields = fillAllFields();
  List<String> allFieldNames = fillAllFieldNames();
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < allFields.size(); i++) {
    Object o = allFields.get(i);
    if (o != null) {
      String fieldName = allFieldNames.get(i);
      sb.append("`" + fieldName + "`");
      sb.append("=");
      sb.append(StringUtil.toDbString(o));
      sb.append(",");
    }
  }
  sb.deleteCharAt(sb.length() - 1);
  return sb.toString();
}
 
开发者ID:linkedin,项目名称:WhereHows,代码行数:18,代码来源:DatasetRecord.java

示例4: toDatabaseValue

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public String toDatabaseValue() {
    allFields = new ArrayList<>();

    allFields.add(parent_urn);
    allFields.add(child_urn);

    StringBuilder sb = new StringBuilder();
    for (Object o : allFields) {
        sb.append(StringUtil.toDbString(o));
        sb.append(",");
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:15,代码来源:LineageRecordLite.java

示例5: toDatabaseValue

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public String toDatabaseValue() {
  allFields = new ArrayList<>();
  allFields.add(appId);
  allFields.add(flowExecId);
  allFields.add(jobExecId);
  allFields.add(jobExecUUID);
  allFields.add(jobName);
  allFields.add(jobStartTime);
  allFields.add(jobEndTime);
  allFields.add(databaseId);
  allFields.add(abstractObjectName);
  allFields.add(fullObjectName);
  allFields.add(partitionStart);
  allFields.add(partitionEnd);
  allFields.add(partitionType);
  allFields.add(layoutId);
  allFields.add(storageType);
  allFields.add(sourceTargetType);
  allFields.add(srlNo);
  allFields.add(relatedSrlNo);
  allFields.add(operation);
  allFields.add(recordCount);
  allFields.add(insertCount);
  allFields.add(deleteCount);
  allFields.add(updateCount);
  allFields.add(flowPath);

  // add the created_date and wh_etl_exec_id
  allFields.add(System.currentTimeMillis() / 1000);
  allFields.add(null);
  StringBuilder sb = new StringBuilder();
  for (Object o : allFields) {
    sb.append(StringUtil.toDbString(o));
    sb.append(",");
  }
  sb.deleteCharAt(sb.length() - 1);
  return sb.toString();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:39,代码来源:LineageRecord.java

示例6: toDatabaseValue

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
@Override
public String toDatabaseValue() {
  List<Object> allFields = fillAllFields();
  StringBuilder sb = new StringBuilder();
  for (Object o : allFields) {
    sb.append(StringUtil.toDbString(o));
    sb.append(",");
  }
  sb.deleteCharAt(sb.length() - 1);
  return sb.toString();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:12,代码来源:AbstractRecord.java

示例7: getAllValuesToString

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * return values of declared fields, and transform record, collection, map and array into string
 * Primitive data types and other structures are unchanged.
 * @return Object[]
 * @throws IllegalAccessException
 */
@JsonIgnore
public Object[] getAllValuesToString()
    throws IllegalAccessException {
  final Object[] values = getAllValues();
  for (int i = 0; i < values.length; i++) {
    values[i] = StringUtil.objectToJsonString(values[i]);
  }
  return values;
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:16,代码来源:AbstractRecord.java

示例8: convertToRecord

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * Convert database query result into AbstractRecord
 * use column name to field mapping to assign each field
 * @param map <String, Object>
 */
@JsonIgnore
public void convertToRecord(Map<String, Object> map) {
  final Field[] fields = getAllFields();
  final String[] columns = getDbColumnNames();
  if (fields.length != columns.length) {
    return;
  }

  final ObjectMapper om = new ObjectMapper();

  for (int i = 0; i < columns.length; i++) {
    final Class<?> type = fields[i].getType();
    final Object value = map.get(columns[i]);
    try {
      if (value == null) {
      } else if (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)
          || Object[].class.isAssignableFrom(type) || Record.class.isAssignableFrom(type)) {
        fields[i].set(this, om.readValue((String) value, om.constructType(type)));
      } else if (Integer.class.isAssignableFrom(type)) {
        // may need to convert from Long (database unsigned int) to Integer
        fields[i].set(this, StringUtil.toInt(value));
      } else if (value instanceof Date) {
        fields[i].set(this, value.toString());
      } else {
        fields[i].set(this, value);
      }
    } catch (IllegalAccessException | IOException ex) {
    }
  }
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:36,代码来源:AbstractRecord.java

示例9: updateDatasetOwner

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public static void updateDatasetOwner(JsonNode root)
    throws Exception {
  final JsonNode owners = root.path("owners");
  if (owners.isMissingNode() || !owners.isArray()) {
    throw new IllegalArgumentException(
        "Dataset owner info update fail, missing necessary fields: " + root.toString());
  }

  final JsonNode ownerSourceNode = root.path("source");
  String ownerSource = null;
  if (!ownerSourceNode.isNull() && !ownerSourceNode.isMissingNode()) {
      ownerSource = ownerSourceNode.asText();
  }

  final Integer datasetId;
  final String urn;
  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    datasetId = 0;
    urn = root.path("datasetProperties").path("uri").asText();
  } else {
    datasetId = (Integer) idUrn[0];
    urn = (String) idUrn[1];
  }

  final JsonNode auditHeader = root.path("auditHeader");
  final Long eventTime = auditHeader != null ? auditHeader.path("time").asLong() / 1000 : null;

  ObjectMapper om = new ObjectMapper();

  List<DatasetOwnerRecord> ownerList = new ArrayList<>();
  for (final JsonNode owner : owners) {
    DatasetOwnerRecord record = om.convertValue(owner, DatasetOwnerRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setSourceTime(eventTime);
    record.setCreatedTime(eventTime);
    record.setModifiedTime(System.currentTimeMillis() / 1000);

    final String ownerString = record.getOwner();
    int lastIndex = ownerString.lastIndexOf(':');
    if (lastIndex >= 0) {
      record.setOwner(ownerString.substring(lastIndex + 1));
      record.setNamespace(ownerString.substring(0, lastIndex));
    } else {
      record.setNamespace("");
    }
    Map<String, Object> ownerInfo = getOwnerByOwnerId(record.getOwner());
    Integer appId = 0;
    String isActive = "N";
    if (ownerInfo.containsKey("app_id")) {
      appId = StringUtil.toInt(ownerInfo.get("app_id"));
      isActive = appId == 301 ? "Y" : appId == 300 ? (String) ownerInfo.get("is_active") : "N";
    }
    record.setAppId(appId);
    record.setIsActive(isActive);
    String ownerTypeString = record.getOwnerType();
    record.setIsGroup(ownerTypeString != null && ownerTypeString.equalsIgnoreCase("group") ? "Y" : "N");

    if (datasetId == 0 || appId == 0) {
      String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn(DATASET_OWNER_UNMATCHED_TABLE,
          record.getDbColumnForUnmatchedOwner());
      OWNER_UNMATCHED_WRITER.execute(sql, record.getValuesForUnmatchedOwner());
    } else {
      ownerList.add(record);
    }
  }

  mergeDatasetOwners(ownerList, datasetId, urn, ownerSource);
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:71,代码来源:DatasetInfoDao.java

示例10: process

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * Process a Gobblin tracking event compaction record
 * @param record
 * @param topic
 * @return Record
 * @throws Exception
 */
@Override
public Record process(GenericData.Record record, String topic)
    throws Exception {
  GobblinTrackingCompactionRecord eventRecord = null;

  // only handle namespace "compaction.tracking.events"
  if (record != null && record.get("namespace") != null && record.get("name") != null
      && "compaction.tracking.events".equals(record.get("namespace").toString())) {
    final String name = record.get("name").toString();

    // for event name "CompactionCompleted" or "CompactionRecordCounts"
    if (name.equals("CompactionCompleted") || name.equals("CompactionRecordCounts")) {
      // logger.info("Processing Gobblin tracking event record: " + name);
      final long timestamp = (long) record.get("timestamp");
      final Map<String, String> metadata = StringUtil.convertObjectMapToStringMap(record.get("metadata"));

      final String jobContext = "Gobblin:" + name;
      final String cluster = ClusterUtil.matchClusterCode(metadata.get("clusterIdentifier"));
      // final String cluster = parseClusterIdentifier(metadata.get("clusterIdentifier")).get("cluster");
      final String projectName = metadata.get("azkabanProjectName");
      final String flowId = metadata.get("azkabanFlowId");
      final String jobId = metadata.get("azkabanJobId");
      final int execId = Integer.parseInt(metadata.get("azkabanExecId"));

      // final String metricContextId = metadata.get("metricContextID");
      // final String metricContextName = metadata.get("metricContextName");
      final String dedupeStatus = metadata.get("dedupeStatus");

      String dataset = null;
      String partitionType = null;
      String partitionName = null;
      long recordCount = 0;
      long lateRecordCount = 0;

      if (name.equals("CompactionCompleted")) {
        dataset = metadata.get("datasetUrn");
        partitionName = metadata.get("partition");
        recordCount = StringUtil.parseLong(metadata.get("recordCount"));
      }
      // name = "CompactionRecordCounts"
      else {
        final Matcher m = UrnPattern.matcher(metadata.get("DatasetOutputPath"));
        if (m.find()) {
          dataset = m.group(1);
          partitionType = m.group(2);
          partitionName = m.group(3);
        }

        recordCount = StringUtil.parseLong(metadata.get("RegularRecordCount"));
        lateRecordCount = StringUtil.parseLong(metadata.get("LateRecordCount"));
      }

      eventRecord =
          new GobblinTrackingCompactionRecord(timestamp, jobContext, cluster, projectName, flowId, jobId, execId);
      eventRecord.setDatasetUrn(dataset, partitionType, partitionName);
      eventRecord.setRecordCount(recordCount);
      eventRecord.setLateRecordCount(lateRecordCount);
      eventRecord.setDedupeStatus(dedupeStatus);
    }
  }
  return eventRecord;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:70,代码来源:GobblinTrackingCompactionProcessor.java

示例11: process

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * Process a Metastore Table/Partition Audit event record
 * @param record
 * @param topic
 * @return Record
 * @throws Exception
 */
@Override
public Record process(GenericData.Record record, String topic) throws Exception {
  MetastoreAuditRecord eventRecord = null;

  // handle MetastoreTableAuditEvent and MetastorePartitionAuditEvent
  if (record != null) {
    // logger.info("Processing Metastore Audit event record.");

    final GenericData.Record auditHeader = (GenericData.Record) record.get("auditHeader");
    final String server = ClusterUtil.matchClusterCode(String.valueOf(auditHeader.get("server")));
    final String instance = String.valueOf(auditHeader.get("instance"));
    final String appName = String.valueOf(auditHeader.get("appName"));

    String eventName;
    GenericData.Record content;
    final Object oldInfo;
    final Object newInfo;

    // check if it is MetastoreTableAuditEvent
    if (record.get("metastoreTableAuditContent") != null) {
      eventName = "MetastoreTableAuditEvent";
      content = (GenericData.Record) record.get("metastoreTableAuditContent");
      oldInfo = content.get("oldTable");
      newInfo = content.get("newTable");
    }
    // check if it is MetastorePartitionAuditEvent
    else if (record.get("metastorePartitionAuditContent") != null) {
      eventName = "MetastorePartitionAuditEvent";
      content = (GenericData.Record) record.get("metastorePartitionAuditContent");
      oldInfo = content.get("oldPartition");
      newInfo = content.get("newPartition");
    }
    else {
      throw new IllegalArgumentException("Unknown Metastore Audit event: " + record);
    }

    final String eventType = String.valueOf(content.get("eventType"));
    final String metastoreThriftUri = String.valueOf(content.get("metastoreThriftUri"));
    final String metastoreVersion = StringUtil.toStringReplaceNull(content.get("metastoreVersion"), null);
    final long timestamp = (long) content.get("timestamp");
    final String isSuccessful = String.valueOf(content.get("isSuccessful"));
    final String isDataDeleted = String.valueOf(content.get("isDataDeleted"));

    // use newOne, if null, use oldOne
    final GenericData.Record rec = newInfo != null ? (GenericData.Record) newInfo : (GenericData.Record) oldInfo;
    final String dbName = String.valueOf(rec.get("dbName"));
    final String tableName = String.valueOf(rec.get("tableName"));
    // set null / "null" partition to '?' for primary key
    final String partition = StringUtil.toStringReplaceNull(rec.get("values"), "?");
    final String location = StringUtil.toStringReplaceNull(rec.get("location"), null);
    final String owner = StringUtil.toStringReplaceNull(rec.get("owner"), null);
    final long createTime = (long) rec.get("createTime");
    final long lastAccessTime = (long) rec.get("lastAccessTime");

    eventRecord = new MetastoreAuditRecord(server, instance, appName, eventName, eventType, timestamp);
    eventRecord.setEventInfo(metastoreThriftUri, metastoreVersion, isSuccessful, isDataDeleted);
    eventRecord.setTableInfo(dbName, tableName, partition, location, owner, createTime, lastAccessTime);
    // eventRecord.setOldInfo(StringUtil.toStringReplaceNull(oldInfo, null));
    // eventRecord.setNewInfo(StringUtil.toStringReplaceNull(newInfo, null));
  }
  return eventRecord;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:70,代码来源:MetastoreAuditProcessor.java

示例12: process

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
/**
 * Process a Gobblin tracking event distcp_ng event record
 * @param record GenericData.Record
 * @param topic
 * @return Record
 * @throws Exception
 */
@Override
public Record process(GenericData.Record record, String topic)
    throws Exception {
  GobblinTrackingDistcpNgRecord eventRecord = null;

  // handle namespace "gobblin.copy.CopyDataPublisher"
  if (record != null && record.get("namespace") != null && record.get("name") != null
      && "gobblin.copy.CopyDataPublisher".equals(record.get("namespace").toString())) {
    final String name = record.get("name").toString();

    if (name.equals("DatasetPublished")) { // || name.equals("FilePublished")) {
      // logger.info("Processing Gobblin tracking event record: " + name);
      final long timestamp = (long) record.get("timestamp");
      final Map<String, String> metadata = StringUtil.convertObjectMapToStringMap(record.get("metadata"));

      final String jobContext = "DistcpNG:" + name;
      final String cluster = ClusterUtil.matchClusterCode(metadata.get("clusterIdentifier"));
      final String projectName = metadata.get("azkabanProjectName");
      final String flowId = metadata.get("azkabanFlowId");
      final String jobId = metadata.get("azkabanJobId");
      final int execId = StringUtil.parseInteger(metadata.get("azkabanExecId"));
      // final String metricContextId = metadata.get("metricContextID");
      // final String metricContextName = metadata.get("metricContextName");

      final long upstreamTimestamp = StringUtil.parseLong(metadata.get("upstreamTimestamp"));
      final long originTimestamp = StringUtil.parseLong(metadata.get("originTimestamp"));
      final String sourcePath = metadata.get("SourcePath");
      final String targetPath = metadata.get("TargetPath");

      final String dataset = metadata.get("datasetUrn");
      String partitionType = null;
      String partitionName = null;

      if (name.equals("DatasetPublished")) {
        partitionName = metadata.get("partition");
      }
      // name "FilePublished"
      else {
        final Matcher m = PathPattern.matcher(targetPath);
        if (m.find()) {
          partitionType = m.group(3);
          partitionName = m.group(4);
        }
      }

      eventRecord =
          new GobblinTrackingDistcpNgRecord(timestamp, jobContext, cluster, projectName, flowId, jobId, execId);
      eventRecord.setDatasetUrn(dataset, partitionType, partitionName);
      eventRecord.setEventInfo(upstreamTimestamp, originTimestamp, sourcePath, targetPath);
    }
  }
  return eventRecord;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:61,代码来源:GobblinTrackingDistcpNgProcessor.java

示例13: updateDatasetOwner

import wherehows.common.utils.StringUtil; //导入依赖的package包/类
public static void updateDatasetOwner(JsonNode root)
    throws Exception {
  final JsonNode owners = root.path("owners");
  if (owners.isMissingNode() || !owners.isArray()) {
    throw new IllegalArgumentException(
        "Dataset owner info update fail, missing necessary fields: " + root.toString());
  }

  final JsonNode ownerSourceNode = root.path("source");
  String ownerSource = null;
  if (!ownerSourceNode.isNull() && !ownerSourceNode.isMissingNode()) {
      ownerSource = ownerSourceNode.asText();
  }

  final Integer datasetId;
  final String urn;
  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    datasetId = 0;
    urn = root.path("datasetProperties").path("uri").asText();
  } else {
    datasetId = (Integer) idUrn[0];
    urn = (String) idUrn[1];
  }

  final JsonNode auditHeader = root.path("auditHeader");
  final Long eventTime = auditHeader != null ? auditHeader.path("time").asLong() / 1000 : null;

  ObjectMapper om = new ObjectMapper();

  List<DatasetOwnerRecord> ownerList = new ArrayList<>();
  for (final JsonNode owner : owners) {
    DatasetOwnerRecord record = om.convertValue(owner, DatasetOwnerRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setSourceTime(eventTime);
    record.setCreatedTime(eventTime);
    record.setModifiedTime(System.currentTimeMillis() / 1000);

    final String ownerString = record.getOwner();
    int lastIndex = ownerString.lastIndexOf(':');
    if (lastIndex >= 0) {
      record.setOwner(ownerString.substring(lastIndex + 1));
      record.setNamespace(ownerString.substring(0, lastIndex));
    } else {
      record.setNamespace("");
    }
    Map<String, Object> ownerInfo = getOwnerByOwnerId(record.getOwner());
    Integer appId = 0;
    String isActive = "N";
    if (ownerInfo.containsKey("app_id")) {
      appId = StringUtil.toInt(ownerInfo.get("app_id"));
      isActive = appId == 301 ? "Y" : appId == 300 ? (String) ownerInfo.get("is_active") : "N";
    }
    record.setAppId(appId);
    record.setIsActive(isActive);
    String ownerTypeString = record.getOwnerType();
    record.setIsGroup(ownerTypeString != null && ownerTypeString.equalsIgnoreCase("group") ? "Y" : "N");

    if (datasetId == 0 || appId == 0) {
      String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn("REPLACE", DATASET_OWNER_UNMATCHED_TABLE,
          record.getDbColumnForUnmatchedOwner());
      OWNER_UNMATCHED_WRITER.execute(sql, record.getValuesForUnmatchedOwner());
    } else {
      ownerList.add(record);
    }
  }

  mergeDatasetOwners(ownerList, datasetId, urn, ownerSource);
}
 
开发者ID:linkedin,项目名称:WhereHows,代码行数:71,代码来源:DatasetInfoDao.java


注:本文中的wherehows.common.utils.StringUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。