diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7078130
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/target/
+/nbproject/
+/.vscode/
+/.settings/
+.classpath
+.project
+nb-configuration.xml
diff --git a/pom.xml b/pom.xml
index 6b37a72..5f43b91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0ua.net.uiduid.database
- 1.0.0-SNAPSHOT
+ 1.0.2-SNAPSHOTjar
@@ -97,6 +97,7 @@
scm:git:https://git.uid.net.ua/git/uid/uid.database.gitscm:git:https://git.uid.net.ua/git/uid/uid.database.githttps://git.uid.net.ua/git/uid/uid.database.git
+ HEAD
diff --git a/src/main/java/ua/net/uid/utils/db/Batch.java b/src/main/java/ua/net/uid/utils/db/Batch.java
index dffd4bd..d70827a 100644
--- a/src/main/java/ua/net/uid/utils/db/Batch.java
+++ b/src/main/java/ua/net/uid/utils/db/Batch.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.io.Closeable;
diff --git a/src/main/java/ua/net/uid/utils/db/Block.java b/src/main/java/ua/net/uid/utils/db/Block.java
index 66424ab..e94b62a 100644
--- a/src/main/java/ua/net/uid/utils/db/Block.java
+++ b/src/main/java/ua/net/uid/utils/db/Block.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.SQLException;
diff --git a/src/main/java/ua/net/uid/utils/db/Connector.java b/src/main/java/ua/net/uid/utils/db/Connector.java
index f2573d0..c0669ae 100644
--- a/src/main/java/ua/net/uid/utils/db/Connector.java
+++ b/src/main/java/ua/net/uid/utils/db/Connector.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import javax.sql.DataSource;
diff --git a/src/main/java/ua/net/uid/utils/db/Database.java b/src/main/java/ua/net/uid/utils/db/Database.java
index 5c899f6..89109f1 100644
--- a/src/main/java/ua/net/uid/utils/db/Database.java
+++ b/src/main/java/ua/net/uid/utils/db/Database.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import javax.sql.ConnectionPoolDataSource;
diff --git a/src/main/java/ua/net/uid/utils/db/Fetcher.java b/src/main/java/ua/net/uid/utils/db/Fetcher.java
index 39e772a..51870c5 100644
--- a/src/main/java/ua/net/uid/utils/db/Fetcher.java
+++ b/src/main/java/ua/net/uid/utils/db/Fetcher.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.ResultSet;
diff --git a/src/main/java/ua/net/uid/utils/db/Outcome.java b/src/main/java/ua/net/uid/utils/db/Outcome.java
index 233766d..15cd0ad 100644
--- a/src/main/java/ua/net/uid/utils/db/Outcome.java
+++ b/src/main/java/ua/net/uid/utils/db/Outcome.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.ResultSet;
diff --git a/src/main/java/ua/net/uid/utils/db/Processor.java b/src/main/java/ua/net/uid/utils/db/Processor.java
index b3dd8b2..c507920 100644
--- a/src/main/java/ua/net/uid/utils/db/Processor.java
+++ b/src/main/java/ua/net/uid/utils/db/Processor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.*;
diff --git a/src/main/java/ua/net/uid/utils/db/Session.java b/src/main/java/ua/net/uid/utils/db/Session.java
index 2625248..eff6d5c 100644
--- a/src/main/java/ua/net/uid/utils/db/Session.java
+++ b/src/main/java/ua/net/uid/utils/db/Session.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.Connection;
diff --git a/src/main/java/ua/net/uid/utils/db/Solid.java b/src/main/java/ua/net/uid/utils/db/Solid.java
index a32efc1..c76864d 100644
--- a/src/main/java/ua/net/uid/utils/db/Solid.java
+++ b/src/main/java/ua/net/uid/utils/db/Solid.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.SQLException;
diff --git a/src/main/java/ua/net/uid/utils/db/Transaction.java b/src/main/java/ua/net/uid/utils/db/Transaction.java
index 0223813..eecfd43 100644
--- a/src/main/java/ua/net/uid/utils/db/Transaction.java
+++ b/src/main/java/ua/net/uid/utils/db/Transaction.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 nightfall.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ua.net.uid.utils.db;
import java.sql.Connection;
diff --git a/src/main/java/ua/net/uid/utils/db/dao/DAO.java b/src/main/java/ua/net/uid/utils/db/dao/DAO.java
deleted file mode 100644
index 73cff9b..0000000
--- a/src/main/java/ua/net/uid/utils/db/dao/DAO.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package ua.net.uid.utils.db.dao;
-
-import ua.net.uid.utils.db.Session;
-
-public interface DAO {
- Session getSession();
-}
diff --git a/src/main/java/ua/net/uid/utils/db/dao/DAOAbstract.java b/src/main/java/ua/net/uid/utils/db/dao/DAOAbstract.java
deleted file mode 100644
index efcc608..0000000
--- a/src/main/java/ua/net/uid/utils/db/dao/DAOAbstract.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package ua.net.uid.utils.db.dao;
-
-import ua.net.uid.utils.db.Session;
-
-import java.io.Serializable;
-
-public abstract class DAOAbstract, PK extends Serializable> extends DAOCore implements DAOBase {
- public DAOAbstract(Session session) {
- super(session);
- }
-}
diff --git a/src/main/java/ua/net/uid/utils/db/dao/DAOBase.java b/src/main/java/ua/net/uid/utils/db/dao/DAOBase.java
deleted file mode 100644
index f70b168..0000000
--- a/src/main/java/ua/net/uid/utils/db/dao/DAOBase.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package ua.net.uid.utils.db.dao;
-
-import ua.net.uid.utils.db.Fetcher;
-import ua.net.uid.utils.db.Outcome;
-import ua.net.uid.utils.db.query.Condition;
-import ua.net.uid.utils.db.query.Order;
-import ua.net.uid.utils.db.query.QueryBuilder;
-
-import java.io.Serializable;
-import java.sql.SQLException;
-import java.util.List;
-import ua.net.uid.utils.db.Processor;
-
-public interface DAOBase, PK extends Serializable> extends DAO {
- String getTableName();
-
- Condition getPrimaryCondition(PK key);
-
- default Order getDefaultOrder() {
- return null;
- }
-
- Fetcher getFetcher();
-
- default T get(PK key) throws SQLException {
- return getBy(getPrimaryCondition(key));
- }
-
- default T getBy(Condition condition) throws SQLException {
- return new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(" WHERE ", condition)
- .append(" LIMIT 1")
- .on(getSession()).scalar(getFetcher());
- }
-
- default long countAll() throws SQLException {
- return getSession().query("SELECT COUNT(*) FROM " + getTableName()).select(Outcome.FIRST_LONG);
- }
-
- default List findAll() throws SQLException {
- return findAll(getDefaultOrder());
- }
-
- default void foreachAll(Processor.Callback callback) throws SQLException {
- foreachAll(callback, getDefaultOrder());
- }
-
- default List findAll(Order order) throws SQLException {
- return new QueryBuilder().append("SELECT * FROM ").append(getTableName())
- .append(order).on(getSession()).list(getFetcher());
- }
-
- default void foreachAll(Processor.Callback callback, Order order) throws SQLException {
- new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(order)
- .on(getSession()).foreach(getFetcher(), callback);
- }
-
- default List findAll(long limit, long offset) throws SQLException {
- return findAll(getDefaultOrder(), limit, offset);
- }
-
- default void foreachAll(Processor.Callback callback, long limit, long offset) throws SQLException {
- foreachAll(callback, getDefaultOrder(), limit, offset);
- }
-
- default List findAll(Order order, long limit, long offset) throws SQLException {
- return new QueryBuilder().append("SELECT * FROM ").append(getTableName())
- .append(order).on(getSession()).list(getFetcher());
- }
-
- default void foreachAll(Processor.Callback callback, Order order, long limit, long offset) throws SQLException {
- new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(order)
- .append(" LIMIT ? OFFSET ?", limit, offset)
- .on(getSession()).foreach(getFetcher(), callback);
- }
-
- default long countBy(Condition condition) throws SQLException {
- return new QueryBuilder()
- .append("SELECT COUNT(*) FROM ")
- .append(getTableName())
- .append(" WHERE ", condition)
- .on(getSession()).select(Outcome.FIRST_LONG);
- }
-
- default List findBy(Condition condition) throws SQLException {
- return findBy(condition, getDefaultOrder());
- }
-
- default void foreachBy(Processor.Callback callback, Condition condition) throws SQLException {
- foreachBy(callback, condition, getDefaultOrder());
- }
-
- default List findBy(Condition condition, Order order) throws SQLException {
- return new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(" WHERE ", condition)
- .append(order)
- .on(getSession()).list(getFetcher());
- }
-
- default void foreachBy(Processor.Callback callback, Condition condition, Order order) throws SQLException {
- new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(" WHERE ", condition)
- .append(order)
- .on(getSession()).foreach(getFetcher(), callback);
- }
-
- default List findBy(Condition condition, long limit, long offset) throws SQLException {
- return findBy(condition, getDefaultOrder(), limit, offset);
- }
-
- default void foreachBy(Processor.Callback callback, Condition condition, long limit, long offset) throws SQLException {
- foreachBy(callback, condition, getDefaultOrder(), limit, offset);
- }
-
- default List findBy(Condition condition, Order order, long limit, long offset) throws SQLException {
- return new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(" WHERE ", condition)
- .append(" LIMIT ? OFFSET ?", limit, offset)
- .append(order)
- .on(getSession()).list(getFetcher());
- }
-
- default void foreachBy(Processor.Callback callback, Condition condition, Order order, long limit, long offset) throws SQLException {
- new QueryBuilder()
- .append("SELECT * FROM ").append(getTableName())
- .append(" WHERE ", condition)
- .append(" LIMIT ? OFFSET ?", limit, offset)
- .append(order)
- .on(getSession()).foreach(getFetcher(), callback);
- }
-
- boolean insert(T item) throws SQLException;
-
- boolean update(T item, PK key) throws SQLException;
-
- default boolean update(T item) throws SQLException {
- return update(item, item.getPrimaryKey());
- }
-
- default boolean delete(PK key) throws SQLException {
- return new QueryBuilder()
- .append("DELETE FROM ").append(getTableName())
- .append(" WHERE ", getPrimaryCondition(key))
- .on(getSession()).update() > 0;
- }
-
- default boolean delete(T item) throws SQLException {
- return delete(item.getPrimaryKey());
- }
-}
diff --git a/src/main/java/ua/net/uid/utils/db/dao/DAOCore.java b/src/main/java/ua/net/uid/utils/db/dao/DAOCore.java
deleted file mode 100644
index 65d6be1..0000000
--- a/src/main/java/ua/net/uid/utils/db/dao/DAOCore.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package ua.net.uid.utils.db.dao;
-
-import ua.net.uid.utils.db.Session;
-
-public abstract class DAOCore implements DAO {
- private final Session session;
-
- public DAOCore(Session session) {
- this.session = session;
- }
-
- @Override
- public Session getSession() {
- return session;
- }
-}
diff --git a/src/main/java/ua/net/uid/utils/db/dao/Entity.java b/src/main/java/ua/net/uid/utils/db/dao/Entity.java
deleted file mode 100644
index 485fa5b..0000000
--- a/src/main/java/ua/net/uid/utils/db/dao/Entity.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package ua.net.uid.utils.db.dao;
-
-import java.io.Serializable;
-
-public interface Entity {
- PK getPrimaryKey();
-}
diff --git a/src/main/java/ua/net/uid/utils/db/query/Condition.java b/src/main/java/ua/net/uid/utils/db/query/Condition.java
deleted file mode 100644
index 90b338b..0000000
--- a/src/main/java/ua/net/uid/utils/db/query/Condition.java
+++ /dev/null
@@ -1,194 +0,0 @@
-package ua.net.uid.utils.db.query;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public abstract class Condition implements QueryPart {
- public static Condition raw(CharSequence condition, Object... params) {
- if (condition == null)
- throw new IllegalArgumentException("condition is null");
- return new Raw(condition, params);
- }
-
- public static Condition not(CharSequence condition, Object... params) {
- return new Not(raw(condition, params));
- }
-
- public static Condition not(Condition condition) {
- if (condition == null) {
- return null;
- } else if (condition instanceof Not) {
- return ((Not) condition).condition;
- } else {
- return new Not(condition);
- }
- }
-
- public static Condition and(Condition left, Condition right) {
- if (left != null) {
- return right == null ? left : new And(left, right);
- } else {
- return right;
- }
- }
-
- public static Condition and(Condition... conditions) {
- if (conditions == null || conditions.length == 0) return null;
- return conditions.length == 1 ? conditions[0] : new And(conditions);
- }
-
- public static Condition or(Condition... conditions) {
- if (conditions == null || conditions.length == 0) return null;
- return conditions.length == 1 ? conditions[0] : new Or(conditions);
- }
-
- public static Condition in(CharSequence left, Collection items) {
- if (left == null || left.length() == 0)
- throw new IllegalArgumentException("left side parameter for 'in' condition is null");
- if (items == null || items.isEmpty()) return null;
- return new In(left, items.toArray(new Object[items.size()]));
- }
-
- public static Condition in(CharSequence left, Object... items) {
- if (left == null || left.length() == 0)
- throw new IllegalArgumentException("left side parameter for 'in' condition is null");
- if (items == null || items.length == 0) return null;
- return new In(left, items);
- }
-
- public Object[] toParams(Object... post) {
- ArrayList