public static Date parseDate(String str, String[] parsePatterns) { return parseDate(str, parsePatterns, null); }
@Override protected void print(Batch batch, String data) { try { if (log.isDebugEnabled() && data != null) { log.debug("Writing data: {}", FormatUtils.abbreviateForLogging(data)); } writer.write(data); } catch (IOException e) { throw new IoException(e); } }
public static boolean isWildCardMatch(String text, String pattern, boolean ignoreCase) { boolean match = isWildCardMatch(text, pattern); if (ignoreCase && !match) { match = isWildCardMatch(text.toLowerCase(), pattern); if (!match) { match = isWildCardMatch(text.toUpperCase(), pattern); } } return match; }
protected String replaceDefaultSchema(String ddl, String defaultSchema) { if (StringUtils.isNotBlank(defaultSchema)) { ddl = FormatUtils.replace("defaultSchema", SymmetricUtils.quote(symmetricDialect, defaultSchema) + ".", ddl); } else { ddl = FormatUtils.replace("defaultSchema", "", ddl); } return ddl; }
public static String replaceToken(String text, String tokenToReplace, String replaceWithText, boolean matchUsingPrefixSuffix) { Map<String, String> replacements = new HashMap<String, String>(1); replacements.put(tokenToReplace, replaceWithText); return replaceTokens(text, replacements, matchUsingPrefixSuffix); }
public List<TriggerHistory> findTriggerHistories(String catalogName, String schemaName, String tableName) { List<TriggerHistory> listToReturn = new ArrayList<TriggerHistory>(); List<TriggerHistory> triggerHistories = getActiveTriggerHistories(); if (triggerHistories != null && triggerHistories.size() > 0) { for (TriggerHistory triggerHistory : triggerHistories) { boolean matches = true; if (StringUtils.isNotBlank(catalogName)) { matches = catalogName.equals(triggerHistory.getSourceCatalogName()); } if (matches && StringUtils.isNotBlank(schemaName)) { matches = schemaName.equals(triggerHistory.getSourceSchemaName()); } if (matches && StringUtils.isNotBlank(tableName)) { boolean ignoreCase = parameterService.is(ParameterConstants.DB_METADATA_IGNORE_CASE) && !FormatUtils.isMixedCase(tableName); matches = ignoreCase ? triggerHistory.getSourceTableName().equalsIgnoreCase(tableName) : triggerHistory.getSourceTableName().equals(tableName); } if (matches) { listToReturn.add(triggerHistory); } } } return listToReturn; }
/** * Word wrap a string where the line size for the first line is different * than the lines sizes for the other lines. * * @param str * @param firstLineSize * @param nonFirstLineSize * @return */ public static String[] wordWrap(String str, int firstLineSize, int nonFirstLineSize) { String[] lines = wordWrap(str, firstLineSize); if (lines.length > 1 && firstLineSize != nonFirstLineSize) { // More than one line. Re-wrap the non-first lines with the non // first line size String notFirstLinesString = StringUtils.join(lines, " ", 1, lines.length); String[] nonFirstLines = wordWrap(notFirstLinesString, nonFirstLineSize); List<String> nonFirstLineCollection = Arrays.asList(nonFirstLines); ArrayList<String> allLines = new ArrayList<String>(); allLines.add(lines[0]); allLines.addAll(nonFirstLineCollection); lines = allLines.toArray(lines); } return lines; }
matcher.appendReplacement(buffer, ""); if (match.length == 2) { replacement = formatString(match[1], replacement);
public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) { String sql = FormatUtils.replaceToken(SQL, "prefixName", symmetricDialect.getTablePrefix(), true); String subSelect = dataMetaData.getRouter().getRouterExpression(); Set<String> nodeIds = null; if (!StringUtils.isBlank(subSelect) && !initialLoadSelectUsed) { try { Map<String, Object> sqlParams = getDataObjectMap(dataMetaData, symmetricDialect, true); sqlParams.put("NODE_GROUP_ID", dataMetaData.getRouter().getNodeGroupLink() .getTargetNodeGroupId()); sqlParams.put("EXTERNAL_DATA", dataMetaData.getData().getExternalData()); ISqlTemplate template = symmetricDialect.getPlatform().getSqlTemplate(); List<String> ids = template.query(String.format("%s%s", sql, subSelect), new StringMapper(), sqlParams); if (ids != null) { nodeIds = new HashSet<String>(ids); } } catch (InvalidSqlException ex) { log.error("The subselect expression was invalid for the {} subselect router", dataMetaData.getRouter().getRouterId()); throw ex; } } else if (initialLoadSelectUsed) { nodeIds = toNodeIds(nodes, null); } else { throw new InvalidSqlException("The subselect expression is missing for the %s router", dataMetaData.getRouter().getRouterId()); } return nodeIds; }
protected String replaceDefaultCatalog(String ddl, String defaultCatalog) { if (StringUtils.isNotBlank(defaultCatalog)) { ddl = FormatUtils.replace("defaultCatalog", SymmetricUtils.quote(symmetricDialect, defaultCatalog) + ".", ddl); } else { ddl = FormatUtils.replace("defaultCatalog", "", ddl); } return ddl; }
protected void putSql(String key, String sql) { if (replacementTokens != null) { sql = FormatUtils.replaceTokens(sql, this.replacementTokens, true); } sql = sql.replaceAll("\\s+", " "); this.sql.put(key, this.platform != null ? this.platform.scrubSql(sql) : sql); }
protected Table toAuditTable(Table table) { Table auditTable = table.copy(); String tableName = table.getName(); if (!FormatUtils.isMixedCase(tableName)) { tableName = tableName.toUpperCase(); } auditTable.setName(String.format("%s_AUDIT", tableName)); Column[] columns = auditTable.getColumns(); auditTable.removeAllColumns(); auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0)); auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0)); for (Column column : columns) { column.setRequired(false); column.setPrimaryKey(false); column.setAutoIncrement(false); auditTable.addColumn(column); } auditTable.removeAllForeignKeys(); auditTable.removeAllIndices(); engine.getDatabasePlatform().alterCaseToMatchDatabaseDefaultCase(auditTable); return auditTable; }
@Override @SuppressWarnings("unchecked") public <T> T getObjectFromResultSet(ResultSet rs, Class<T> clazz) throws SQLException { if (Date.class.isAssignableFrom(clazz) || Timestamp.class.isAssignableFrom(clazz)) { String s = rs.getString(1); Date d = null; d = FormatUtils.parseDate(s,FormatUtils.TIMESTAMP_PATTERNS); if (Timestamp.class.isAssignableFrom(clazz)) { return (T) new Timestamp(d.getTime()); } else { return (T) d; } } else { return super.getObjectFromResultSet(rs, clazz); } }
protected long logDebugAndCountBytes(String[] tokens) { long bytesRead = 0; if (tokens != null) { StringBuilder debugBuffer = log.isDebugEnabled() ? new StringBuilder() : null; for (String token : tokens) { bytesRead += token != null ? token.length() : 0; if (debugBuffer != null) { if (token != null) { String tokenTrimmed = FormatUtils.abbreviateForLogging(token); debugBuffer.append(tokenTrimmed); } else { debugBuffer.append("<null>"); } debugBuffer.append(","); } } if (debugBuffer != null && debugBuffer.length() > 1) { log.debug("CSV parsed: {}", debugBuffer.substring(0, debugBuffer.length() - 1)); } } return bytesRead; }
public long getDatabaseTime() { try { String sql = "select current_timestamp from " + this.parameterService.getTablePrefix() + "_node_identity"; sql = FormatUtils.replaceTokens(sql, platform.getSqlScriptReplacementTokens(), false); Date dateTime = this.platform.getSqlTemplate() .queryForObject(sql, java.util.Date.class); if (dateTime != null) { return dateTime.getTime(); } else { return System.currentTimeMillis(); } } catch (Exception ex) { log.error(ex.getMessage(), ex); return System.currentTimeMillis(); } }
public boolean matches(Table table, String defaultCatalog, String defaultSchema, boolean ignoreCase) { boolean schemaAndCatalogMatch = (StringUtils.equals(sourceCatalogName, table.getCatalog()) || (StringUtils .isBlank(sourceCatalogName) && StringUtils.equals(defaultCatalog, table.getCatalog()))) && (StringUtils.equals(sourceSchemaName, table.getSchema()) || (StringUtils .isBlank(sourceSchemaName) && StringUtils.equals(defaultSchema, table.getSchema()))); boolean tableMatches = ignoreCase ? table.getName().equalsIgnoreCase(sourceTableName) : table.getName().equals(sourceTableName); if (!tableMatches && isSourceTableNameWildCarded()) { String[] wildcardTokens = sourceTableName.split(","); for (String wildcardToken : wildcardTokens) { if (FormatUtils.isWildCardMatch(table.getName(), wildcardToken, ignoreCase)) { if (!wildcardToken.startsWith(FormatUtils.NEGATE_TOKEN)) { tableMatches = true; } else { tableMatches = false; } } } } return schemaAndCatalogMatch && tableMatches; }
protected String qualifyUsingDataGaps(List<DataGap> dataGaps, int numberOfGapsToQualify, String sql) { StringBuilder gapClause = new StringBuilder(); for (int i = 0; i < numberOfGapsToQualify && i < dataGaps.size(); i++) { if (i == 0) { gapClause.append(" and ("); } else { gapClause.append(" or "); } gapClause.append("(d.data_id between ? and ?)"); } gapClause.append(")"); return FormatUtils.replace("dataRange", gapClause.toString(), sql); }
existingTs = FormatUtils.parseDate(existingStr.substring(0, split).trim(), FormatUtils.TIMESTAMP_PATTERNS, TimeZone.getTimeZone(existingStr.substring(split).trim())); loadingTs = FormatUtils.parseDate(loadingStr.substring(0, split).trim(), FormatUtils.TIMESTAMP_PATTERNS, TimeZone.getTimeZone(loadingStr.substring(split).trim()));
@Override protected void print(Batch batch, String data) { if (log.isDebugEnabled() && data != null) { log.debug("Writing staging data: {}", FormatUtils.abbreviateForLogging(data)); } IStagedResource resource = getStagedResource(batch); BufferedWriter writer = resource.getWriter(); try { int size = data.length(); for (int i = 0; i < size; i = i + 1024) { int end = i + 1024; writer.append(data, i, end < size ? end : size); } } catch (IOException ex) { throw new IoException(ex); } }