Example #1
0
    def _get_java_object(self):
        from maprdb.connection import Connection
        maprdb = Connection.get_instance().MapRDB
        java_document = maprdb.newDocument()

        for k,v in self.items():
            java_document.set(python_to_java_cast(k),python_to_java_cast(v))

        return java_document
Example #2
0
    def _get_java_object(self):
        from maprdb.connection import Connection
        maprdb = Connection.get_instance().MapRDB
        java_document = maprdb.newDocument()

        for k, v in self.items():
            java_document.set(python_to_java_cast(k), python_to_java_cast(v))

        return java_document
Example #3
0
    def find_by_condition(self, condition, columns=None):
        """
        Returns a generator that iterates over all documents that satisfy the passed condition.

        :param condition: maprdb.document.Condition class instance
        :param columns: list of strings, which
        specifies certain columns to select from the returned document.
        :returns: generator, which returns maprdb.document.Document class instances.
        """
        document_stream = self.java_table.find(
            python_to_java_cast(condition),
            columns) if columns else self.java_table.find(
                python_to_java_cast(condition))
        return self._find_by_java_document_stream(document_stream)
Example #4
0
    def insert_or_replace(self, doc, key=None):
        """
        Insert the document in the database. If the document already exists, it gets replaced.

        :param doc: maprdb.document.Document class instance, that should have an _id field. If not present an exception should be raised.
        If the user specific a key, it will be added to the document automatically as _id field, if the document contains an _id and a key is passed, an maprdb.utils.MapRDBError will be raised.
        :param key: string value, which is _id of the record to find.
        """
        doc = self._fill_document_key(doc, key=key)
        self.java_table.insertOrReplace(python_to_java_cast(doc))
Example #5
0
    def insert_or_replace(self, doc, key=None):
        """
        Insert the document in the database. If the document already exists, it gets replaced.

        :param doc: maprdb.document.Document class instance, that should have an _id field. If not present an exception should be raised.
        If the user specific a key, it will be added to the document automatically as _id field, if the document contains an _id and a key is passed, an maprdb.utils.MapRDBError will be raised.
        :param key: string value, which is _id of the record to find.
        """
        doc = self._fill_document_key(doc, key=key)
        self.java_table.insertOrReplace(python_to_java_cast(doc))
Example #6
0
    def append(self, field_name, value):
        """
        Appends the specified value to the specified field.

        :param field_name: string value, which is a name of field to set.
        :param value: a list or string value to append.
        :return: maprdb.mutation.Mutation resulting instance
        """
        self.java_mutation = self.java_mutation.append(
            field_name, python_to_java_cast(value))
        return self
Example #7
0
    def set_or_replace(self, field_name, value):
        """
        Sets the value of a field conditionally. If a previous value exists, it is overwritten.

        :param field_name: string value, which is a name of field to set.
        :param value: a list, dictionary, numeric or date value to set for the field.
        :return: maprdb.mutation.Mutation resulting instance
        """
        self.java_mutation = self.java_mutation.setOrReplace(
            field_name, python_to_java_cast(value))
        return self
Example #8
0
    def set(self, field_name, value):
        """
        Sets the value of a field if no previous value exists.

        :param field_name: string value, which is a name of field to set.
        :param value: a list, dictionary, numeric or date value to set for the field.
        :return: maprdb.mutation.Mutation resulting instance
        """
        self.java_mutation = self.java_mutation.set(field_name,
                                                    python_to_java_cast(value))
        return self
Example #9
0
    def find_by_condition(self, condition, columns=None):
        """
        Returns a generator that iterates over all documents that satisfy the passed condition.

        :param condition: maprdb.document.Condition class instance
        :param columns: list of strings, which
        specifies certain columns to select from the returned document.
        :returns: generator, which returns maprdb.document.Document class instances.
        """
        document_stream = self.java_table.find(python_to_java_cast(condition), columns) if columns else self.java_table.find(python_to_java_cast(condition))
        return self._find_by_java_document_stream(document_stream)
Example #10
0
    def update(self, key, mutation):
        """
        Performs the requested mutation on the document with the specified key(s).

        :param key: string value or list of strings, if it is a list,
        then the same mutation will be applied to each document specified by the elements of the list.
        :param mutation: maprdb.mutation.Mutation class instance, which is a mutation to perform.
        """
        keys_list = key if isinstance(key, (list, tuple)) else [key]

        for k in keys_list:
            self.java_table.update(k, python_to_java_cast(mutation))
Example #11
0
    def update(self, key, mutation):
        """
        Performs the requested mutation on the document with the specified key(s).

        :param key: string value or list of strings, if it is a list,
        then the same mutation will be applied to each document specified by the elements of the list.
        :param mutation: maprdb.mutation.Mutation class instance, which is a mutation to perform.
        """
        keys_list = key if isinstance(key, (list,tuple)) else [key]

        for k in keys_list:
            self.java_table.update(k, python_to_java_cast(mutation))
Example #12
0
 def _is(self, field, condition, value):
     value = python_to_java_cast(value)
     self.java_condition = self.java_condition.is_(field, condition, value)
     return self
Example #13
0
 def _is(self, field, condition, value):
     value = python_to_java_cast(value)
     self.java_condition = self.java_condition.is_(field, condition, value)
     return self