AspectJ从另一个特定方法切入方法

时间:2015-06-22 09:08:54

标签: java aspectj

我有一个类,它创建一个带有一些控件的应用程序窗口(代码如下,windowAs.java文件)。在“initialize”类中创建所有元素。这些只是应用程序中许多其他按钮的几个按钮,并且所有按钮都具有“actionPerformed”方法,后面有非常相似的逻辑。 在一个单独的方法中,我放置了我想要包含在方面代码中的那些按钮的初始化。所有这些“特殊”按钮都有一些共同点:使用两个参数调用方法tableCreation(String header [],String query)。如何创建与这些按钮的定义相匹配的切入点?

databaseConnection.java

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;

class databaseConnectionAs {

    String query = null;

    static Connection conn = null;
    static Statement statement = null;
    ResultSet resultSet = null;

    String url = null; 
    String user = null;
    String password = null; 

    List<List<String>> test_table = new ArrayList<List<String>>();

    void execute_update (String query_arg) {
        if(statement != null) {
            try {
                query = query_arg;
                statement.executeUpdate(query);
            } catch (SQLException e) {
                System.out.println("Unable to execute update: " + e.getMessage());
            }
        }
    }

    void execute_query (String query_arg) {
        if(statement != null) {
            try {
                query = query_arg;
                resultSet = statement.executeQuery(query);
            } catch (SQLException e) {
                System.out.println("Unable to create statement: " + e.getMessage()); 
            }
        }

       try {
            if (!resultSet.isBeforeFirst()) {
                System.out.println("resultSet empty - no data");
            }
        } catch (SQLException e) {
            System.out.println("Error: " + e.getMessage());
        }


        int columnCount=0;
        try {
            test_table.clear();
            ResultSetMetaData metadata = this.resultSet.getMetaData();
            columnCount = metadata.getColumnCount();
        } catch (SQLException e) {
            System.out.println("Error: " + e.getMessage());
        }

        if (this.resultSet != null) {
            try {
                int i = 0; // row counter 
                while (this.resultSet.next()) {
                    this.test_table.add(new ArrayList<String>()); // creates new line  
                    for (int j=1; j<columnCount+1; j++) { // counter for adding a new field in the row  
                        this.test_table.get(i).add(this.resultSet.getString(j)); // adding a new field in the row  
                    }
                    i++;
                }
            } catch (SQLException e) {
                System.out.println("Unable to iterate over resultset: " + e.getMessage());
            }
        }
    }

    void print_results () {

        for (int i=0; i<this.test_table.size(); i++) { // from zero to number of records (rows) in a table  
            for (int j=0; j<this.test_table.get(i).size(); j++) { // from zero to number of columns  
                System.out.print(this.test_table.get(i).get(j) + " ");
            } 
            System.out.println("");
        } 
    }

}

