Skip to content

Commit

Permalink
3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Jun 18, 2022
1 parent b054725 commit 2e615ca
Show file tree
Hide file tree
Showing 24 changed files with 678 additions and 11 deletions.
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<classpathentry kind="src" path="samples"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=17
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.1

* Improvements and bug fix.


### 2.9

* Improvements and bug fix.
Expand Down
13 changes: 4 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.landawn</groupId>
<artifactId>abacus-jdbc</artifactId>
<version>3.1</version>
<version>3.1.1</version>
<packaging>jar</packaging>

<name>abacus-jdbc</name>
Expand Down Expand Up @@ -208,8 +208,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>

Expand All @@ -233,12 +233,7 @@
<doctitle>abacus-jdbc</doctitle>
<show>public</show>
<doclint>none</doclint>
<source>8</source>
<sourceFileExcludes>
<exclude>/com/landawn/abacus/util/JoinInfo.java</exclude>
<exclude>/com/landawn/abacus/util/DaoImpl.java</exclude>
<exclude>/com/landawn/abacus/util/dao/DaoUtil.java</exclude>
</sourceFileExcludes>
<source>${maven.compiler.source}</source>
</configuration>

<executions>
Expand Down
8 changes: 8 additions & 0 deletions samples/com/landawn/abacus/samples/dao/AddressDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.dao.CrudDaoL;
import com.landawn.abacus.samples.entity.Address;
import com.landawn.abacus.util.SQLBuilder;

public interface AddressDao extends CrudDaoL<Address, SQLBuilder.PSC, AddressDao> {
}
8 changes: 8 additions & 0 deletions samples/com/landawn/abacus/samples/dao/DeviceDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.dao.CrudDao;
import com.landawn.abacus.samples.entity.Device;
import com.landawn.abacus.util.SQLBuilder;

public interface DeviceDao extends CrudDao<Device, Integer, SQLBuilder.PSC, DeviceDao> {
}
11 changes: 11 additions & 0 deletions samples/com/landawn/abacus/samples/dao/EmployeeDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.SqlLogEnabled;
import com.landawn.abacus.jdbc.dao.CrudDao;
import com.landawn.abacus.jdbc.dao.JoinEntityHelper;
import com.landawn.abacus.samples.entity.Employee;
import com.landawn.abacus.util.SQLBuilder;

@SqlLogEnabled
public interface EmployeeDao extends CrudDao<Employee, Integer, SQLBuilder.PSC, EmployeeDao>, JoinEntityHelper<Employee, SQLBuilder.PSC, EmployeeDao> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.dao.CrudDao;
import com.landawn.abacus.samples.entity.EmployeeProject;
import com.landawn.abacus.util.EntityId;
import com.landawn.abacus.util.SQLBuilder;

public interface EmployeeProjectDao extends CrudDao<EmployeeProject, EntityId, SQLBuilder.PSC, EmployeeProjectDao> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.dao.CrudDao;
import com.landawn.abacus.samples.entity.EmployeeProject;
import com.landawn.abacus.util.SQLBuilder;

public interface EmployeeProjectDao2 extends CrudDao<EmployeeProject, EmployeeProject, SQLBuilder.PSC, EmployeeProjectDao2> {
}
14 changes: 14 additions & 0 deletions samples/com/landawn/abacus/samples/dao/MyUserDaoA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.Config;
import com.landawn.abacus.jdbc.annotation.Handler;
import com.landawn.abacus.jdbc.annotation.PerfLog;
import com.landawn.abacus.samples.dao.handler.UserDaoHandlerA;

@PerfLog(minExecutionTimeForSql = 101, minExecutionTimeForOperation = 100)
@Handler(type = UserDaoHandlerA.class)
@Handler(qualifier = "handler1", filter = ".*")
@Handler(qualifier = "handler2", filter = ".*", isForInvokeFromOutsideOfDaoOnly = true)
@Config(addLimitForSingleQuery = true, callGenerateIdForInsertIfIdNotSet = false)
public interface MyUserDaoA extends UserDao {
}
14 changes: 14 additions & 0 deletions samples/com/landawn/abacus/samples/dao/NoUpdateUserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.Cache;
import com.landawn.abacus.jdbc.annotation.CacheResult;
import com.landawn.abacus.jdbc.annotation.RefreshCache;
import com.landawn.abacus.jdbc.dao.NoUpdateCrudDao;
import com.landawn.abacus.samples.entity.User;
import com.landawn.abacus.util.SQLBuilder;

@CacheResult(transfer = "none")
@Cache(capacity = 1000, evictDelay = 6000)
@RefreshCache
public interface NoUpdateUserDao extends NoUpdateCrudDao<User, Long, SQLBuilder.PSC, NoUpdateUserDao> {
}
11 changes: 11 additions & 0 deletions samples/com/landawn/abacus/samples/dao/ProjectDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.SqlLogEnabled;
import com.landawn.abacus.jdbc.dao.CrudDao;
import com.landawn.abacus.jdbc.dao.JoinEntityHelper;
import com.landawn.abacus.samples.entity.Project;
import com.landawn.abacus.util.SQLBuilder;

