Every judicial officer shall have power:
1.To preserve and enforce order in his immediate presence, and in proceedings before him, when he is engaged in the performance of official duty;
2.To compel obedience to his lawful orders as provided in this Code;
3.To compel the attendance of persons to testify in a proceeding before him, in the cases and manner provided in this Code;
4.To administer oaths to persons in a
proceeding pending before him, and in all other cases where it may be necessary in the exercise of his powers and duties.