List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.irccloud.android.CollapsedEventsList.java
public String getCollapsedMessage() { StringBuilder message = new StringBuilder(); if (data.size() == 0) return null; if (data.size() == 1 && data.get(0).modeCount() < ((data.get(0).type == TYPE_MODE) ? 2 : 1)) { CollapsedEvent e = data.get(0);//from www . ja v a2 s . co m switch (e.type) { case TYPE_NETSPLIT: message.append(e.msg.replace(" ", " ")); break; case TYPE_MODE: message.append("<b>").append(formatNick(e.nick, e.target_mode, false)).append("</b> was ") .append(e.getModes(true)); if (e.from_nick != null) { if (e.from_mode != null && e.from_mode.equalsIgnoreCase("__the_server__")) message.append(" by the server <b>").append(e.from_nick).append("</b>"); else message.append(" by ").append(formatNick(e.from_nick, e.from_mode, false)); } break; case TYPE_JOIN: message.append(" <b>").append(formatNick(e.nick, e.from_mode, false)).append("</b>") .append(was(e)); message.append(" joined"); if (showChan) message.append(" ").append(e.chan); message.append(" (").append(e.hostmask).append(")"); break; case TYPE_PART: message.append("? <b>").append(formatNick(e.nick, e.from_mode, false)).append("</b>") .append(was(e)); message.append(" left"); if (showChan) message.append(" ").append(e.chan); message.append(" (").append(e.hostmask).append(")"); if (e.msg != null && e.msg.length() > 0) message.append(": ").append(e.msg); break; case TYPE_QUIT: message.append("? <b>").append(formatNick(e.nick, e.from_mode, false)).append("</b>") .append(was(e)); if (e.hostmask != null) message.append(" quit (").append(e.hostmask).append(") "); else message.append(" quit: "); if (e.msg != null && e.msg.length() > 0) message.append(e.msg); break; case TYPE_NICKCHANGE: message.append(e.old_nick).append(" <b>").append(formatNick(e.nick, e.from_mode, false)) .append("</b>"); break; case TYPE_POPIN: message.append(" <b>").append(formatNick(e.nick, e.from_mode, false)).append("</b>") .append(was(e)); message.append(" popped in"); if (showChan) message.append(" ").append(e.chan); break; case TYPE_POPOUT: message.append(" <b>").append(formatNick(e.nick, e.from_mode, false)).append("</b>") .append(was(e)); message.append(" nipped out"); if (showChan) message.append(" ").append(e.chan); break; case TYPE_CONNECTIONSTATUS: message.append(e.msg); if (e.count > 1) message.append(" (").append(e.count).append("x)"); break; } } else { boolean netsplit = false; Collections.sort(data, new comparator()); Iterator<CollapsedEvent> i = data.iterator(); CollapsedEvent last = null; CollapsedEvent next = i.next(); CollapsedEvent e; int groupcount = 0; while (next != null) { e = next; do { if (i.hasNext()) next = i.next(); else next = null; } while (next != null && netsplit && next.netsplit); if (message.length() > 0 && e.type < TYPE_NICKCHANGE && ((next == null || next.type != e.type) && last != null && last.type == e.type)) { if (groupcount == 1) message.delete(message.length() - 2, message.length()).append(" "); message.append("and "); } if (last == null || last.type != e.type) { switch (e.type) { case TYPE_NETSPLIT: netsplit = true; break; case TYPE_MODE: if (message.length() > 0) message.append(" "); message.append("\u00031mode:\u000f "); break; case TYPE_JOIN: message.append(" "); break; case TYPE_PART: message.append("? "); break; case TYPE_QUIT: message.append("? "); break; case TYPE_NICKCHANGE: if (message.length() > 0) message.append(" "); break; case TYPE_POPIN: case TYPE_POPOUT: message.append(" "); break; case TYPE_CONNECTIONSTATUS: break; } } if (e.type == TYPE_NICKCHANGE) { message.append(e.old_nick).append(" <b>").append(formatNick(e.nick, e.from_mode, false)) .append("</b>"); String old_nick = e.old_nick; e.old_nick = null; message.append(was(e)); e.old_nick = old_nick; } else if (e.type == TYPE_NETSPLIT) { message.append(e.msg.replace(" ", " ")); } else if (e.type == TYPE_CONNECTIONSTATUS) { message.append(e.msg); if (e.count > 1) message.append(" (").append(e.count).append("x)"); } else if (!showChan) { message.append("<b>") .append(formatNick(e.nick, (e.type == TYPE_MODE) ? e.target_mode : e.from_mode, false)) .append("</b>").append(was(e)); } if ((next == null || next.type != e.type) && !showChan) { switch (e.type) { case TYPE_JOIN: message.append(" joined"); break; case TYPE_PART: message.append(" left"); break; case TYPE_QUIT: message.append(" quit"); break; case TYPE_POPIN: message.append(" popped in"); break; case TYPE_POPOUT: message.append(" nipped out"); break; } } else if (showChan && e.type != TYPE_NETSPLIT && e.type != TYPE_CONNECTIONSTATUS) { if (groupcount == 0) { message.append("<b>").append( formatNick(e.nick, (e.type == TYPE_MODE) ? e.target_mode : e.from_mode, false)) .append("</b>").append(was(e)); switch (e.type) { case TYPE_JOIN: message.append(" joined "); break; case TYPE_PART: message.append(" left "); break; case TYPE_QUIT: message.append(" quit "); break; case TYPE_POPIN: message.append(" popped in "); break; case TYPE_POPOUT: message.append(" nipped out "); break; } } if (e.type != TYPE_QUIT) message.append(e.chan); } if (next != null && next.type == e.type) { if (message.length() > 0) { message.append(", "); groupcount++; } } else if (next != null) { message.append(" "); groupcount = 0; } last = e; } } return message.toString(); }
From source file:org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.java
/** * Write tags according javaEntityTags./* w ww. j a va 2s .co m*/ * * @param sb not null * @param entity not null * @param isJavaMethod * @param javaEntityTags not null */ private void updateJavadocTags(final StringBuilder sb, final AbstractInheritableJavaEntity entity, final boolean isJavaMethod, final JavaEntityTags javaEntityTags) { for (int i = 0; i < entity.getTags().length; i++) { DocletTag docletTag = entity.getTags()[i]; if (isJavaMethod) { JavaMethod javaMethod = (JavaMethod) entity; String[] params = docletTag.getParameters(); if (params.length < 1) { continue; } if (docletTag.getName().equals(PARAM_TAG)) { writeParamTag(sb, javaMethod, javaEntityTags, params); } else if (docletTag.getName().equals(RETURN_TAG)) { writeReturnTag(sb, javaMethod, javaEntityTags); } else if (docletTag.getName().equals(THROWS_TAG)) { writeThrowsTag(sb, javaMethod, javaEntityTags, params); } else { // write unknown tags for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext();) { String originalJavadocTag = it.next(); if (StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim() .contains("@" + docletTag.getName())) { it.remove(); sb.append(originalJavadocTag); sb.append(EOL); } } } } else { for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext();) { String originalJavadocTag = it.next(); if (StringUtils.removeDuplicateWhitespace(originalJavadocTag).trim() .contains("@" + docletTag.getName())) { it.remove(); sb.append(originalJavadocTag); sb.append(EOL); } } } if (sb.toString().endsWith(EOL)) { sb.delete(sb.toString().lastIndexOf(EOL), sb.toString().length()); } sb.append(EOL); } }
From source file:com.cohort.util.String2.java
/** * This removes white space characters at the beginning and end of a StringBuilder. * * @param sb a StringBuilder/* w w w .ja v a 2 s . c om*/ * @return the same pointer to the StringBuilder for convenience */ public static StringBuilder trim(StringBuilder sb) { int po = 0; while (po < sb.length() && isWhite(sb.charAt(po))) po++; sb.delete(0, po); po = sb.length(); while (po > 0 && isWhite(sb.charAt(po - 1))) po--; sb.delete(po, sb.length()); return sb; }
From source file:org.apache.nifi.controller.repository.StandardProcessSession.java
private String summarizeEvents(final Checkpoint checkpoint) { final Map<Relationship, Set<String>> transferMap = new HashMap<>(); // relationship to flowfile ID's final Set<String> modifiedFlowFileIds = new HashSet<>(); int largestTransferSetSize = 0; for (final Map.Entry<FlowFileRecord, StandardRepositoryRecord> entry : checkpoint.records.entrySet()) { final FlowFile flowFile = entry.getKey(); final StandardRepositoryRecord record = entry.getValue(); final Relationship relationship = record.getTransferRelationship(); if (Relationship.SELF.equals(relationship)) { continue; }// www. ja v a2 s .com Set<String> transferIds = transferMap.get(relationship); if (transferIds == null) { transferIds = new HashSet<>(); transferMap.put(relationship, transferIds); } transferIds.add(flowFile.getAttribute(CoreAttributes.UUID.key())); largestTransferSetSize = Math.max(largestTransferSetSize, transferIds.size()); final ContentClaim workingClaim = record.getWorkingClaim(); if (workingClaim != null && workingClaim != record.getOriginalClaim() && record.getTransferRelationship() != null) { modifiedFlowFileIds.add(flowFile.getAttribute(CoreAttributes.UUID.key())); } } final int numRemoved = checkpoint.removedFlowFiles.size(); final int numModified = modifiedFlowFileIds.size(); final int numCreated = checkpoint.createdFlowFiles.size(); final StringBuilder sb = new StringBuilder(512); if (!LOG.isDebugEnabled() && (largestTransferSetSize > VERBOSE_LOG_THRESHOLD || numModified > VERBOSE_LOG_THRESHOLD || numCreated > VERBOSE_LOG_THRESHOLD || numRemoved > VERBOSE_LOG_THRESHOLD)) { if (numCreated > 0) { sb.append("created ").append(numCreated).append(" FlowFiles, "); } if (numModified > 0) { sb.append("modified ").append(modifiedFlowFileIds.size()).append(" FlowFiles, "); } if (numRemoved > 0) { sb.append("removed ").append(numRemoved).append(" FlowFiles, "); } for (final Map.Entry<Relationship, Set<String>> entry : transferMap.entrySet()) { if (entry.getKey() != null) { sb.append("Transferred ").append(entry.getValue().size()).append(" FlowFiles"); final Relationship relationship = entry.getKey(); if (relationship != Relationship.ANONYMOUS) { sb.append(" to '").append(relationship.getName()).append("', "); } } } } else { if (numCreated > 0) { sb.append("created FlowFiles ").append(checkpoint.createdFlowFiles).append(", "); } if (numModified > 0) { sb.append("modified FlowFiles ").append(modifiedFlowFileIds).append(", "); } if (numRemoved > 0) { sb.append("removed FlowFiles ").append(checkpoint.removedFlowFiles).append(", "); } for (final Map.Entry<Relationship, Set<String>> entry : transferMap.entrySet()) { if (entry.getKey() != null) { sb.append("Transferred FlowFiles ").append(entry.getValue()); final Relationship relationship = entry.getKey(); if (relationship != Relationship.ANONYMOUS) { sb.append(" to '").append(relationship.getName()).append("', "); } } } } if (sb.length() > 2 && sb.subSequence(sb.length() - 2, sb.length()).equals(", ")) { sb.delete(sb.length() - 2, sb.length()); } // don't add processing time if we did nothing, because we don't log the summary anyway if (sb.length() > 0) { final long processingNanos = checkpoint.processingTime; sb.append(", Processing Time = "); formatNanos(processingNanos, sb); } return sb.toString(); }
From source file:org.eclipse.swt.examples.layoutexample.GridLayoutTab.java
/** * Generates code for the example layout. *//* w w w .j a v a 2 s .c om*/ @Override StringBuilder generateLayoutCode() { StringBuilder code = new StringBuilder(); code.append("\t\tGridLayout gridLayout = new GridLayout ("); if (gridLayout.numColumns != 1 || gridLayout.makeColumnsEqualWidth) { code.append(gridLayout.numColumns + ", " + gridLayout.makeColumnsEqualWidth); } code.append(");\n"); if (gridLayout.marginWidth != 5) { code.append("\t\tgridLayout.marginWidth = " + gridLayout.marginWidth + ";\n"); } if (gridLayout.marginHeight != 5) { code.append("\t\tgridLayout.marginHeight = " + gridLayout.marginHeight + ";\n"); } if (gridLayout.marginLeft != 0) { code.append("\t\tgridLayout.marginLeft = " + gridLayout.marginLeft + ";\n"); } if (gridLayout.marginRight != 0) { code.append("\t\tgridLayout.marginRight = " + gridLayout.marginRight + ";\n"); } if (gridLayout.marginTop != 0) { code.append("\t\tgridLayout.marginTop = " + gridLayout.marginTop + ";\n"); } if (gridLayout.marginBottom != 0) { code.append("\t\tgridLayout.marginBottom = " + gridLayout.marginBottom + ";\n"); } if (gridLayout.horizontalSpacing != 5) { code.append("\t\tgridLayout.horizontalSpacing = " + gridLayout.horizontalSpacing + ";\n"); } if (gridLayout.verticalSpacing != 5) { code.append("\t\tgridLayout.verticalSpacing = " + gridLayout.verticalSpacing + ";\n"); } code.append("\t\tshell.setLayout (gridLayout);\n"); boolean first = true; boolean bounds, align, grab, span; for (int i = 0; i < children.length; i++) { Control control = children[i]; code.append(getChildCode(control, i)); GridData data = (GridData) control.getLayoutData(); if (data != null) { /* Use the most efficient constructor */ bounds = data.widthHint != SWT.DEFAULT || data.heightHint != SWT.DEFAULT; align = data.horizontalAlignment != SWT.BEGINNING || data.verticalAlignment != SWT.CENTER; grab = data.grabExcessHorizontalSpace || data.grabExcessVerticalSpace; span = data.horizontalSpan != 1 || data.verticalSpan != 1; code.append("\t\t"); if (first) { code.append("GridData "); first = false; } if (align || grab || span) { code.append("data = new GridData ("); code.append(alignmentString(data.horizontalAlignment) + ", "); code.append(alignmentString(data.verticalAlignment) + ", "); code.append(data.grabExcessHorizontalSpace + ", "); code.append(data.grabExcessVerticalSpace); if (span) { code.append(", " + data.horizontalSpan); code.append(", " + data.verticalSpan); } code.append(");\n"); if (data.widthHint != SWT.DEFAULT) { code.append("\t\tdata.widthHint = " + data.widthHint + ";\n"); } if (data.heightHint != SWT.DEFAULT) { code.append("\t\tdata.heightHint = " + data.heightHint + ";\n"); } } else { if (bounds) { code.append("data = new GridData ("); code.append(data.widthHint == SWT.DEFAULT ? "SWT.DEFAULT" : String.valueOf(data.widthHint) + ", "); code.append( data.heightHint == SWT.DEFAULT ? "SWT.DEFAULT" : String.valueOf(data.heightHint)); code.append(");\n"); } else { code.append("data = new GridData ();\n"); } } if (data.horizontalIndent != 0) { code.append("\t\tdata.horizontalIndent = " + data.horizontalIndent + ";\n"); } if (data.verticalIndent != 0) { code.append("\t\tdata.verticalIndent = " + data.verticalIndent + ";\n"); } if (data.minimumWidth != 0) { code.append("\t\tdata.minimumWidth = " + data.minimumWidth + ";\n"); } if (data.minimumHeight != 0) { code.append("\t\tdata.minimumHeight = " + data.minimumHeight + ";\n"); } if (data.exclude) { code.append("\t\tdata.exclude = true;\n"); } if (code.substring(code.length() - 33).equals("GridData data = new GridData ();\n")) { code.delete(code.length() - 33, code.length()); first = true; } else if (code.substring(code.length() - 24).equals("data = new GridData ();\n")) { code.delete(code.length() - 24, code.length()); } else { code.append("\t\t" + names[i] + ".setLayoutData (data);\n"); } } } return code; }
From source file:com.impetus.client.cassandra.query.CassQuery.java
/** * On condition.// w ww . ja v a 2 s. c o m * * @param m * the m * @param metaModel * the meta model * @param keyObj * the compound key * @param idColumn * the id column * @param builder * the builder * @param isPresent * the is present * @param translator * the translator * @param use * the use * @return true, if successful */ private boolean onCondition(EntityMetadata m, MetamodelImpl metaModel, EmbeddableType keyObj, String idColumn, StringBuilder builder, boolean isPresent, CQLTranslator translator, boolean use) { String partitionKey = null; boolean allowFiltering = false; for (Object o : getKunderaQuery().getFilterClauseQueue()) { if (o instanceof FilterClause) { FilterClause clause = ((FilterClause) o); String fieldName = clause.getProperty(); String condition = clause.getCondition(); List<Object> value = clause.getValue(); boolean useInClause = condition.trim().equalsIgnoreCase("IN"); // if compound key field is given in where clause. isPresent = true; if (keyObj != null && idColumn.equals(fieldName)) { Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields(); Map<Attribute, List<Object>> columnValues = new HashMap<Attribute, List<Object>>(); for (Field field : fields) { if (!ReflectUtils.isTransientOrStatic(field)) { extractCompositeKey(metaModel, keyObj, builder, translator, value, useInClause, columnValues, field); } } // Composite key always contains clusterKey. allowFiltering = true; if (useInClause) { for (Attribute columnAttribute : columnValues.keySet()) { isPresent = appendInClause(builder, translator, columnValues.get(columnAttribute), ((AbstractAttribute) columnAttribute).getBindableJavaType(), ((AbstractAttribute) columnAttribute).getJPAColumnName(), isPresent); } } } else if (keyObj != null && metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()) && StringUtils.contains(fieldName, '.')) { // Means it is a case of composite column. isPresent = getCompoundKeyColumn(metaModel, keyObj, builder, isPresent, translator, fieldName, condition, value, useInClause); allowFiltering = true; } else if (idColumn.equals(fieldName)) { // dont use token for equals query on id column (#856) boolean useToken = use; if (condition.equals("=")) { useToken = false; } isPresent = buildWhereClause(builder, isPresent, translator, condition, value, useInClause, ((AbstractAttribute) m.getIdAttribute()), CassandraUtilities.getIdColumnName(kunderaMetadata, m, externalProperties, ((CassandraClientBase) persistenceDelegeator.getClient(m)).isCql3Enabled(m)), useToken); } else { EntityType entity = metaModel.entity(m.getEntityClazz()); // Metamodel metamodel = // KunderaMetadataManager.getMetamodel(kunderaMetadata, // m.getPersistenceUnit()); String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn(); if (fieldName.equals(discriminatorColumn)) { translator.buildWhereClause(builder, String.class, fieldName, value.isEmpty() ? null : value.get(0), condition, false); isPresent = true; } else { Metamodel metamodel = KunderaMetadataManager.getMetamodel(kunderaMetadata, m.getPersistenceUnit()); Attribute attribute = ((MetamodelImpl) metamodel).getEntityAttribute(m.getEntityClazz(), m.getFieldName(fieldName)); isPresent = buildWhereClause(builder, isPresent, translator, condition, value, useInClause, ((AbstractAttribute) attribute), fieldName, false); } allowFiltering = true; } } } // Strip last AND clause. if (isPresent) { builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length()); } // Append order by clause into query builder = appendOrderByClause(metaModel, m, keyObj, builder, translator); if (allowFiltering && use) { onLimit(builder); builder.append(" "); translator.buildFilteringClause(builder); } else if (use) { onLimit(builder); } return isPresent; }
From source file:lcmc.crm.domain.CrmXml.java
private void initResourceAgentsWithoutMetaData() { final String command = host.getHostParser().getDistCommand("Heartbeat.getOCFParametersQuick", (ConvertCmdCallback) null);//from w w w.java2 s.c om final SshOutput ret = host.captureCommandProgressIndicator(Tools.getString("CRMXML.GetRAMetaData"), new ExecCommandConfig().command(command).silentCommand().silentOutput().sshCommandTimeout(60000)); boolean linbitDrbdPresent0 = false; boolean drbddiskPresent0 = false; if (ret.getExitCode() != 0) { drbddiskResourceAgentPresent = drbddiskPresent0; linbitDrbdResourceAgentPresent = linbitDrbdPresent0; return; } final String output = ret.getOutput(); if (output == null) { drbddiskResourceAgentPresent = drbddiskPresent0; linbitDrbdResourceAgentPresent = linbitDrbdPresent0; return; } final String[] lines = output.split("\\r?\\n"); final Pattern cp = Pattern.compile("^class:\\s*(.*?)\\s*$"); final Pattern pp = Pattern.compile("^provider:\\s*(.*?)\\s*$"); final Pattern sp = Pattern.compile("^ra:\\s*(.*?)\\s*$"); final StringBuilder xml = new StringBuilder(""); String resourceClass = null; String provider = null; String serviceName = null; for (final String line : lines) { final Matcher cm = cp.matcher(line); if (cm.matches()) { resourceClass = cm.group(1); continue; } final Matcher pm = pp.matcher(line); if (pm.matches()) { provider = pm.group(1); continue; } final Matcher sm = sp.matcher(line); if (sm.matches()) { serviceName = sm.group(1); } if (serviceName != null) { xml.append(line); xml.append('\n'); if ("drbddisk".equals(serviceName)) { drbddiskPresent0 = true; } else if ("drbd".equals(serviceName) && "linbit".equals(provider)) { linbitDrbdPresent0 = true; } final ResourceAgent ra; if ("drbddisk".equals(serviceName) && ResourceAgent.HEARTBEAT_CLASS_NAME.equals(resourceClass)) { ra = drbddiskResourceAgent; ra.setMetaDataLoaded(true); setLsbResourceAgent(serviceName, resourceClass, ra); } else if ("drbd".equals(serviceName) && ResourceAgent.OCF_CLASS_NAME.equals(resourceClass) && "linbit".equals(provider)) { ra = linbitDrbdResourceAgent; } else { ra = new ResourceAgent(serviceName, provider, resourceClass); if (IGNORE_RA_DEFAULTS_FOR.contains(serviceName)) { ra.setIgnoreDefaults(true); } if (ResourceAgent.SERVICE_CLASSES.contains(resourceClass) || ResourceAgent.HEARTBEAT_CLASS_NAME.equals(resourceClass)) { ra.setMetaDataLoaded(true); setLsbResourceAgent(serviceName, resourceClass, ra); } } serviceToResourceAgentMap.put(serviceName, provider, resourceClass, ra); List<ResourceAgent> raList = classToServicesMap.get(resourceClass); if (raList == null) { raList = new ArrayList<ResourceAgent>(); classToServicesMap.put(resourceClass, raList); } raList.add(ra); serviceName = null; xml.delete(0, xml.length()); } } drbddiskResourceAgentPresent = drbddiskPresent0; linbitDrbdResourceAgentPresent = linbitDrbdPresent0; }
From source file:com.github.gekoh.yagen.ddl.CreateDDL.java
private String getHistTableSqlCreateString(Dialect dialect, String sqlCreateString, String histTableName, String histColName, Set<String> columns, List<String> pkCols, IntervalPartitioning livePartitioning) { checkTableName(dialect, histTableName); Matcher matcher = TBL_PATTERN.matcher(sqlCreateString); Matcher matchUnique = UNIQUE_PATTERN.matcher(sqlCreateString); StringBuilder sql = new StringBuilder(); // try matching create table sql with PK definition if (!matcher.matches()) { matcher = TBL_PATTERN_WO_PK.matcher(sqlCreateString); // next try without PD definition (e.g. for CollectionTable) if (!matcher.matches()) { throw new IllegalStateException("cannot find create table in sql: " + sqlCreateString); }/* www. ja va 2 s . c o m*/ sql.append(sqlCreateString.substring(0, matcher.start(TBL_PATTERN_WO_PK_IDX_TBLNAME))) .append(histTableName); sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_WO_PK_IDX_TBLNAME), matcher.end(TBL_PATTERN_WO_PK_IDX_BEFORE_COL_DEF))); sql.append(formatColumn(dialect, HIST_TABLE_PK_COLUMN_NAME + " ${varcharType} not null", Constants.UUID_LEN, null, null)).append(", "); sql.append( formatColumn(dialect, HIST_OPERATION_COLUMN_NAME + " ${varcharType} not null", 1, null, null)) .append(", "); sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_WO_PK_IDX_BEFORE_COL_DEF), matcher.start(TBL_PATTERN_WO_PK_IDX_AFTER_COL_DEF))); sql.append(", "); if (!columns.contains(histColName)) { sql.append(formatColumn(dialect, histColName + " ${timestampType} not null", null, null, null)) .append(", "); } sql.append("primary key ("); sql.append(HIST_TABLE_PK_COLUMN_NAME).append("), "); sql.append("unique ("); for (String columnName : pkCols) { sql.append(columnName).append(", "); } sql.append(histColName); sql.append(")"); sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_WO_PK_IDX_AFTER_COL_DEF))); } else { sql.append(sqlCreateString.substring(0, matcher.start(TBL_PATTERN_IDX_TBLNAME))).append(histTableName); sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_IDX_TBLNAME), matcher.start(TBL_PATTERN_IDX_TBL_DEF))); sql.append(formatColumn(dialect, HIST_TABLE_PK_COLUMN_NAME + " ${varcharType} not null", Constants.UUID_LEN, null, null)).append(", "); sql.append( formatColumn(dialect, HIST_OPERATION_COLUMN_NAME + " ${varcharType} not null", 1, null, null)) .append(", "); sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_IDX_TBL_DEF), matcher.start(TBL_PATTERN_IDX_PK_CLAUSE))); if (!columns.contains(histColName)) { sql.append(formatColumn(dialect, histColName + " ${timestampType} not null", null, null, null)) .append(", "); } sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_IDX_PK_CLAUSE), matcher.start(TBL_PATTERN_IDX_PK_COLLIST))); sql.append(HIST_TABLE_PK_COLUMN_NAME).append("), "); sql.append("unique ("); sql.append(matcher.group(TBL_PATTERN_IDX_PK_COLLIST)); sql.append(", "); sql.append(histColName); sql.append(")"); int restIdx = matcher.end(TBL_PATTERN_IDX_PK_CLAUSE); while (matchUnique.find(restIdx)) { restIdx = matchUnique.end(1); } sql.append(sqlCreateString.substring(restIdx)); } Matcher uniqueColMatcher = COL_PATTERN.matcher(sql.toString()); int colIdx = 0; while (uniqueColMatcher.find(colIdx)) { String colName = TableConfig.getIdentifierForReference(uniqueColMatcher.group(COL_PATTERN_IDX_COLNAME)); // remove unique constraint from single column if (uniqueColMatcher.group(COL_PATTERN_IDX_UNIQUE) != null) { sql.delete(uniqueColMatcher.start(COL_PATTERN_IDX_UNIQUE), uniqueColMatcher.end(COL_PATTERN_IDX_UNIQUE)); colIdx = uniqueColMatcher.start(); uniqueColMatcher = COL_PATTERN.matcher(sql.toString()); } // remove not null constraints else if (!colName.equals(HIST_OPERATION_COLUMN_NAME) && !colName.equals(histColName) && uniqueColMatcher.group(COL_PATTERN_IDX_NOT) != null) { sql.delete(uniqueColMatcher.start(COL_PATTERN_IDX_NOTNULL), uniqueColMatcher.end(COL_PATTERN_IDX_NOTNULL)); colIdx = uniqueColMatcher.start(); uniqueColMatcher = COL_PATTERN.matcher(sql.toString()); } else if (colName.equals(histColName)) { String addCol = ", " + HIST_INVALID_TIMESTAMP_COLUMN_NAME + " " + uniqueColMatcher.group(COL_PATTERN_IDX_TYPE); sql.insert(uniqueColMatcher.end() - 1, addCol); colIdx = uniqueColMatcher.end() + addCol.length(); uniqueColMatcher = COL_PATTERN.matcher(sql.toString()); } else { colIdx = uniqueColMatcher.end(); } } StringBuffer additionalObjects = new StringBuffer(); if (supportsPartitioning(dialect) && livePartitioning != null) { sqlCreateString = addPartitioning(additionalObjects, livePartitioning, histTableName, sql.toString(), columns, pkCols); } else { sqlCreateString = sql.toString(); } sqlCreateString = addConstraintsAndNames(dialect, additionalObjects, sqlCreateString, histTableName.toLowerCase(), null); // not adding default values to history tables, this will make investigations very hard // sqlCreateString = addDefaultValues(sqlCreateString, histTableName.toLowerCase()); getProfile().duplex(ObjectType.TABLE, histTableName, sqlCreateString); return sqlCreateString + additionalObjects.toString(); }
From source file:org.apache.asterix.app.translator.QueryTranslator.java
protected List<String> constructPregelixCommand(RunStatement pregelixStmt, String fromDataverseName, String fromDatasetName, String toDataverseName, String toDatasetName) { // Constructs AsterixDB parameters, e.g., URL, source dataset and sink dataset. AsterixExternalProperties externalProperties = AsterixAppContextInfo.INSTANCE.getExternalProperties(); String clientIP = ClusterProperties.INSTANCE.getCluster().getMasterNode().getClientIp(); StringBuilder asterixdbParameterBuilder = new StringBuilder(); asterixdbParameterBuilder.append("pregelix.asterixdb.url=" + "http://" + clientIP + ":" + externalProperties.getAPIServerPort() + ","); asterixdbParameterBuilder.append("pregelix.asterixdb.source=true,"); asterixdbParameterBuilder.append("pregelix.asterixdb.sink=true,"); asterixdbParameterBuilder.append("pregelix.asterixdb.input.dataverse=" + fromDataverseName + ","); asterixdbParameterBuilder.append("pregelix.asterixdb.input.dataset=" + fromDatasetName + ","); asterixdbParameterBuilder.append("pregelix.asterixdb.output.dataverse=" + toDataverseName + ","); asterixdbParameterBuilder.append("pregelix.asterixdb.output.dataset=" + toDatasetName + ","); asterixdbParameterBuilder.append("pregelix.asterixdb.output.cleanup=false,"); // construct command List<String> cmds = new ArrayList<>(); cmds.add("bin/pregelix"); cmds.add(pregelixStmt.getParameters().get(0)); // jar cmds.add(pregelixStmt.getParameters().get(1)); // class String customizedPregelixProperty = "-cust-prop"; String inputConverterClassKey = "pregelix.asterixdb.input.converterclass"; String inputConverterClassValue = "=org.apache.pregelix.example.converter.VLongIdInputVertexConverter,"; String outputConverterClassKey = "pregelix.asterixdb.output.converterclass"; String outputConverterClassValue = "=org.apache.pregelix.example.converter.VLongIdOutputVertexConverter,"; boolean custPropAdded = false; boolean meetCustProp = false; // User parameters. for (String s : pregelixStmt.getParameters().get(2).split(" ")) { if (meetCustProp) { if (!s.contains(inputConverterClassKey)) { asterixdbParameterBuilder.append(inputConverterClassKey + inputConverterClassValue); }/*from w w w .j a v a 2 s. co m*/ if (!s.contains(outputConverterClassKey)) { asterixdbParameterBuilder.append(outputConverterClassKey + outputConverterClassValue); } cmds.add(asterixdbParameterBuilder.toString() + s); meetCustProp = false; custPropAdded = true; continue; } cmds.add(s); if (s.equals(customizedPregelixProperty)) { meetCustProp = true; } } if (!custPropAdded) { cmds.add(customizedPregelixProperty); // Appends default converter classes to asterixdbParameterBuilder. asterixdbParameterBuilder.append(inputConverterClassKey + inputConverterClassValue); asterixdbParameterBuilder.append(outputConverterClassKey + outputConverterClassValue); // Remove the last comma. asterixdbParameterBuilder.delete(asterixdbParameterBuilder.length() - 1, asterixdbParameterBuilder.length()); cmds.add(asterixdbParameterBuilder.toString()); } return cmds; }
From source file:lcmc.data.CRMXML.java
/** Initialize resource agents WITHOUT their meta data. */ private void initOCFMetaDataQuick() { final String command = host.getDistCommand("Heartbeat.getOCFParametersQuick", (ConvertCmdCallback) null); final SSH.SSHOutput ret = Tools.execCommandProgressIndicator(host, command, null, /* ExecCallback */ false, /* outputVisible */ Tools.getString("CRMXML.GetRAMetaData"), 60000); boolean linbitDrbdPresent0 = false; boolean drbddiskPresent0 = false; if (ret.getExitCode() != 0) { drbddiskPresent = drbddiskPresent0; linbitDrbdPresent = linbitDrbdPresent0; return;// w ww . jav a 2 s. co m } final String output = ret.getOutput(); if (output == null) { drbddiskPresent = drbddiskPresent0; linbitDrbdPresent = linbitDrbdPresent0; return; } final String[] lines = output.split("\\r?\\n"); final Pattern mp = Pattern.compile("^master:\\s*(.*?)\\s*$"); final Pattern cp = Pattern.compile("^class:\\s*(.*?)\\s*$"); final Pattern pp = Pattern.compile("^provider:\\s*(.*?)\\s*$"); final Pattern sp = Pattern.compile("^ra:\\s*(.*?)\\s*$"); final StringBuilder xml = new StringBuilder(""); String resourceClass = null; String provider = null; String serviceName = null; boolean masterSlave = false; /* is probably m/s ...*/ for (int i = 0; i < lines.length; i++) { final Matcher cm = cp.matcher(lines[i]); if (cm.matches()) { resourceClass = cm.group(1); continue; } final Matcher pm = pp.matcher(lines[i]); if (pm.matches()) { provider = pm.group(1); continue; } final Matcher sm = sp.matcher(lines[i]); if (sm.matches()) { serviceName = sm.group(1); } if (serviceName != null) { xml.append(lines[i]); xml.append('\n'); if ("drbddisk".equals(serviceName)) { drbddiskPresent0 = true; } else if ("drbd".equals(serviceName) && "linbit".equals(provider)) { linbitDrbdPresent0 = true; } ResourceAgent ra; if ("drbddisk".equals(serviceName) && ResourceAgent.HEARTBEAT_CLASS.equals(resourceClass)) { ra = hbDrbddisk; ra.setMetaDataLoaded(true); setLSBResourceAgent(serviceName, resourceClass, ra); } else if ("drbd".equals(serviceName) && ResourceAgent.OCF_CLASS.equals(resourceClass) && "linbit".equals(provider)) { ra = hbLinbitDrbd; } else { ra = new ResourceAgent(serviceName, provider, resourceClass); if (IGNORE_DEFAULTS_FOR.contains(serviceName)) { ra.setIgnoreDefaults(true); } if (ResourceAgent.SERVICE_CLASSES.contains(resourceClass) || ResourceAgent.HEARTBEAT_CLASS.equals(resourceClass)) { ra.setMetaDataLoaded(true); setLSBResourceAgent(serviceName, resourceClass, ra); } } serviceToResourceAgentMap.put(serviceName, provider, resourceClass, ra); List<ResourceAgent> raList = classToServicesMap.get(resourceClass); if (raList == null) { raList = new ArrayList<ResourceAgent>(); classToServicesMap.put(resourceClass, raList); } raList.add(ra); serviceName = null; xml.delete(0, xml.length()); } } drbddiskPresent = drbddiskPresent0; linbitDrbdPresent = linbitDrbdPresent0; }