windowAs.java

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import javax.swing.ButtonGroup;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JPanel;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class windowAs {

    private JFrame first_frame;
    private JTable first_table;
    private JScrollPane first_scrollpane;

    private MyButton btn_student_list;
    private MyButton btn_subjects_list;
    private MyButton btn_passed_by_students;
    private MyButton btn_passed_by_subjects;

    private JButton btn_insert;
    private JTextField txt_id;
    private JTextField txt_name;
    private JTextField txt_surname;
    private JTextField txt_year;
    private JTextField txt_error;

    // starting the app 
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    windowAs window = new windowAs();
                    window.first_frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    // creating the app  
    public windowAs() {
        initialize();
    }

    // initializaion of frame contents  
    private void initialize() {
        first_frame = new JFrame();
        first_frame.setBounds(100, 100, 800, 324);
        first_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        first_frame.getContentPane().setLayout(null);
        first_frame.setLocationRelativeTo(null);
        first_frame.setResizable(false);




        // adding the STUDENT LIST button 
        btn_student_list = new MyButton("Students list");
        btn_student_list.setFont(new Font("Tahoma", Font.PLAIN, 10));
        btn_student_list.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String header[] = new String[] {"ID", "NAME", "SURNAME", "GENDER", "YEAR"};
                String query = "SELECT studenti.student_id, studenti.student_ime, studenti.student_prezime, spol.spol_naziv, studenti.student_godina_studija FROM studenti JOIN spol ON studenti.student_spol=spol.spol_id ";
                tableCreation(header, query);
            }
        });
        btn_student_list.setBounds(10, 11, 150, 40);
        first_frame.getContentPane().add(btn_student_list);
        // end 

        // adding the SUBJECTS LIST button  
        btn_subjects_list = new MyButton("Subjects list");
        btn_subjects_list.setFont(new Font("Tahoma", Font.PLAIN, 10));
        btn_subjects_list.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String header[] = new String[] {"ID", "NAME", "YEAR"};
                String query = "SELECT * FROM kolegiji";
                tableCreation(header, query);
            }
        });
        btn_subjects_list.setBounds(170, 11, 150, 40);
        first_frame.getContentPane().add(btn_subjects_list);
        // end 

        // adding the PASSED BY STUDENTS button  
        btn_passed_by_students = new MyButton("Passed by students");
        btn_passed_by_students.setFont(new Font("Tahoma", Font.PLAIN, 10));
        btn_passed_by_students.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String header[] = new String[] {"ID", "NAME", "SURNAME", "SUBJECT ID", "NAME", "MARK"};
                String query = "SELECT studenti.student_id, studenti.student_ime, studenti.student_prezime, kolegiji.kolegij_id, kolegiji.kolegij_naziv, polozeni_kolegiji.ocjena FROM studenti JOIN polozeni_kolegiji ON studenti.student_id=polozeni_kolegiji.student_id JOIN kolegiji ON polozeni_kolegiji.kolegij_id=kolegiji.kolegij_id;";
                tableCreation(header, query);
            }
        });
        btn_passed_by_students.setBounds(10, 62, 150, 40);
        first_frame.getContentPane().add(btn_passed_by_students);
        // end  

        // adding the PASSED BY SUBJECT NAME button 
        btn_passed_by_subjects = new MyButton("Passed by subjects");
        btn_passed_by_subjects.setFont(new Font("Tahoma", Font.PLAIN, 10));
        btn_passed_by_subjects.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String header[] = new String[] {"JMBAG", "IME", "PREZIME", "ID KOLEGIJA", "NAZIV", "OCJENA"};
                String query = "SELECT studenti.student_id, studenti.student_ime, studenti.student_prezime, kolegiji.kolegij_id, kolegiji.kolegij_naziv, polozeni_kolegiji.ocjena FROM studenti JOIN polozeni_kolegiji ON studenti.student_id=polozeni_kolegiji.student_id JOIN kolegiji ON polozeni_kolegiji.kolegij_id=kolegiji.kolegij_id ORDER BY kolegiji.kolegij_id;";
                tableCreation(header, query);
            }
        });
        btn_passed_by_subjects.setBounds(170, 62, 150, 40);
        first_frame.getContentPane().add(btn_passed_by_subjects);
        // end 




        first_scrollpane = new JScrollPane();
        first_scrollpane.setBounds(330, 11, 454, 243);
        first_frame.getContentPane().add(first_scrollpane);

        first_table = new JTable();

        DefaultTableModel model = new DefaultTableModel(0, 0);
        String header[] = new String[] {"LIST HERE"};
        model.setColumnIdentifiers(header);
        first_table.setModel(model);

        first_scrollpane.setViewportView(first_table);

        ButtonGroup genders = new ButtonGroup();

        JPanel panel = new JPanel();
        panel.setBounds(10, 113, 310, 141);
        first_frame.getContentPane().add(panel);
        panel.setLayout(null);

        btn_insert = new JButton("INSERT");
        btn_insert.setFont(new Font("Tahoma", Font.PLAIN, 11));
        btn_insert.setBounds(199, 92, 111, 39);
        panel.add(btn_insert);

        JLabel lbl_id = new JLabel("id");
        lbl_id.setBounds(0, 17, 60, 14);
        panel.add(lbl_id);

        JLabel lbl_name = new JLabel("Name");
        lbl_name.setBounds(0, 42, 60, 14);
        panel.add(lbl_name);

        JLabel lbl_surname = new JLabel("Surname");
        lbl_surname.setBounds(0, 67, 60, 14);
        panel.add(lbl_surname);

        JLabel lbl_gender = new JLabel("Gender");
        lbl_gender.setBounds(0, 92, 60, 14);
        panel.add(lbl_gender);

        JLabel lbl_year = new JLabel("Year");
        lbl_year.setBounds(0, 117, 60, 14);
        panel.add(lbl_year);

        txt_id = new JTextField();
        txt_id.setBounds(69, 11, 241, 20);
        panel.add(txt_id);
        txt_id.setColumns(10);

        txt_name = new JTextField();
        txt_name.setBounds(69, 36, 241, 20);
        panel.add(txt_name);
        txt_name.setColumns(10);

        txt_surname = new JTextField();
        txt_surname.setBounds(69, 61, 241, 20);
        panel.add(txt_surname);
        txt_surname.setColumns(10);

        JRadioButton rdbtn_m = new JRadioButton("M");
        rdbtn_m.setBounds(69, 88, 50, 23);
        panel.add(rdbtn_m);
        genders.add(rdbtn_m);

        JRadioButton rdbtn_f = new JRadioButton("F");
        rdbtn_f.setBounds(140, 88, 50, 23);
        panel.add(rdbtn_f);
        genders.add(rdbtn_f);

        txt_year = new JTextField();
        txt_year.setBounds(69, 111, 120, 20);
        panel.add(txt_year);
        txt_year.setColumns(10);

        btn_insert.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    int id = Integer.parseInt(txt_id.getText());
                    String name = txt_name.getText();
                    String surname = txt_surname.getText(); 
                    int year = Integer.parseInt(txt_year.getText());
                    int gender = 0;
                    if (rdbtn_m.isSelected()) {
                        gender = 1;
                    }
                    else if (rdbtn_f.isSelected()) {
                        gender = 2;
                    }

                    databaseConnectionAs conn = new databaseConnectionAs();
                    String query = "INSERT INTO studenti VALUES ('" + id + "', '" + name + "', '" + surname + "', '" + gender + "', '" + year + "');";
                    conn.execute_update(query);

                } catch (Exception er) {
                    txt_error.setVisible(true);
                    txt_error.setEditable(false);
                    txt_error.setText("Error: " + er.getMessage());
                }
            }
        });

        txt_error = new JTextField();
        txt_error.setBounds(10, 265, 774, 23);
        first_frame.getContentPane().add(txt_error);
        txt_error.setColumns(10);
        txt_error.setVisible(false);

    }


    public void tableCreation (String header[], String query) {
        databaseConnectionAs conn = new databaseConnectionAs();

        DefaultTableModel model = new DefaultTableModel(0, 0);
        model.setColumnIdentifiers(header);
        first_table.setModel(model);

        conn.execute_query(query);
        for (int i=0; i<conn.test_table.size(); i++) {
            model.addRow(new Object[]{});
            for (int j=0; j<conn.test_table.get(i).size(); j++) {
                model.setValueAt(conn.test_table.get(i).get(j), i, j);
            }
        }
    }

}

