private int getStyleValue(ColorThemeSetting setting) { final boolean bold = TRUE.equals(setting.isBoldEnabled()); final boolean italic = TRUE.equals(setting.isItalicEnabled()); final boolean underline = TRUE.equals(setting.isUnderlineEnabled()); final boolean strikethrough = TRUE.equals(setting.isStrikethroughEnabled()); int style = SWT.NORMAL; style |= bold ? SWT.BOLD : 0; style |= italic ? SWT.ITALIC : 0; style |= underline ? STYLE_VALUE_UNDERLINE : 0; style |= strikethrough ? STYLE_VALUE_STRIKETHROUGH : 0; return style; }
private void execute(boolean testing) throws Exception { if (TRUE.equalsIgnoreCase(System.getProperty(SKIP_PROP))) { LOG.info("Skipping startup routines"); return; } Collections.sort(routines, new StartupRoutineComparator()); int total = routines.size(); int index = 1; for (StartupRoutine routine : routines) { if (!(testing && routine.skipInTests())) { LOG.info( "Executing startup routine [" + index + " of " + total + ", runlevel " + routine.getRunlevel() + "]: " + routine.getName()); routine.execute(); ++index; } } LOG.info("All startup routines done"); }
@Override public OperationResult invokeOperation(String name, Configuration parameters) throws Exception { if (name.equals(ENABLE_OPERATION)) { Operation operation = new Operation(ENABLE_OPERATION, getAddress()); Boolean persistent = Boolean.valueOf(parameters.getSimpleValue("persistent", TRUE.toString())); operation.addAdditionalProperty("persistent", persistent); Result res = getASConnection().execute(operation); if (res.isSuccess()) { return new OperationResult(); } else { OperationResult operationResult = new OperationResult(); operationResult.setErrorMessage(res.getFailureDescription()); return operationResult; } } if (name.equals(DISABLE_OPERATION)) { Operation operation = new Operation(DISABLE_OPERATION, getAddress()); boolean allowResourceServiceRestart = Boolean.parseBoolean( parameters.getSimpleValue("allow-resource-service-restart", FALSE.toString())); if (allowResourceServiceRestart) { operation.allowResourceServiceRestart(); } Result res = getASConnection().execute(operation); if (res.isSuccess()) { return new OperationResult(); } else { OperationResult operationResult = new OperationResult(); operationResult.setErrorMessage(res.getFailureDescription()); return operationResult; } } return super.invokeOperation(name, parameters); }
@SuppressWarnings("unchecked") private final R fetchOne() { AbstractRecord record = null; try { if (!isClosed && rs.next()) { // [#1296] Force a row-lock by updating the row if the // FOR UPDATE clause is simulated if (TRUE.equals(ctx.data(DATA_LOCK_ROWS_FOR_UPDATE))) { rs.updateObject(1, rs.getObject(1)); rs.updateRow(); } record = Utils.newRecord((Class<AbstractRecord>) type, fields, ctx.configuration()) .operate(initialiser); } } catch (SQLException e) { ctx.sqlException(e); listener.exception(ctx); throw ctx.exception(); } // [#1868] [#2373] [#2385] This calls through to Utils.safeClose() // if necessary, lazy-terminating the ExecuteListener lifecycle if // the result is not eager-fetched. if (record == null) { CursorImpl.this.close(); } return (R) record; }
private static Boolean convertBool(Attribute attr, Object value) { if (value instanceof Boolean) { return (Boolean) value; } if (value == null) { return null; } Boolean booleanValue; if (value instanceof String) { String stringValue = (String) value; if (stringValue.equalsIgnoreCase(TRUE.toString())) { booleanValue = true; } else if (stringValue.equalsIgnoreCase(FALSE.toString())) { booleanValue = false; } else { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] value [%s] cannot be converter to type [%s]", attr.getName(), value, Boolean.class.getSimpleName()))); } } else { throw new MolgenisValidationException( new ConstraintViolation( format( "Attribute [%s] value is of type [%s] instead of [%s] or [%s]", attr.getName(), value.getClass().getSimpleName(), String.class.getSimpleName(), Boolean.class.getSimpleName()))); } return booleanValue; }
/** @param control control that may fill vertically */ protected boolean willFillVertically(Control control, Map<String, String> attributes) { if (attributes != null && TRUE.equals(attributes.get(LARGE))) { return true; } return false; }
protected String layoutBeforeChild( Control control, String labelText, String elementName, Map<String, String> attributes, Composite composite, SwtMetawidget metawidget) { // Add label if (SimpleLayoutUtils.needsLabel(labelText, elementName)) { Label label = new Label(composite, SWT.None); label.setData(NAME, attributes.get(NAME) + LABEL_NAME_SUFFIX); if (mLabelFont != null) { label.setFont(mLabelFont); } if (mLabelForeground != null) { label.setForeground(mLabelForeground); } label.setAlignment(mLabelAlignment); // Required String labelTextToUse = labelText; if (mRequiredText != null && TRUE.equals(attributes.get(REQUIRED)) && !WidgetBuilderUtils.isReadOnly(attributes) && !metawidget.isReadOnly()) { if (mRequiredAlignment == SWT.CENTER) { labelTextToUse += mRequiredText; } else if (mRequiredAlignment == SWT.LEFT) { labelTextToUse = mRequiredText + labelTextToUse; } } if (mLabelSuffix != null) { labelTextToUse += mLabelSuffix; } label.setText(labelTextToUse); GridData labelLayoutData = new GridData(); labelLayoutData.horizontalAlignment = SWT.FILL; labelLayoutData.verticalAlignment = SWT.FILL; label.setLayoutData(labelLayoutData); label.moveAbove(control); } return labelText; }
protected void applyFilters(BatchQuery query) { if (batchId != null) { query.batchId(batchId); } if (type != null) { query.type(type); } if (TRUE.equals(withoutTenantId)) { query.withoutTenantId(); } if (tenantIds != null && !tenantIds.isEmpty()) { query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()])); } if (TRUE.equals(suspended)) { query.suspended(); } if (FALSE.equals(suspended)) { query.active(); } }
public void updateClientFromRep( ClientRepresentation rep, ClientModel client, KeycloakSession session) throws ModelDuplicateException { if (TRUE.equals(rep.isServiceAccountsEnabled()) && !client.isServiceAccountsEnabled()) { new ClientManager(new RealmManager(session)).enableServiceAccount(client); } if (!rep.getClientId().equals(client.getClientId())) { new ClientManager(new RealmManager(session)).clientIdChanged(client, rep.getClientId()); } RepresentationToModel.updateClient(rep, client); if (Profile.isFeatureEnabled(Profile.Feature.AUTHORIZATION)) { if (TRUE.equals(rep.getAuthorizationServicesEnabled())) { authorization().enable(); } else { authorization().disable(); } } }
public StaticXmlWidget processWidget( StaticXmlWidget widget, String elementName, Map<String, String> attributes, StaticXmlMetawidget metawidget) { if (TRUE.equals(attributes.get(REQUIRED))) { widget.putAttribute(REQUIRED, TRUE); } return widget; }
public void loadJobNode(Node arg0) throws LoadJobException { try { selectionPanel.getClearButton().doClick(); List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel .getLoader() .addFile( new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
@Override public void registerKeySubscriber( @NotNull RequestContext rc, @NotNull Subscriber<K> subscriber, @NotNull Filter<K> filter) { addToStats("keySubscription"); final Boolean bootstrap = rc.bootstrap(); final Subscriber<K> sub = subscriber(subscriber, filter); keySubscribers.add(sub); if (bootstrap != Boolean.FALSE && kvStore != null) { try { for (int i = 0; i < kvStore.segments(); i++) kvStore.keysFor(i, sub::onMessage); if (TRUE.equals(rc.endSubscriptionAfterBootstrap())) { sub.onEndOfSubscription(); keySubscribers.remove(sub); } } catch (InvalidSubscriberException e) { keySubscribers.remove(sub); } } }
public UIComponent buildWidget( String elementName, Map<String, String> attributes, UIMetawidget metawidget) { // Not for Tomahawk? if (TRUE.equals(attributes.get(HIDDEN))) { return null; } if (attributes.containsKey(FACES_LOOKUP) || attributes.containsKey(LOOKUP)) { return null; } Application application = FacesContext.getCurrentInstance().getApplication(); String type = WidgetBuilderUtils.getActualClassOrType(attributes); if (type == null) { return null; } Class<?> clazz = ClassUtils.niceForName(type); if (clazz == null) { return null; } // HtmlInputFileUpload if (UploadedFile.class.isAssignableFrom(clazz)) { return application.createComponent("org.apache.myfaces.HtmlInputFileUpload"); } // Not for Tomahawk return null; }
private void registerSubscriber0( @NotNull RequestContext rc, @NotNull Subscriber<MapEvent<K, V>> subscriber, @NotNull Filter<MapEvent<K, V>> filter) { addToStats("subscription"); final Subscriber<MapEvent<K, V>> sub = subscriber(subscriber, filter); this.subscribers.add(sub); Boolean bootstrap = rc.bootstrap(); if (bootstrap != Boolean.FALSE && kvStore != null) { try { for (int i = 0; i < kvStore.segments(); i++) kvStore.entriesFor(i, sub::onMessage); if (TRUE.equals(rc.endSubscriptionAfterBootstrap())) { sub.onEndOfSubscription(); LOG.info("onEndOfSubscription"); this.subscribers.remove(sub); } } catch (InvalidSubscriberException e) { this.subscribers.remove(sub); } } }
public JComponent buildWidget( String elementName, Map<String, String> attributes, SwingMetawidget metawidget) { // Not read-only? if (!WidgetBuilderUtils.isReadOnly(attributes)) { return null; } // Hidden if (TRUE.equals(attributes.get(HIDDEN))) { return new Stub(); } // Action if (ACTION.equals(elementName)) { JButton button = new JButton(metawidget.getLabelString(attributes)); button.setEnabled(false); return button; } // Masked (return a JPanel, so that we DO still render a label) if (TRUE.equals(attributes.get(MASKED))) { return new JPanel(); } // Lookups String lookup = attributes.get(LOOKUP); if (lookup != null && !"".equals(lookup)) { // May have alternate labels String lookupLabels = attributes.get(LOOKUP_LABELS); if (lookupLabels != null && !"".equals(lookupLabels)) { return new LookupLabel( CollectionUtils.newHashMap( CollectionUtils.fromString(lookup), CollectionUtils.fromString(lookupLabels))); } return new JLabel(); } // Lookup the Class Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class); if (clazz != null) { // Primitives if (clazz.isPrimitive()) { return new JLabel(); } if (String.class.equals(clazz)) { if (TRUE.equals(attributes.get(LARGE))) { // Do not use a JLabel: JLabels do not support carriage returns like JTextAreas // do, so a multi-line JTextArea formats to a single line JLabel. Instead use // a non-editable JTextArea within a borderless JScrollPane JTextArea textarea = new JTextArea(); // Since we know we are dealing with Strings, we consider // word-wrapping a sensible default textarea.setLineWrap(true); textarea.setWrapStyleWord(true); textarea.setEditable(false); // We also consider 2 rows a sensible default, so that the // read-only JTextArea is always distinguishable from a JLabel textarea.setRows(2); JScrollPane scrollPane = new JScrollPane(textarea); scrollPane.setBorder(null); return scrollPane; } return new JLabel(); } if (Character.class.equals(clazz)) { return new JLabel(); } if (Date.class.equals(clazz)) { return new JLabel(); } if (Boolean.class.equals(clazz)) { return new JLabel(); } if (Number.class.isAssignableFrom(clazz)) { return new JLabel(); } // Collections if (Collection.class.isAssignableFrom(clazz)) { return new Stub(); } } // Not simple, but don't expand if (TRUE.equals(attributes.get(DONT_EXPAND))) { return new JLabel(); } // Nested Metawidget return null; }
@Test public void writeBooleanTrue() throws Exception { TRUE.write(writer); assertEquals("true", writer.toString()); }
@Override public StaticJavaWidget buildWidget( String elementName, Map<String, String> attributes, StaticJavaMetawidget metawidget) { // Drill down if (ENTITY.equals(elementName)) { return null; } // Suppress if (TRUE.equals(attributes.get(HIDDEN))) { return new StaticJavaStub(); } String type = WidgetBuilderUtils.getActualClassOrType(attributes); Class<?> clazz = ClassUtils.niceForName(type); String name = attributes.get(NAME); // String if (String.class.equals(clazz)) { StaticJavaStub toReturn = new StaticJavaStub(); toReturn .getChildren() .add( new JavaStatement( "String " + name + " = this.search.get" + StringUtils.capitalize(name) + "()")); JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))"); ifNotEmpty .getChildren() .add( new JavaStatement( "predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name + " + '%'))")); toReturn.getChildren().add(ifNotEmpty); return toReturn; } // int if (int.class.equals(clazz)) { StaticJavaStub toReturn = new StaticJavaStub(); toReturn .getChildren() .add( new JavaStatement( "int " + name + " = this.search.get" + StringUtils.capitalize(name) + "()")); JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)"); ifNotEmpty .getChildren() .add( new JavaStatement( "predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))")); toReturn.getChildren().add(ifNotEmpty); return toReturn; } // Lookup if (attributes.containsKey(FACES_LOOKUP)) { StaticJavaStub toReturn = new StaticJavaStub(); JavaStatement getValue = new JavaStatement( ClassUtils.getSimpleName(type) + " " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"); getValue.putImport(type); toReturn.getChildren().add(getValue); JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && " + name + ".getId() != null)"); ifNotEmpty .getChildren() .add( new JavaStatement( "predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))")); toReturn.getChildren().add(ifNotEmpty); return toReturn; } // We tried searching against N_TO_MANY relationships, but had the following problems: // // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following // items'. For 'a Set // having the following item' can do: // predicatesList.add(root.join("customers").in(this.search.getCustomer())); // 2. Cumbersome to have a new class for this.search that only has a single Customer, as opposed // to a Set // 3. Difficult to make JSF's h:selectOne* bind to a Set // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown // // So we've left it out for now return new StaticJavaStub(); }
@Override protected void applyFilters(DecisionDefinitionQuery query) { if (decisionDefinitionId != null) { query.decisionDefinitionId(decisionDefinitionId); } if (decisionDefinitionIdIn != null && !decisionDefinitionIdIn.isEmpty()) { query.decisionDefinitionIdIn( decisionDefinitionIdIn.toArray(new String[decisionDefinitionIdIn.size()])); } if (category != null) { query.decisionDefinitionCategory(category); } if (categoryLike != null) { query.decisionDefinitionCategoryLike(categoryLike); } if (name != null) { query.decisionDefinitionName(name); } if (nameLike != null) { query.decisionDefinitionNameLike(nameLike); } if (deploymentId != null) { query.deploymentId(deploymentId); } if (key != null) { query.decisionDefinitionKey(key); } if (keyLike != null) { query.decisionDefinitionKeyLike(keyLike); } if (resourceName != null) { query.decisionDefinitionResourceName(resourceName); } if (resourceNameLike != null) { query.decisionDefinitionResourceNameLike(resourceNameLike); } if (version != null) { query.decisionDefinitionVersion(version); } if (TRUE.equals(latestVersion)) { query.latestVersion(); } if (decisionRequirementsDefinitionId != null) { query.decisionRequirementsDefinitionId(decisionRequirementsDefinitionId); } if (decisionRequirementsDefinitionKey != null) { query.decisionRequirementsDefinitionKey(decisionRequirementsDefinitionKey); } if (TRUE.equals(withoutDecisionRequirementsDefinition)) { query.withoutDecisionRequirementsDefinition(); } if (tenantIds != null && !tenantIds.isEmpty()) { query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()])); } if (TRUE.equals(withoutTenantId)) { query.withoutTenantId(); } if (TRUE.equals(includeDefinitionsWithoutTenantId)) { query.includeDecisionDefinitionsWithoutTenantId(); } }
/** Is this thread currently replicating remote events from another node? */ public static boolean isReplicating() { return TRUE.equals(isReplicating.get()); }
public UIComponent buildWidget( String elementName, Map<String, String> attributes, UIMetawidget metawidget) { // Not for RichFaces? if (TRUE.equals(attributes.get(HIDDEN))) { return null; } // Note: we tried implementing lookups using org.richfaces.ComboBox, but that // allows manual input and if you set enableManualInput=false it behaves a // bit screwy for our liking (ie. if you hit backspace the browser goes back) if (attributes.containsKey(FACES_LOOKUP) || attributes.containsKey(LOOKUP)) { return null; } // Lookup the class Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null); if (clazz == null) { return null; } // Primitives if (clazz.isPrimitive()) { // Not for RichFaces if (boolean.class.equals(clazz) || char.class.equals(clazz)) { return null; } // Ranged UIComponent ranged = createRanged(attributes); if (ranged != null) { return ranged; } // Not-ranged HtmlInputNumberSpinner spinner = VERSION_SPECIFIC_WIDGET_BUILDER.createInputNumberSpinner(); // May be ranged in one dimension only. In which case, explictly range the *other* // dimension because RichFaces defaults to 0-100 String minimumValue = attributes.get(MINIMUM_VALUE); if (minimumValue != null && !"".equals(minimumValue)) { spinner.setMinValue(minimumValue); } else if (byte.class.equals(clazz)) { spinner.setMinValue(String.valueOf(Byte.MIN_VALUE)); } else if (short.class.equals(clazz)) { spinner.setMinValue(String.valueOf(Short.MIN_VALUE)); } else if (int.class.equals(clazz)) { spinner.setMinValue(String.valueOf(Integer.MIN_VALUE)); } else if (long.class.equals(clazz)) { spinner.setMinValue(String.valueOf(Long.MIN_VALUE)); } else if (float.class.equals(clazz)) { spinner.setMinValue(String.valueOf(-Float.MAX_VALUE)); } else if (double.class.equals(clazz)) { spinner.setMinValue(String.valueOf(-Double.MAX_VALUE)); } String maximumValue = attributes.get(MAXIMUM_VALUE); if (maximumValue != null && !"".equals(maximumValue)) { spinner.setMaxValue(maximumValue); } else if (byte.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Byte.MAX_VALUE)); } else if (short.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Short.MAX_VALUE)); } else if (int.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Integer.MAX_VALUE)); } else if (long.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Long.MAX_VALUE)); } else if (float.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Float.MAX_VALUE)); } else if (double.class.equals(clazz)) { spinner.setMaxValue(String.valueOf(Double.MAX_VALUE)); } // Wraps around? spinner.setCycled(false); // Stepped if (float.class.equals(clazz) || double.class.equals(clazz)) { spinner.setStep("0.1"); } return spinner; } // Dates // // Note: when http://jira.jboss.org/jira/browse/RF-2023 gets implemented, that // would allow external, app-level configuration of this Calendar if (Date.class.isAssignableFrom(clazz)) { UICalendar calendar = FacesUtils.createComponent(HtmlCalendar.COMPONENT_TYPE, "org.richfaces.CalendarRenderer"); if (attributes.containsKey(DATETIME_PATTERN)) { calendar.setDatePattern(attributes.get(DATETIME_PATTERN)); } if (attributes.containsKey(LOCALE)) { calendar.setLocale(new Locale(attributes.get(LOCALE))); } if (attributes.containsKey(TIME_ZONE)) { calendar.setTimeZone(TimeZone.getTimeZone(attributes.get(TIME_ZONE))); } return calendar; } // Object primitives if (Number.class.isAssignableFrom(clazz)) { // Ranged UIComponent ranged = createRanged(attributes); if (ranged != null) { return ranged; } // Not-ranged // // Until https://jira.jboss.org/jira/browse/RF-4450 is fixed, do not use // UIInputNumberSpinner for nullable numbers } // RichFaces version-specific return VERSION_SPECIFIC_WIDGET_BUILDER.buildWidget(elementName, attributes, metawidget); }
public void insert( String keySpace, String columnFamily, String key, Map<String, Object> values, boolean probablyNew) throws StorageClientException { checkClosed(); Map<String, PreparedStatement> statementCache = Maps.newHashMap(); boolean autoCommit = true; try { autoCommit = startBlock(); String rid = rowHash(keySpace, columnFamily, key); for (Entry<String, Object> e : values.entrySet()) { String k = e.getKey(); Object o = e.getValue(); if (o instanceof byte[]) { throw new RuntimeException( "Invalid content in " + k + ", storing byte[] rather than streaming it"); } } Map<String, Object> m = get(keySpace, columnFamily, key); if (storageClientListener != null) { storageClientListener.before(keySpace, columnFamily, key, m); } if (TRUE.equals(m.get(DELETED_FIELD))) { // if the map was previously deleted, delete all content since we don't want the old map // becoming part of the new map. m.clear(); } for (Entry<String, Object> e : values.entrySet()) { String k = e.getKey(); Object o = e.getValue(); if (o instanceof RemoveProperty || o == null) { m.remove(k); } else { m.put(k, o); } } if (storageClientListener != null) { storageClientListener.after(keySpace, columnFamily, key, m); } LOGGER.debug("Saving {} {} {} ", new Object[] {key, rid, m}); if (probablyNew && !UPDATE_FIRST_SEQUENCE.equals(getSql(SQL_STATEMENT_SEQUENCE))) { PreparedStatement insertBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW, rid, statementCache); insertBlockRow.clearWarnings(); insertBlockRow.clearParameters(); insertBlockRow.setString(1, rid); InputStream insertStream = null; try { insertStream = Types.storeMapToStream(rid, m, columnFamily); } catch (UTFDataFormatException e) { throw new DataFormatException(INVALID_DATA_ERROR, e); } if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) { insertBlockRow.setBinaryStream(2, insertStream, insertStream.available()); } else { insertBlockRow.setBinaryStream(2, insertStream); } int rowsInserted = 0; try { long t1 = System.currentTimeMillis(); rowsInserted = insertBlockRow.executeUpdate(); checkSlow(t1, getSql(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW)); } catch (SQLException e) { LOGGER.debug(e.getMessage(), e); } if (rowsInserted == 0) { PreparedStatement updateBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW, rid, statementCache); updateBlockRow.clearWarnings(); updateBlockRow.clearParameters(); updateBlockRow.setString(2, rid); try { insertStream = Types.storeMapToStream(rid, m, columnFamily); } catch (UTFDataFormatException e) { throw new DataFormatException(INVALID_DATA_ERROR, e); } if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) { updateBlockRow.setBinaryStream(1, insertStream, insertStream.available()); } else { updateBlockRow.setBinaryStream(1, insertStream); } long t = System.currentTimeMillis(); int u = updateBlockRow.executeUpdate(); checkSlow(t, getSql(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW)); if (u == 0) { throw new StorageClientException("Failed to save " + rid); } else { LOGGER.debug("Updated {} ", rid); } } else { LOGGER.debug("Inserted {} ", rid); } } else { PreparedStatement updateBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW, rid, statementCache); updateBlockRow.clearWarnings(); updateBlockRow.clearParameters(); updateBlockRow.setString(2, rid); InputStream updateStream = null; try { updateStream = Types.storeMapToStream(rid, m, columnFamily); } catch (UTFDataFormatException e) { throw new DataFormatException(INVALID_DATA_ERROR, e); } if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) { updateBlockRow.setBinaryStream(1, updateStream, updateStream.available()); } else { updateBlockRow.setBinaryStream(1, updateStream); } long t = System.currentTimeMillis(); int u = updateBlockRow.executeUpdate(); checkSlow(t, getSql(keySpace, columnFamily, SQL_BLOCK_UPDATE_ROW)); if (u == 0) { PreparedStatement insertBlockRow = getStatement(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW, rid, statementCache); insertBlockRow.clearWarnings(); insertBlockRow.clearParameters(); insertBlockRow.setString(1, rid); try { updateStream = Types.storeMapToStream(rid, m, columnFamily); } catch (UTFDataFormatException e) { throw new DataFormatException(INVALID_DATA_ERROR, e); } if ("1.5".equals(getSql(JDBC_SUPPORT_LEVEL))) { insertBlockRow.setBinaryStream(2, updateStream, updateStream.available()); } else { insertBlockRow.setBinaryStream(2, updateStream); } t = System.currentTimeMillis(); u = insertBlockRow.executeUpdate(); checkSlow(t, getSql(keySpace, columnFamily, SQL_BLOCK_INSERT_ROW)); if (u == 0) { throw new StorageClientException("Failed to save " + rid); } else { LOGGER.debug("Inserted {} ", rid); } } else { LOGGER.debug("Updated {} ", rid); } } // Indexing --------------------------------------------------------------------------- indexer.index(statementCache, keySpace, columnFamily, key, rid, values); endBlock(autoCommit); } catch (SQLException e) { abandonBlock(autoCommit); LOGGER.warn( "Failed to perform insert/update operation on {}:{}:{} ", new Object[] {keySpace, columnFamily, key}, e); throw new StorageClientException(e.getMessage(), e); } catch (IOException e) { abandonBlock(autoCommit); LOGGER.warn( "Failed to perform insert/update operation on {}:{}:{} ", new Object[] {keySpace, columnFamily, key}, e); throw new StorageClientException(e.getMessage(), e); } finally { closeStatementCache(statementCache); } }
public View buildWidget( String elementName, Map<String, String> attributes, AndroidMetawidget metawidget) { // Not read-only? if (!WidgetBuilderUtils.isReadOnly(attributes)) { return null; } // Hidden if (TRUE.equals(attributes.get(HIDDEN))) { return new Stub(metawidget.getContext()); } // Action if (ACTION.equals(elementName)) { return new Stub(metawidget.getContext()); } // Masked (return an invisible View, so that we DO still // render a label and reserve some blank space) if (TRUE.equals(attributes.get(MASKED))) { TextView view = new TextView(metawidget.getContext()); view.setVisibility(View.INVISIBLE); return view; } // Lookups String lookup = attributes.get(LOOKUP); if (lookup != null && !"".equals(lookup)) { return new TextView(metawidget.getContext()); } // Lookup the Class Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class); if (clazz != null) { if (clazz.isPrimitive()) { return new TextView(metawidget.getContext()); } if (String.class.equals(clazz)) { return new TextView(metawidget.getContext()); } if (Character.class.equals(clazz)) { return new TextView(metawidget.getContext()); } if (Date.class.equals(clazz)) { return new TextView(metawidget.getContext()); } if (Boolean.class.equals(clazz)) { return new TextView(metawidget.getContext()); } if (Number.class.isAssignableFrom(clazz)) { return new TextView(metawidget.getContext()); } // Collections if (Collection.class.isAssignableFrom(clazz)) { return new Stub(metawidget.getContext()); } } // Not simple, but don't expand if (TRUE.equals(attributes.get(DONT_EXPAND))) { return new TextView(metawidget.getContext()); } // Nested Metawidget return null; }