Generic read file into database method.

        Args:
            directory (str): Directory containing the file to be read.
            filename (str): Name of the file which will be read (e.g.: 'example.prj').
            session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database.
            spatial (bool, optional): If True, spatially enabled objects will be read in as PostGIS spatial objects.
                Defaults to False.
            spatialReferenceID (int, optional): Integer id of spatial reference system for the model. Required if
                spatial is True. Defaults to srid 4236.
            replaceParamFile (:class:`gsshapy.orm.ReplaceParamFile`, optional): ReplaceParamFile instance. Use this if
                the file you are reading contains replacement parameters.

def read(self, directory, filename, session, spatial=False,
             spatialReferenceID=4236, replaceParamFile=None, **kwargs):
        """
        Generic read file into database method.

        Args:
            directory (str): Directory containing the file to be read.
            filename (str): Name of the file which will be read (e.g.: 'example.prj').
            session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database.
            spatial (bool, optional): If True, spatially enabled objects will be read in as PostGIS spatial objects.
                Defaults to False.
            spatialReferenceID (int, optional): Integer id of spatial reference system for the model. Required if
                spatial is True. Defaults to srid 4236.
            replaceParamFile (:class:`gsshapy.orm.ReplaceParamFile`, optional): ReplaceParamFile instance. Use this if
                the file you are reading contains replacement parameters.
        """

        # Read parameter derivatives
        path = os.path.join(directory, filename)
        filename_split = filename.split('.')
        name = filename_split[0]

        # Default file extension
        extension = ''

        if len(filename_split) >= 2:
            extension = filename_split[-1]

        if os.path.isfile(path):
            # Add self to session
            session.add(self)

            # Read
            self._read(directory, filename, session, path, name, extension,
                       spatial, spatialReferenceID, replaceParamFile, **kwargs)

            # Commit to database
            self._commit(session, self.COMMIT_ERROR_MESSAGE)
        else:
            # Rollback the session if the file doesn't exist
            session.rollback()

            # Print warning
            log.warning('Could not find file named {0}. File not read.'.format(filename))