View Javadoc
1   package guru.mikelue.jdut.operation;
2   
3   import java.sql.Connection;
4   import java.sql.SQLException;
5   import java.util.List;
6   import java.util.function.UnaryOperator;
7   
8   import guru.mikelue.jdut.datagrain.DataGrain;
9   import guru.mikelue.jdut.datagrain.DataRow;
10  
11  /**
12   * Operator to execute code by fed {@link List} of {@link DataRow}.
13   */
14  @FunctionalInterface
15  public interface DataRowsOperator {
16  	/**
17  	 * The operator for surrounding of {@link DataRowsOperator}.
18  	 */
19  	public interface SurroundOperator {
20  		/**
21  		 * Converts this operator ot {@link UnaryOperator}.
22  		 *
23  		 * @return The unary operator
24  		 */
25  		default UnaryOperator<DataRowsOperator> asUnaryOperator()
26  		{
27  			return operator -> surround(operator);
28  		}
29  
30  		/**
31  		 * Surrounds operator.
32  		 *
33  		 * @param surroundedOperator The oprator to be surrounded
34  		 *
35  		 * @return The final function
36  		 */
37  		public DataRowsOperator../guru/mikelue/jdut/operation/DataRowsOperator.html#DataRowsOperator">DataRowsOperator surround(DataRowsOperator surroundedOperator);
38  	}
39  
40  	/**
41  	 * Does nothing.
42  	 *
43  	 * @param conn The connection object
44  	 * @param dataRows The data of rows
45  	 *
46  	 * @return The same data rows
47  	 */
48  	static List<DataRow> none(Connection conn, List<DataRow> dataRows) { return dataRows; }
49  
50  	/**
51  	 * Converts this instance to {@link DataGrainOperator}.
52  	 *
53  	 * @return The operator for {@link DataGrain}
54  	 */
55  	default DataGrainOperator toDataGrainOperator()
56  	{
57  		return (connection, dataGrain) -> new DataGrain(operate(connection, dataGrain.getRows()));
58  	}
59  
60  	/**
61  	 * Surrounds this instance by {@link SurroundOperator}.
62  	 *
63  	 * @param surroundOperator The operator to surrounding staff
64  	 *
65  	 * @return new operator of data rows
66  	 */
67  	default DataRowsOperator surroundedBy(SurroundOperator surroundOperator)
68  	{
69  		return surroundOperator.surround(this);
70  	}
71  
72  	/**
73  	 * Operates {@link List} of {@link DataRow} by {@link Connection}.
74  	 *
75  	 * @param connection The connection of database
76  	 * @param dataRows The data grain to be operated
77  	 *
78  	 * @return The processed data rows
79  	 *
80  	 * @throws SQLException The SQL exception defined by JDBC
81  	 */
82  	public List<DataRow> operate(Connection connection, List<DataRow> dataRows) throws SQLException;
83  }