Ejemplo n.º 1
0
        public virtual void TestCreateIndexAtRuntime()
        {
            IStoredField field = StoredField();

            Assert.IsFalse(field.HasIndex());
            field.CreateIndex();
            Assert.IsTrue(field.HasIndex());
            AssertQuery();
            field.CreateIndex();
        }
Ejemplo n.º 2
0
        private void AssertIndexed(Type clazz, bool expected)
        {
            IStoredClass storedClass = FileSession().StoredClass(clazz);
            IStoredField storedField = storedClass.StoredField("_id", typeof(int));

            Assert.AreEqual(expected, storedField.HasIndex());
        }
Ejemplo n.º 3
0
        public virtual void TestDropIndex()
        {
            IStoredField field = StoredField();

            field.CreateIndex();
            AssertQuery();
            field.DropIndex();
            Assert.IsFalse(field.HasIndex());
            AssertQuery();
        }
Ejemplo n.º 4
0
        public Db4oField(IStoredField storedField)
        {
            this.storedField = storedField;
            internalName = storedField.GetName();
            name = AutomaticPropertyUtils.TryParseName(internalName);
            IsIndexed = storedField.HasIndex();

            IReflectClass type = storedField.GetStoredType();
            if(type!=null)
                DataType = type.ToString();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            using (IObjectContainer container = Db4oEmbedded.OpenFile("database.db4o"))
            {
                container.Store(new Person("Johnson", "Roman", 42));
                container.Store(new Person("Miller", "John", 21));

                // #example: All stored classes
                // Get the information about all stored classes.
                IStoredClass[] classesInDB = container.Ext().StoredClasses();
                foreach (IStoredClass storedClass in classesInDB)
                {
                    Console.WriteLine(storedClass.GetName());
                }

                // Information for a certain class
                IStoredClass metaInfo = container.Ext().StoredClass(typeof(Person));
                // #end example

                // #example: Accessing stored fields
                IStoredClass metaInfoForPerson = container.Ext().StoredClass(typeof(Person));
                // Access all existing fields
                foreach (IStoredField field in metaInfoForPerson.GetStoredFields())
                {
                    Console.WriteLine("Field: " + field.GetName());
                }
                // Accessing the field 'name' of any type.
                IStoredField nameField = metaInfoForPerson.StoredField("name", null);
                // Accessing the string field 'name'. Important if this field had another time in previous
                // versions of the class model
                IStoredField ageField = metaInfoForPerson.StoredField("age", typeof(int));

                // Check if the field is indexed
                bool isAgeFieldIndexed = ageField.HasIndex();

                // Get the type of the field
                string fieldType = ageField.GetStoredType().GetName();
                // #end example

                // #example: Access via meta data
                IStoredClass metaForPerson = container.Ext().StoredClass(typeof(Person));
                IStoredField metaNameField = metaForPerson.StoredField("name", null);

                IList <Person> persons = container.Query <Person>();
                foreach (Person person in persons)
                {
                    string name = (string)metaNameField.Get(person);
                    Console.WriteLine("Name is " + name);
                }
                // #end example
            }
        }
Ejemplo n.º 6
0
 private void AssertHasIndexInfo(IObjectContainer db)
 {
     IStoredClass[] scArray = db.Ext().StoredClasses();
     for (int scIndex = 0; scIndex < scArray.Length; ++scIndex)
     {
         IStoredClass sc = scArray[scIndex];
         if (!sc.GetName().Equals(typeof(KnownClassesIndexTestCase.WithIndex).FullName))
         {
             continue;
         }
         IStoredField[] sfArray = sc.GetStoredFields();
         for (int sfIndex = 0; sfIndex < sfArray.Length; ++sfIndex)
         {
             IStoredField sf = sfArray[sfIndex];
             if (sf.HasIndex())
             {
                 return;
             }
         }
         Assert.Fail("no index found");
     }
 }
Ejemplo n.º 7
0
        private void AssertStoredField(Type objectClass, string fieldName, object expectedFieldValue
                                       , Type expectedFieldType, bool hasIndex, bool isArray)
        {
            IStoredClass storedClass = StoredClass(objectClass);

            IStoredField[] storedFields = storedClass.GetStoredFields();
            Assert.AreEqual(1, storedFields.Length);
            IStoredField storedField = storedFields[0];

            Assert.AreEqual(fieldName, storedField.GetName());
            IStoredField storedFieldByName = storedClass.StoredField(fieldName, expectedFieldType
                                                                     );

            Assert.AreEqual(storedField, storedFieldByName);
            object item = RetrieveOnlyInstance(objectClass);

            Assert.AreEqual(expectedFieldValue, storedField.Get(item));
            IReflectClass fieldType = storedField.GetStoredType();

            Assert.AreEqual(Reflector().ForClass(expectedFieldType), fieldType);
            Assert.AreEqual(isArray, storedField.IsArray());
            if (IsMultiSession())
            {
                return;
            }
            Assert.AreEqual(hasIndex, storedField.HasIndex());
            // FIXME: test rename
            if (!hasIndex)
            {
                Assert.Expect(typeof(Exception), new _ICodeBlock_113(storedField));
            }
            else
            {
                IntByRef count = new IntByRef();
                storedField.TraverseValues(new _IVisitor4_123(count, expectedFieldValue));
                Assert.AreEqual(1, count.value);
            }
        }
Ejemplo n.º 8
0
        public bool IsIndexed()
        {
            try
            {
                IStoredClass storedClass = objectContainer.Ext().StoredClass(m_classname);
                if (null == storedClass)
                {
                    return(false);
                }

                IStoredField field = DataLayerCommon.GetDeclaredStoredFieldInHeirarchy(storedClass, m_fieldname);
                if (field == null)
                {
                    return(false);
                }

                return(field.HasIndex());
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
                return(false);
            }
        }
Ejemplo n.º 9
0
 private static IndexingState HasIndex(IStoredField sf)
 {
     return(sf.HasIndex() ? IndexingState.Indexed : IndexingState.NotIndexed);
 }
Ejemplo n.º 10
0
 private static IndexingState HasIndex(IStoredField sf)
 {
     return sf.HasIndex() ? IndexingState.Indexed : IndexingState.NotIndexed;
 }