private void commitImport(final String source, ImportMessages importMessages) throws Exception { UnitOfWork trans = getTransaction(); final String txName = trans.getName(); trans.commit(); Repository.UnitOfWorkListener uowListener = trans.getCallback(); SynchronousCallback callback = null; if (uowListener != null && uowListener instanceof SynchronousCallback) { callback = (SynchronousCallback) uowListener; } final boolean success = callback.await(3, TimeUnit.MINUTES); if (success) { // For imports, if has callback error - add to import errors and return. if (callback.hasError()) { importMessages.addErrorMessage(callback.error()); return; } final KException error = trans.getError(); final Repository.UnitOfWork.State txState = trans.getState(); if ((error != null) || !State.COMMITTED.equals(txState)) { throw new KException(I18n.bind(ShellI18n.transactionCommitError, txName), error); } } else { throw new KException(I18n.bind(ShellI18n.transactionTimeout, txName)); } }
/** * {@inheritDoc} * * @see * org.komodo.spi.repository.ValidationManager#addChildRelationshipValidationRule(org.komodo.spi.repository.Repository.UnitOfWork, * java.lang.String, java.lang.String, java.lang.String, java.util.List, java.util.List, * java.util.List, java.util.List, java.util.List, java.util.List) */ @Override public Rule addChildRelationshipValidationRule( final UnitOfWork transaction, final String name, final String nodeType, final String childType, final List<String> propsThatMustExist, final List<String> propsThatMustNotExist, final List<String> childTypesThatMustExist, final List<String> childTypesThatMustNotExist, final List<LocalizedMessage> descriptions, final List<LocalizedMessage> messages) throws KException { ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$ ArgCheck.isTrue( (transaction.getState() == State.NOT_STARTED), "transaction state is not NOT_STARTED"); //$NON-NLS-1$ ArgCheck.isNotEmpty(childType, "childType"); // $NON-NLS-1$ ArgCheck.isTrue( ((propsThatMustExist != null) && !propsThatMustExist.isEmpty()) || ((propsThatMustNotExist != null) && !propsThatMustNotExist.isEmpty()) || ((childTypesThatMustExist != null) && !childTypesThatMustExist.isEmpty()) || ((childTypesThatMustNotExist != null) && !childTypesThatMustNotExist.isEmpty()), "at least one relationship collection must not be empty"); //$NON-NLS-1$ if (LOGGER.isDebugEnabled()) { LOGGER.debug( "addChildRelationshipValidationRule: transaction = {0}, name = {1}", transaction.getName(), name); // $NON-NLS-1$ } try { final RuleImpl rule = createRule( transaction, name, KomodoLexicon.Rule.RELATIONSHIP_RULE, Rule.ValidationType.CHILD, Rule.RuleType.RELATIONSHIP, nodeType, descriptions, messages); processMultiValuedProperty( transaction, rule, KomodoLexicon.Rule.PROP_EXISTS, propsThatMustExist); processMultiValuedProperty( transaction, rule, KomodoLexicon.Rule.PROP_ABSENT, propsThatMustNotExist); processMultiValuedProperty( transaction, rule, KomodoLexicon.Rule.CHILD_EXISTS, childTypesThatMustExist); processMultiValuedProperty( transaction, rule, KomodoLexicon.Rule.CHILD_ABSENT, childTypesThatMustNotExist); return rule; } catch (final Exception e) { throw ObjectImpl.handleError(e); } }
/** * {@inheritDoc} * * @see * org.komodo.spi.repository.ValidationManager#addPropertyValueNumberValidationRule(org.komodo.spi.repository.Repository.UnitOfWork, * java.lang.String, java.lang.String, java.lang.String, java.lang.Number, boolean, * java.lang.Number, boolean, java.util.List, java.util.List) */ @Override public Rule addPropertyValueNumberValidationRule( final UnitOfWork transaction, final String name, final String nodeType, final String propertyName, final Number minValue, final boolean minInclusive, final Number maxValue, final boolean maxInclusive, final List<LocalizedMessage> descriptions, final List<LocalizedMessage> messages) throws KException { ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$ ArgCheck.isTrue( (transaction.getState() == State.NOT_STARTED), "transaction state is not NOT_STARTED"); //$NON-NLS-1$ ArgCheck.isNotEmpty(propertyName, "propertyName"); // $NON-NLS-1$ ArgCheck.isTrue( (minValue != null) || (maxValue != null), "minValue or maxValue must not be null"); //$NON-NLS-1$ if (LOGGER.isDebugEnabled()) { LOGGER.debug( "addPropertyValueNumberValidationRule: transaction = {0}, name = {1}", transaction.getName(), name); // $NON-NLS-1$ } try { final RuleImpl rule = createRule( transaction, name, KomodoLexicon.Rule.NUMBER_RULE, Rule.ValidationType.PROPERTY, Rule.RuleType.NUMBER, nodeType, descriptions, messages); rule.setProperty(transaction, KomodoLexicon.Rule.JCR_NAME, propertyName); if (minValue != null) { rule.setProperty(transaction, KomodoLexicon.Rule.MIN_VALUE, minValue.toString()); rule.setProperty(transaction, KomodoLexicon.Rule.MIN_VALUE_INCLUSIVE, minInclusive); } if (maxValue != null) { rule.setProperty(transaction, KomodoLexicon.Rule.MAX_VALUE, maxValue.toString()); rule.setProperty(transaction, KomodoLexicon.Rule.MAX_VALUE_INCLUSIVE, maxInclusive); } return rule; } catch (final Exception e) { throw ObjectImpl.handleError(e); } }
/** * {@inheritDoc} * * @see * org.komodo.spi.repository.ValidationManager#addPropertyPatternRule(org.komodo.spi.repository.Repository.UnitOfWork, * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.List, * java.util.List) */ @Override public Rule addPropertyPatternRule( final UnitOfWork transaction, final String name, final String nodeType, final String propertyName, final String pattern, final List<LocalizedMessage> descriptions, final List<LocalizedMessage> messages) throws KException { ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$ ArgCheck.isTrue( (transaction.getState() == State.NOT_STARTED), "transaction state is not NOT_STARTED"); //$NON-NLS-1$ ArgCheck.isNotEmpty(propertyName, "propertyName"); // $NON-NLS-1$ ArgCheck.isNotEmpty(pattern, "pattern"); // $NON-NLS-1$ if (LOGGER.isDebugEnabled()) { LOGGER.debug( "addPropertyPatternRule: transaction = {0}, name = {1}", transaction.getName(), name); // $NON-NLS-1$ } try { final RuleImpl rule = createRule( transaction, name, KomodoLexicon.Rule.PATTERN_RULE, Rule.ValidationType.PROPERTY, Rule.RuleType.PATTERN, nodeType, descriptions, messages); rule.setProperty(transaction, KomodoLexicon.Rule.JCR_NAME, propertyName); rule.setProperty(transaction, KomodoLexicon.Rule.PATTERN, pattern); return rule; } catch (final Exception e) { throw ObjectImpl.handleError(e); } }
/** * {@inheritDoc} * * @see * org.komodo.spi.repository.ValidationManager#addSameNameSiblingValidationRule(org.komodo.spi.repository.Repository.UnitOfWork, * java.lang.String, java.lang.String, boolean, java.util.List, java.util.List) */ @Override public Rule addSameNameSiblingValidationRule( final UnitOfWork transaction, final String name, final String nodeType, final boolean matchType, final List<LocalizedMessage> descriptions, final List<LocalizedMessage> messages) throws KException { ArgCheck.isNotNull(transaction, "transaction"); // $NON-NLS-1$ ArgCheck.isTrue( (transaction.getState() == State.NOT_STARTED), "transaction state is not NOT_STARTED"); //$NON-NLS-1$ if (LOGGER.isDebugEnabled()) { LOGGER.debug( "addSameNameSiblingValidationRule: transaction = {0}, name = {1}", transaction.getName(), name); // $NON-NLS-1$ } try { final RuleImpl rule = createRule( transaction, name, KomodoLexicon.Rule.SNS_RULE, Rule.ValidationType.CHILD, Rule.RuleType.SAME_NAME_SIBLING, nodeType, descriptions, messages); rule.setProperty(transaction, KomodoLexicon.Rule.MATCH_TYPE, matchType); return rule; } catch (final Exception e) { throw ObjectImpl.handleError(e); } }