@SqlLogEnabled(true)
public interface ProjectDao extends CrudDao<Project, Integer, SQLBuilder.PSC, ProjectDao>, JoinEntityHelper<Project, SQLBuilder.PSC, ProjectDao> {
}
14 changes: 14 additions & 0 deletions samples/com/landawn/abacus/samples/dao/ReadOnlyUserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.Cache;
import com.landawn.abacus.jdbc.annotation.CacheResult;
import com.landawn.abacus.jdbc.annotation.RefreshCache;
import com.landawn.abacus.jdbc.dao.ReadOnlyCrudDao;
import com.landawn.abacus.samples.entity.User;
import com.landawn.abacus.util.SQLBuilder;

@CacheResult(transfer = "none")
@Cache(capacity = 1000, evictDelay = 6000)
@RefreshCache
public interface ReadOnlyUserDao extends ReadOnlyCrudDao<User, Long, SQLBuilder.PSC, ReadOnlyUserDao> {
}
136 changes: 136 additions & 0 deletions samples/com/landawn/abacus/samples/dao/UncheckedUserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.landawn.abacus.samples.dao;

import java.sql.SQLException;
import java.util.List;

import com.landawn.abacus.exception.UncheckedSQLException;
import com.landawn.abacus.jdbc.Propagation;
import com.landawn.abacus.jdbc.annotation.Bind;
import com.landawn.abacus.jdbc.annotation.Define;
import com.landawn.abacus.jdbc.annotation.DefineList;
import com.landawn.abacus.jdbc.annotation.Delete;
import com.landawn.abacus.jdbc.annotation.Handler;
import com.landawn.abacus.jdbc.annotation.Insert;
import com.landawn.abacus.jdbc.annotation.PerfLog;
import com.landawn.abacus.jdbc.annotation.Select;
import com.landawn.abacus.jdbc.annotation.SqlLogEnabled;
import com.landawn.abacus.jdbc.annotation.Sqls;
import com.landawn.abacus.jdbc.annotation.Transactional;
import com.landawn.abacus.jdbc.annotation.Update;
import com.landawn.abacus.jdbc.dao.OP;
import com.landawn.abacus.jdbc.dao.UncheckedCrudDao;
import com.landawn.abacus.jdbc.dao.UncheckedJoinEntityHelper;
import com.landawn.abacus.samples.entity.User;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.SQLBuilder;
import com.landawn.abacus.util.stream.Stream;

