Section 17. A justice, clerk or assistant clerk of a district court shall not be retained or employed as an attorney in an action, complaint or proceeding pending in the court to which he is appointed, or which has been examined or tried therein; and a special justice shall not be so retained or employed in any case in which he acts or has acted as justice. No justice or special justice shall hear or try any case or proceeding in any court of the district court department, if he shall know that a partner or office associate of his has been directly or indirectly retained or employed as an attorney in such case or proceeding. No special justice shall practice in a criminal session of any court in the commonwealth nor shall he practice at all in the court, or predecessor district court, to which he is appointed.