MyButton.java

import javax.swing.JButton;

public class MyButton extends JButton {

    private static final long serialVersionUID = 1L;

    public MyButton(String string) {
        setText(string);
    }

}

databaseAspect.aj

import java.sql.DriverManager;
import java.sql.SQLException;

public aspect databaseAspect {

    pointcut myConnection() : execution(* execute_query(..)) || execution(* execute_update(..));

    // advice to open the connection and statement creation before accessing the database  
    before() : myConnection() {
        String url = "jdbc:mysql://localhost/testbaza"; 
        String user = "testkorisnik";
        String password = "testlozinka";

        try {
            databaseConnectionAs.conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            System.out.println("\nUnable to connect to database: " + e.getMessage());
        }

        if (databaseConnectionAs.conn != null) {
            try {
                databaseConnectionAs.statement = databaseConnectionAs.conn.createStatement();
            } catch (SQLException e) {
                System.out.println("Unable to create statement: " + e.getMessage());
            }
        }
    }

    // advice to close the connection after finishing the query  
    after() : myConnection() {
        try {
            databaseConnectionAs.conn.close();
        } catch (SQLException e) {
            System.out.println("\nError while disconnecting the database: " + e.getMessage());
        }
    }


    pointcut click() : execution(* actionPerformed(..)) && within(MyButton..*); 

    after() : click() {
        System.out.println("You did it!");
    }


}

testbaza.sql

-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jul 15, 2015 at 01:16 AM
-- Server version: 5.6.21
-- PHP Version: 5.6.3

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `testbaza`
--