@PerfLog(minExecutionTimeForSql = 101, minExecutionTimeForOperation = 100)
public interface UncheckedUserDao
extends UncheckedCrudDao<User, Long, SQLBuilder.PSC, UncheckedUserDao>, UncheckedJoinEntityHelper<User, SQLBuilder.PSC, UncheckedUserDao> {
@Insert("INSERT INTO user (id, first_name, last_name, email) VALUES (:id, :firstName, :lastName, :email)")
void insertWithId(User user);

@Update("UPDATE user SET first_name = :firstName, last_name = :lastName WHERE id = :id")
int updateFirstAndLastName(@Bind("firstName") String newFirstName, @Bind("lastName") String newLastName, @Bind("id") long id);

@SqlLogEnabled
@Select("SELECT first_name, last_name FROM user WHERE id = :id")
User getFirstAndLastNameBy(@Bind("id") long id);

@SqlLogEnabled(false)
@Select("SELECT id, first_name, last_name, email FROM user")
Stream<User> allUsers();

@Insert(sql = "INSERT INTO user (id, first_name, last_name, email) VALUES (:id, :firstName, :lastName, :email)", isBatch = true)
List<Long> batchInsertWithId(List<User> users);

@Insert(sql = "INSERT INTO user (first_name, last_name, email) VALUES (:firstName, :lastName, :email)", isBatch = true, batchSize = 123)
List<Long> batchInsertWithoutId(List<User> users);

@Update(sql = "UPDATE user SET first_name = :firstName, last_name = :lastName WHERE id = :id", isBatch = true)
int batchUpdate(List<User> users);

@Delete(sql = "DELETE FROM user where id = :id", isBatch = true)
int batchDelete(List<User> users);

@Delete(sql = "DELETE FROM user where id = :id", isBatch = true, batchSize = 10000)
int batchDeleteByIds(List<Long> userIds);

@Delete(sql = "DELETE FROM user where id = ?", isBatch = true, batchSize = 10000)
int batchDeleteByIds_1(List<Long> userIds);

default int[] batchDeleteByIds_2(List<Long> userIds) throws SQLException {
return prepareNamedQuery("DELETE FROM user where id = :id").addBatchParameters(userIds, long.class).batchUpdate();
}

@Sqls({ "SELECT * FROM user where id >= :id", "SELECT * FROM user where id >= :id" })
default List<User> listUserByAnnoSql(long id, String... sqls) {
try {
return prepareNamedQuery(sqls[0]).setLong(1, id).list(User.class);
} catch (SQLException e) {
throw new UncheckedSQLException(e);
}
}

@Transactional
@Sqls({ "update user set first_name = ? where id = -1", "SELECT * FROM user where id >= :id" })
default List<User> listUserByAnnoSql2(String firstName, long id, String... sqls) {
try {
prepareQuery(sqls[0]).setString(1, firstName).update();
return prepareNamedQuery(sqls[1]).setLong(1, id).list(User.class);
} catch (SQLException e) {
throw new UncheckedSQLException(e);
}
}

@Transactional(propagation = Propagation.SUPPORTS)
@Sqls("DELETE from user where id = ?")
default boolean delete_propagation_SUPPORTS(long id, String... sqls) {
N.sleep(1001);

try {
return prepareQuery(sqls[0]).setLong(1, id).update() > 0;
} catch (SQLException e) {
throw new UncheckedSQLException(e);
}
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Handler(qualifier = "handler2")
@Sqls("DELETE from user where id = ?")
default boolean delete_propagation_REQUIRES_NEW(long id, String... sqls) {
try {
return prepareQuery(sqls[0]).setLong(1, id).update() > 0;
} catch (SQLException e) {
throw new UncheckedSQLException(e);
}
}

@Delete(sql = "DELETE FROM {tableName} where id = :id")
int deleteByIdWithDefine(@Define("tableName") String tableName, @Bind("id") long id);

@Delete(sql = "DELETE FROM {tableName} where id = :id", isBatch = true, batchSize = 10000)
int deleteByIdsWithDefine(@DefineList("tableName") List<String> tableName, List<Long> userIds);

@Select(sql = "SELECT * FROM {tableName} where id = :id ORDER BY {{orderBy}}")
User selectByIdWithDefine(@Define("tableName") String tableName, @Define("{{orderBy}}") String orderBy, @Bind("id") long id);

@Select(sql = "SELECT * FROM {tableName} where id >= ? ORDER BY {whatever -> orderBy{{P}}")
List<User> selectByIdWithDefine_2(@Define("tableName") String tableName, @Define("{whatever -> orderBy{{P}}") String orderBy, long id);

@Select(sql = "SELECT * FROM {tableName} where id >= ? AND first_name != ? ORDER BY {whatever -> orderBy{{P}} LIMIT {count}")
List<User> selectByIdWithDefine_3(@Define("tableName") String tableName, long id, @Define("{whatever -> orderBy{{P}}") String orderBy,
@Define("{count}") long count, String firstName);

@Select(sql = "SELECT * FROM {tableName} where id >= :id AND first_name != :firstName ORDER BY {whatever -> orderBy{{P}} LIMIT {count}")
List<User> selectByIdWithDefine_4(@Define("tableName") String tableName, @Bind("id") long id, @Define("{whatever -> orderBy{{P}}") String orderBy,
@Define("{count}") long count, @Bind("firstName") String firstName);

@Select(sql = "SELECT * FROM {tableName} where id = :id ORDER BY {{orderBy}}")
boolean exists(@Define("tableName") String tableName, @Define("{{orderBy}}") String orderBy, @Bind("id") long id);

@Select(sql = "SELECT * FROM {tableName} where id = :id ORDER BY {{orderBy}}", op = OP.exists)
boolean isThere(@Define("tableName") String tableName, @Define("{{orderBy}}") String orderBy, @Bind("id") long id) throws SQLException;

}
12 changes: 12 additions & 0 deletions samples/com/landawn/abacus/samples/dao/UncheckedUserDaoL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.landawn.abacus.samples.dao;

import com.landawn.abacus.jdbc.annotation.PerfLog;
import com.landawn.abacus.jdbc.dao.UncheckedCrudDaoL;
import com.landawn.abacus.jdbc.dao.UncheckedReadOnlyCrudJoinEntityHelper;
import com.landawn.abacus.samples.entity.User;
import com.landawn.abacus.util.SQLBuilder;

@PerfLog(minExecutionTimeForSql = 101, minExecutionTimeForOperation = 100)
public interface UncheckedUserDaoL extends UncheckedCrudDaoL<User, SQLBuilder.PSC, UncheckedUserDaoL>,
UncheckedReadOnlyCrudJoinEntityHelper<User, Long, SQLBuilder.PSC, UncheckedUserDaoL> {
}
Loading

0 comments on commit 2e615ca

Please sign in to comment.