Ejemplo n.º 1
0
 public InputEntityVisitor apply(InputEntityVisitor from)
 {
     foreach (Decorator decorator in _decorators)
     {
         from = decorator.apply(from);
     }
     return(from);
 }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean next(org.neo4j.unsafe.impl.batchimport.input.InputEntityVisitor nakedVisitor) throws java.io.IOException
        public override bool Next(InputEntityVisitor nakedVisitor)
        {
            if (_visitor == null || nakedVisitor != _previousVisitor)
            {
                DecorateVisitor(nakedVisitor);
            }

            return(_parser.next(_visitor));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean next(org.neo4j.unsafe.impl.batchimport.input.InputEntityVisitor visitor) throws java.io.IOException
        public override bool Next(InputEntityVisitor visitor)
        {
            if (_cursor < _entities.Length)
            {
                _entities[_cursor++].replayOnto(visitor);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean fillFrom(org.neo4j.csv.reader.Chunker chunker) throws java.io.IOException
        public override bool FillFrom(Chunker chunker)
        {
            if (chunker.NextChunk(_processingChunk))
            {
                CloseCurrentParser();
                this._visitor = null;
                this._parser  = new CsvInputParser(seeker(_processingChunk, _config), _delimiter, _idType, _header.clone(), _badCollector, _extractors);
                return(_header.entries().Length != 0);
            }
            return(false);
        }
Ejemplo n.º 5
0
 private static void ApplyProperties(InputEntityVisitor entity, object[] properties, long?propertyId)
 {
     if (propertyId != null)
     {
         entity.PropertyId(propertyId.Value);
     }
     for (int i = 0; i < properties.Length; i++)
     {
         entity.Property(( string )properties[i++], properties[i]);
     }
 }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddLabelsToNodeWithoutLabels() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddLabelsToNodeWithoutLabels()
        {
            // GIVEN
            string[]           toAdd = new string[] { "Add1", "Add2" };
            InputEntityVisitor node  = additiveLabels(toAdd).apply(_entity);

            // WHEN
            node(node, "source", 1, 0, "id", NO_PROPERTIES, null, NO_LABELS, null);

            // THEN
            assertArrayEquals(toAdd, _entity.labels());
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideDefaultRelationshipType() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideDefaultRelationshipType()
        {
            // GIVEN
            string             defaultType  = "TYPE";
            InputEntityVisitor relationship = defaultRelationshipType(defaultType).apply(_entity);

            // WHEN
            relationship(relationship, "source", 1, 0, NO_PROPERTIES, null, "start", "end", null, null);

            // THEN
            assertEquals(defaultType, _entity.stringType);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddMissingLabels() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddMissingLabels()
        {
            // GIVEN
            string[]           toAdd = new string[] { "Add1", "Add2" };
            InputEntityVisitor node  = additiveLabels(toAdd).apply(_entity);

            // WHEN
            string[] nodeLabels = new string[] { "SomeOther" };
            node(node, "source", 1, 0, "id", NO_PROPERTIES, null, nodeLabels, null);

            // THEN
            assertEquals(asSet(ArrayUtil.union(toAdd, nodeLabels)), asSet(_entity.labels()));
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotOverrideAlreadySetRelationshipType() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotOverrideAlreadySetRelationshipType()
        {
            // GIVEN
            string             defaultType  = "TYPE";
            InputEntityVisitor relationship = defaultRelationshipType(defaultType).apply(_entity);

            // WHEN
            string customType = "CUSTOM_TYPE";

            relationship(relationship, "source", 1, 0, NO_PROPERTIES, null, "start", "end", customType, null);

            // THEN
            assertEquals(customType, _entity.stringType);
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void node(InputEntityVisitor entity, String sourceDescription, long lineNumber, long position, Object id, Object[] properties, System.Nullable<long> propertyId, String[] labels, System.Nullable<long> labelField) throws java.io.IOException
        private static void Node(InputEntityVisitor entity, string sourceDescription, long lineNumber, long position, object id, object[] properties, long?propertyId, string[] labels, long?labelField)
        {
            ApplyProperties(entity, properties, propertyId);
            entity.Id(id, Group_Fields.Global);
            if (labelField != null)
            {
                entity.LabelField(labelField.Value);
            }
            else
            {
                entity.Labels(labels);
            }
            entity.EndOfEntity();
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotTouchLabelsIfNodeHasLabelFieldSet() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotTouchLabelsIfNodeHasLabelFieldSet()
        {
            // GIVEN
            string[]           toAdd = new string[] { "Add1", "Add2" };
            InputEntityVisitor node  = additiveLabels(toAdd).apply(_entity);

            // WHEN
            long labelField = 123L;

            node(node, "source", 1, 0, "id", NO_PROPERTIES, null, null, labelField);

            // THEN
            assertEquals(0, _entity.labels().Length);
            assertEquals(labelField, _entity.labelField);
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void relationship(InputEntityVisitor entity, String sourceDescription, long lineNumber, long position, Object[] properties, System.Nullable<long> propertyId, Object startNode, Object endNode, String type, System.Nullable<int> typeId) throws java.io.IOException
        private static void Relationship(InputEntityVisitor entity, string sourceDescription, long lineNumber, long position, object[] properties, long?propertyId, object startNode, object endNode, string type, int?typeId)
        {
            ApplyProperties(entity, properties, propertyId);
            entity.StartId(startNode, Group_Fields.Global);
            entity.EndId(endNode, Group_Fields.Global);
            if (typeId != null)
            {
                entity.type(typeId);
            }
            else if (!string.ReferenceEquals(type, null))
            {
                entity.Type(type);
            }
            entity.EndOfEntity();
        }
Ejemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotOverrideAlreadySetRelationshipTypeId() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotOverrideAlreadySetRelationshipTypeId()
        {
            // GIVEN
            string             defaultType  = "TYPE";
            Decorator          decorator    = defaultRelationshipType(defaultType);
            InputEntityVisitor relationship = decorator.apply(_entity);

            // WHEN
            int typeId = 5;

            relationship(relationship, "source", 1, 0, NO_PROPERTIES, null, "start", "end", null, typeId);

            // THEN
            assertTrue(_entity.hasIntType);
            assertEquals(typeId, _entity.intType);
        }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean nextChunk(org.neo4j.csv.reader.Source_Chunk chunk) throws java.io.IOException
        public override bool NextChunk(Source_Chunk chunk)
        {
            InputEntityArray   entities  = new InputEntityArray(_chunkSize);
            InputEntityVisitor decorated = _decorator.apply(entities);
            int cursor = 0;

            for ( ; cursor < _chunkSize && _parser.next(decorated); cursor++)
            {               // just loop through and parse
            }

            if (cursor > 0)
            {
                (( EagerCsvInputChunk )chunk).Initialize(entities.ToArray());
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCramMultipleDecoratorsIntoOne()
        public virtual void ShouldCramMultipleDecoratorsIntoOne()
        {
            // GIVEN
            Decorator decorator1 = spy(new IdentityDecorator());
            Decorator decorator2 = spy(new IdentityDecorator());
            Decorator multi      = decorators(decorator1, decorator2);

            // WHEN
            InputEntityVisitor node = mock(typeof(InputEntityVisitor));

            multi.apply(node);

            // THEN
            InOrder order = inOrder(decorator1, decorator2);

            order.verify(decorator1, times(1)).apply(node);
            order.verify(decorator2, times(1)).apply(node);
            order.verifyNoMoreInteractions();
        }
Ejemplo n.º 16
0
 public InputEntity(InputEntityVisitor @delegate)
 {
     this.@delegate = @delegate;
     Clear();
 }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void replayOnto(InputEntityVisitor visitor) throws java.io.IOException
        public virtual void ReplayOnto(InputEntityVisitor visitor)
        {
            // properties
            if (HasPropertyId)
            {
                visitor.PropertyId(PropertyIdConflict);
            }
            else if (PropertiesConflict.Count > 0)
            {
                int propertyCount = propertyCount();
                for (int i = 0; i < propertyCount; i++)
                {
                    if (HasIntPropertyKeyIds)
                    {
                        visitor.property(( int? )PropertyKey(i), PropertyValue(i));
                    }
                    else
                    {
                        visitor.Property(( string )PropertyKey(i), PropertyValue(i));
                    }
                }
            }

            // id
            if (HasLongId)
            {
                visitor.Id(LongId);
            }
            else if (ObjectId != null)
            {
                visitor.Id(ObjectId, IdGroup);
            }

            // labels
            if (HasLabelField)
            {
                visitor.LabelField(LabelFieldConflict);
            }
            else if (LabelsConflict.Count > 0)
            {
                visitor.Labels(LabelsConflict.ToArray());
            }

            // start id
            if (HasLongStartId)
            {
                visitor.StartId(LongStartId);
            }
            else if (ObjectStartId != null)
            {
                visitor.StartId(ObjectStartId, StartIdGroup);
            }

            // end id
            if (HasLongEndId)
            {
                visitor.EndId(LongEndId);
            }
            else if (ObjectEndId != null)
            {
                visitor.EndId(ObjectEndId, EndIdGroup);
            }

            // type
            if (HasIntType)
            {
                visitor.Type(IntType);
            }
            else if (!string.ReferenceEquals(StringType, null))
            {
                visitor.Type(StringType);
            }

            // all done
            visitor.EndOfEntity();
        }
Ejemplo n.º 18
0
 internal AdditiveLabelsDecorator(InputEntityVisitor actual, string[] labelNamesToAdd) : base(actual)
 {
     this.LabelNamesToAdd = labelNamesToAdd;
     this.SeenLabels      = new bool[labelNamesToAdd.Length];
 }
Ejemplo n.º 19
0
 private void DecorateVisitor(InputEntityVisitor nakedVisitor)
 {
     _visitor         = _decorator.apply(nakedVisitor);
     _previousVisitor = nakedVisitor;
 }
Ejemplo n.º 20
0
 internal RelationshipTypeDecorator(InputEntityVisitor actual, string defaultType) : base(actual)
 {
     this.DefaultType = defaultType;
 }
Ejemplo n.º 21
0
 public InputEntityVisitor_Delegate(InputEntityVisitor actual)
 {
     this.Actual = actual;
 }
Ejemplo n.º 22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean next(org.neo4j.unsafe.impl.batchimport.input.InputEntityVisitor visitor) throws java.io.IOException
        public override bool Next(InputEntityVisitor visitor)
        {
            return(_actual.next(visitor));
        }
Ejemplo n.º 23
0
 protected internal override void VisitRecord(RecordNodeCursor record, InputEntityVisitor visitor)
 {
     visitor.Id(record.EntityReference());
     visitor.LabelField(record.LabelField);
     VisitProperties(record, visitor);
 }
Ejemplo n.º 24
0
 public override InputEntityVisitor Apply(InputEntityVisitor entity)
 {
     return(entity);
 }
Ejemplo n.º 25
0
 protected internal override void VisitRecord(StorageRelationshipScanCursor record, InputEntityVisitor visitor)
 {
     visitor.StartId(record.SourceNodeReference());
     visitor.EndId(record.TargetNodeReference());
     visitor.Type(record.Type());
     VisitProperties(record, visitor);
 }
Ejemplo n.º 26
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: boolean next(org.neo4j.unsafe.impl.batchimport.input.InputEntityVisitor visitor) throws java.io.IOException
        internal virtual bool Next(InputEntityVisitor visitor)
        {
            _lineNumber++;
            int   i     = 0;
            Entry entry = null;

            Entry[] entries = _header.entries();
            try
            {
                bool doContinue = true;
                for (i = 0; i < entries.Length && doContinue; i++)
                {
                    entry = entries[i];
                    if (!_seeker.seek(_mark, _delimiter))
                    {
                        if (i > 0)
                        {
                            throw new UnexpectedEndOfInputException("Near " + _mark);
                        }
                        // We're just at the end
                        return(false);
                    }

                    switch (entry.Type())
                    {
                    case ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                object idValue = entry.Extractor().value();
                                doContinue = visitor.Id(idValue, entry.Group());
                                if (!string.ReferenceEquals(entry.Name(), null))
                                {
                                    doContinue = visitor.Property(entry.Name(), idValue);
                                }
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.Id(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case START_ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                                doContinue = visitor.StartId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                doContinue = visitor.StartId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.StartId(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case END_ID:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            switch (_idType.innerEnumValue)
                            {
                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.STRING:
                                doContinue = visitor.EndId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.INTEGER:
                                doContinue = visitor.EndId(entry.Extractor().value(), entry.Group());
                                break;

                            case Org.Neo4j.@unsafe.Impl.Batchimport.input.csv.IdType.InnerEnum.ACTUAL:
                                doContinue = visitor.EndId(((Extractors.LongExtractor)entry.Extractor()).longValue());
                                break;

                            default:
                                throw new System.ArgumentException(_idType.name());
                            }
                        }
                        break;

                    case TYPE:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            doContinue = visitor.Type(( string )entry.Extractor().value());
                        }
                        break;

                    case PROPERTY:
                        if (_seeker.tryExtract(_mark, entry.Extractor(), entry.OptionalParameter()))
                        {
                            // TODO since PropertyStore#encodeValue takes Object there's no point splitting up
                            // into different primitive types
                            object value = entry.Extractor().value();
                            if (!IsEmptyArray(value))
                            {
                                doContinue = visitor.Property(entry.Name(), value);
                            }
                        }
                        break;

                    case LABEL:
                        if (_seeker.tryExtract(_mark, entry.Extractor()))
                        {
                            object labelsValue = entry.Extractor().value();
                            if (labelsValue.GetType().IsArray)
                            {
                                doContinue = visitor.Labels(( string[] )labelsValue);
                            }
                            else
                            {
                                doContinue = visitor.Labels(new string[] { ( string )labelsValue });
                            }
                        }
                        break;

                    case IGNORE:
                        break;

                    default:
                        throw new System.ArgumentException(entry.Type().ToString());
                    }

                    if (_mark.EndOfLine)
                    {
                        // We're at the end of the line, break and return an entity with what we have.
                        break;
                    }
                }

                while (!_mark.EndOfLine)
                {
                    _seeker.seek(_mark, _delimiter);
                    if (doContinue)
                    {
                        _seeker.tryExtract(_mark, _stringExtractor, entry.OptionalParameter());
                        _badCollector.collectExtraColumns(_seeker.sourceDescription(), _lineNumber, _stringExtractor.value());
                    }
                }
                visitor.EndOfEntity();
                return(true);
            }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final RuntimeException e)
            catch (Exception e)
            {
                string stringValue = null;
                try
                {
                    Extractors extractors = new Extractors('?');
                    if (_seeker.tryExtract(_mark, extractors.String(), entry.OptionalParameter()))
                    {
                        stringValue = extractors.String().value();
                    }
                }
                catch (Exception)
                {                         // OK
                }

                string message = format("ERROR in input" + "%n  data source: %s" + "%n  in field: %s" + "%n  for header: %s" + "%n  raw field value: %s" + "%n  original error: %s", _seeker, entry + ":" + (i + 1), _header, !string.ReferenceEquals(stringValue, null) ? stringValue : "??", e.Message);

                if (e is InputException)
                {
                    throw Exceptions.withMessage(e, message);
                }
                throw new InputException(message, e);
            }
        }