-- --------------------------------------------------------

--
-- Table structure for table `kolegiji`
--

CREATE TABLE IF NOT EXISTS `kolegiji` (
`kolegij_id` int(5) NOT NULL,
  `kolegij_naziv` varchar(50) NOT NULL,
  `kolegij_godina` int(1) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `kolegiji`
--

INSERT INTO `kolegiji` (`kolegij_id`, `kolegij_naziv`, `kolegij_godina`) VALUES
(1, 'Financijska Matematika', 1),
(2, 'Marketing', 1),
(3, 'Marketing', 1),
(4, 'Statistika', 1),
(5, 'Trgovacko Pravo', 1),
(6, 'Informaticko Pravo', 1),
(7, 'Ured I Uredsko Poslovanje', 1),
(8, 'Baze Podataka', 2),
(9, 'Informatika u Primjeni', 2),
(10, 'Kvantitativni Menadzment', 2),
(11, 'Matematicke Metode za Poslovne Analize', 2),
(12, 'Poslovni Informacijski Sustavi Drzvane Uprave', 2),
(13, 'Elektronicko Poslovanje', 2),
(14, 'Financije Malih i Srednjih Poduzeca', 1),
(15, 'IS Malih i Srednjih Poduzeca', 1),
(16, 'Kontroling i Politika Kvalitete', 2),
(17, 'Medunarodna Trgovina', 1),
(18, 'Transport Spedicija i Osiguranje', 1),
(19, 'Izgradnja Web Aplikacija', 3),
(20, 'Modeliranje Poslovnih Pravila', 3),
(21, 'Multimedijski Sustavi', 3),
(22, 'Napredno Programiranje', 3),
(23, 'Poslovno Planiranje', 3),
(24, 'Primjena Mreznih Servisa', 3),
(25, 'Programiranje', 3),
(26, 'Sigurnost Informacijskih Sustava', 3),
(27, 'Upravljanje Informatickim Uslugama', 3),
(28, 'Engleski 1', 1),
(29, 'Informatika 1', 1),
(30, 'Engleski 2', 2),
(31, 'Informatika 2', 2),
(32, 'Obrada Teksta i Slike', 1),
(33, 'Organizacija', 1),
(34, 'Osnove Ekonomije', 1),
(35, 'Poslovno Komuniciranje', 1),
(36, 'Statistika', 1),
(37, 'Matematika 1', 1),
(38, 'Racunovodstvo', 2),
(39, 'Teorija Sustava', 2),
(40, 'Marketing', 3),
(41, 'Ergonomija', 4),
(42, 'IS u Potpori Upravljanju i Odlucivanju', 4),
(43, 'Razvoj IS', 4),
(44, 'Ekonomika', 4),
(45, 'Dinamicke Web Aplikacije', 4),
(46, 'Management Kvalitete', 4),
(47, 'Softversko Inzenjerstvo', 4),
(48, 'Teorija Informacija', 4),
(49, 'ICT i Drustvo', 5),
(50, 'Informacijski Management', 5),
(51, 'Modeliranje i Simulacija', 5),
(52, 'Poduzetnistvo i Gospodarstvo', 5);

-- --------------------------------------------------------

--
-- Table structure for table `polozeni_kolegiji`
--

CREATE TABLE IF NOT EXISTS `polozeni_kolegiji` (
  `student_id` bigint(10) NOT NULL,
  `kolegij_id` int(5) NOT NULL,
  `ocjena` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `polozeni_kolegiji`
--

INSERT INTO `polozeni_kolegiji` (`student_id`, `kolegij_id`, `ocjena`) VALUES
(1394984532, 1, 3),
(1394984532, 2, 5),
(1394984532, 3, 2),
(1394984532, 4, 2),
(1394984532, 5, 5),
(1394984532, 6, 3),
(1394984532, 7, 3),
(1394984532, 14, 5),
(1394984532, 15, 4),
(1394984532, 17, 4),
(1394984532, 18, 2),
(1473419155, 1, 2),
(1473419155, 2, 4),
(1473419155, 3, 3),
(1473419155, 4, 4),
(1473419155, 5, 2),
(1473419155, 6, 3),
(1473419155, 7, 3),
(1473419155, 8, 4),
(1473419155, 9, 2),
(1473419155, 10, 3),
(1473419155, 11, 3),
(1473419155, 12, 5),
(1473419155, 13, 5),
(1473419155, 14, 3),
(1473419155, 15, 3),
(1473419155, 16, 4),
(1473419155, 17, 3),
(1473419155, 18, 5),
(1473419155, 19, 5),
(1473419155, 20, 2),
(1473419155, 21, 4),
(1473419155, 22, 2),
(1473419155, 23, 4),
(1473419155, 24, 3),
(1473419155, 25, 5),
(1473419155, 26, 5),
(1473419155, 27, 4),
(1473419155, 28, 3),
(1473419155, 29, 2),
(1473419155, 30, 2),
(1473419155, 31, 2),
(1473419155, 32, 2),
(1473419155, 33, 5),
(1473419155, 34, 3),
(1473419155, 35, 5),
(1473419155, 36, 5),
(1473419155, 37, 4),
(1473419155, 38, 4),
(1473419155, 39, 5),
(1473419155, 40, 2),
(1876743912, 1, 5),
(1876743912, 2, 4),
(1876743912, 3, 4),
(1876743912, 4, 4),
(1876743912, 5, 2),
(1876743912, 6, 5),
(1876743912, 7, 2),
(1876743912, 14, 4),
(1876743912, 15, 5),
(1876743912, 17, 5),
(1876743912, 18, 5),
(1876743912, 28, 5),
(1876743912, 29, 5),
(1876743912, 32, 5),
(1876743912, 33, 4),
(1876743912, 34, 5),
(1876743912, 35, 5),
(1876743912, 36, 4),
(1876743912, 37, 5),
(2131875260, 1, 5),
(2131875260, 2, 2),
(2131875260, 3, 3),
(2131875260, 4, 2),
(2131875260, 5, 4),
(2131875260, 6, 3),
(2131875260, 7, 4),
(2131875260, 14, 5),
(2131875260, 15, 4),
(2131875260, 17, 2),
(2131875260, 18, 5),
(2131875260, 28, 4),
(2131875260, 29, 4),
(2131875260, 32, 5),
(2131875260, 33, 4),
(2131875260, 34, 3),
(2131875260, 35, 3),
(2131875260, 36, 4),
(2131875260, 37, 3),
(2517879602, 1, 2),
(2517879602, 2, 3),
(2517879602, 3, 3),
(2517879602, 4, 3),
(2517879602, 5, 4),
(2517879602, 6, 2),
(2517879602, 7, 2),
(2517879602, 8, 2),
(2517879602, 9, 2),
(2517879602, 10, 2),
(2517879602, 11, 4),
(2517879602, 12, 5),
(2517879602, 13, 4),
(2517879602, 14, 3),
(2517879602, 15, 5),
(2517879602, 16, 5),
(2517879602, 17, 2),
(2517879602, 18, 4),
(2517879602, 28, 3),
(2517879602, 29, 2),
(2517879602, 30, 5),
(2517879602, 31, 5),
(2517879602, 32, 2),
(2517879602, 33, 4),
(2517879602, 34, 5),
(2517879602, 35, 4),
(2517879602, 36, 2),
(2517879602, 37, 3),
(2517879602, 38, 5),
(2517879602, 39, 2),
(2936048095, 1, 2),
(2936048095, 2, 5),
(2936048095, 3, 3),
(2936048095, 4, 5),
(2936048095, 5, 4),
(2936048095, 6, 4),
(2936048095, 7, 2),
(2936048095, 14, 5),
(2936048095, 15, 5),
(2936048095, 17, 3),
(2936048095, 18, 3),
(2936048095, 28, 5),
(2936048095, 29, 2),
(2936048095, 32, 5),
(2936048095, 33, 5),
(2936048095, 34, 3),
(2936048095, 35, 4),
(2936048095, 36, 5),
(2936048095, 37, 3),
(3736706852, 1, 5),
(3736706852, 2, 4),
(3736706852, 3, 2),
(3736706852, 4, 2),
(3736706852, 5, 4),
(3736706852, 6, 3),
(3736706852, 7, 4),
(3736706852, 8, 4),
(3736706852, 9, 5),
(3736706852, 10, 2),
(3736706852, 11, 2),
(3736706852, 12, 4),
(3736706852, 13, 2),
(3736706852, 14, 3),
(3736706852, 15, 4),
(3736706852, 16, 4),
(3736706852, 17, 3),
(3736706852, 18, 5),
(3736706852, 19, 2),
(3736706852, 20, 5),
(3736706852, 21, 3),
(3736706852, 22, 5),
(3736706852, 23, 4),
(3736706852, 24, 4),
(3736706852, 25, 3),
(3736706852, 26, 5),
(3736706852, 27, 5),
(3736706852, 28, 3),
(3736706852, 29, 2),
(3736706852, 30, 4),
(3736706852, 31, 3),
(3736706852, 32, 3),
(3736706852, 33, 4),
(3736706852, 34, 3),
(3736706852, 35, 5),
(3736706852, 36, 3),
(3736706852, 37, 3),
(3736706852, 38, 5),
(3736706852, 39, 2),
(3736706852, 40, 4),

-- --------------------------------------------------------

--
-- Table structure for table `spol`
--

CREATE TABLE IF NOT EXISTS `spol` (
  `spol_id` int(1) DEFAULT NULL,
  `spol_naziv` varchar(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `spol`
--

INSERT INTO `spol` (`spol_id`, `spol_naziv`) VALUES
(1, 'musko'),
(2, 'zensko');

-- --------------------------------------------------------

--
-- Table structure for table `studenti`
--

CREATE TABLE IF NOT EXISTS `studenti` (
  `student_id` bigint(10) unsigned NOT NULL,
  `student_ime` varchar(25) NOT NULL,
  `student_prezime` varchar(25) NOT NULL,
  `student_spol` int(1) unsigned NOT NULL,
  `student_godina_studija` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `studenti`
--

INSERT INTO `studenti` (`student_id`, `student_ime`, `student_prezime`, `student_spol`, `student_godina_studija`) VALUES
(1394984532, 'Mario', 'Kos', 1, 2),
(1473419155, 'Alen', 'Katic', 1, 4),
(1876743912, 'Darija', 'Popovic', 2, 2),
(2131875260, 'Vlatka', 'Marusic', 2, 2),
(2517879602, 'Jelica', 'Miletic', 2, 3),
(2801676037, 'Milovan', 'Ceh', 1, 1),
(2936048095, 'Vladimir', 'Peric', 1, 2),
(3477826494, 'Aleksandra', 'Novosel', 2, 1),
(3736706852, 'Zeljka', 'Stanic', 2, 4),

-- --------------------------------------------------------

--
-- Table structure for table `testna_tablica`
--

CREATE TABLE IF NOT EXISTS `testna_tablica` (
  `id` int(5) NOT NULL,
  `ime` varchar(25) NOT NULL,
  `prezime` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `testna_tablica`
--

INSERT INTO `testna_tablica` (`id`, `ime`, `prezime`) VALUES
(1, 'Ivo', 'Ivic'),
(2, 'Ana', 'Anic'),
(3, 'Pero', 'Peric'),
(4, 'Marko', 'Markic');

-- --------------------------------------------------------

--
-- Table structure for table `test_upisivanja`
--

CREATE TABLE IF NOT EXISTS `test_upisivanja` (
  `prvi` int(5) DEFAULT NULL,
  `drugi` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `kolegiji`
--
ALTER TABLE `kolegiji`
 ADD PRIMARY KEY (`kolegij_id`);

--
-- Indexes for table `polozeni_kolegiji`
--
ALTER TABLE `polozeni_kolegiji`
 ADD PRIMARY KEY (`student_id`,`kolegij_id`);

--
-- Indexes for table `studenti`
--
ALTER TABLE `studenti`
 ADD PRIMARY KEY (`student_id`);

--
-- Indexes for table `testna_tablica`
--
ALTER TABLE `testna_tablica`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `kolegiji`
--
ALTER TABLE `kolegiji`
MODIFY `kolegij_id` int(5) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=53;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

1 个答案:

答案 0 :(得分:0)

如果您确实想要使用方面执行此操作,那么当您要替换将要发生的事情时,您将使用around建议。 beforeafter不会影响将要发生的事情。

pointcut click() : execution (* actionPerformed(..));

void around() : click() {
    // the code in here will run instead of the actionPerformed method body
    // If you make a proceed call, that will run the original body
    // proceed();
}

更多信息:https://eclipse.org/aspectj/doc/next/progguide/semantics-advice.html