本文整理汇总了Java中play.db.DB类的典型用法代码示例。如果您正苦于以下问题:Java DB类的具体用法?Java DB怎么用?Java DB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DB类属于play.db包,在下文中一共展示了DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import play.db.DB; //导入依赖的package包/类
public static boolean create(UserModuleActivation activation) {
Long userId = activation.userId;
String moduleId = activation.moduleId;
if (doesActivationExist(userId, moduleId)) {
return true;
}
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement("INSERT INTO "
+ TABLE_NAME
+ " (user_id, module_id, creation_time) VALUES "
+ "(?, ?, CURRENT_TIMESTAMP)");
s.setLong(1, userId);
s.setString(2, moduleId);
boolean result = s.executeUpdate() != 0;
s.close();
return result;
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:25,代码来源:UserModuleActivationPersistency.java
示例2: remove
import play.db.DB; //导入依赖的package包/类
public static boolean remove(UserModuleActivation activation) {
Long userId = activation.userId;
String moduleId = activation.moduleId;
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement("DELETE FROM "
+ TABLE_NAME + " WHERE user_id = ? AND module_id = ?");
s.setLong(1, userId);
s.setString(2, moduleId);
boolean result = s.executeUpdate() != 0;
s.close();
return result;
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:19,代码来源:UserModuleActivationPersistency.java
示例3: doesActivationExist
import play.db.DB; //导入依赖的package包/类
public static boolean doesActivationExist(Long userId, String moduleId) {
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement("SELECT user_id FROM "
+ TABLE_NAME + " WHERE user_id = ? AND module_id = ?");
s.setLong(1, userId);
s.setString(2, moduleId);
ResultSet result = s.executeQuery();
boolean returnResult = result != null && result.next();
result.close();
s.close();
return returnResult;
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:17,代码来源:UserModuleActivationPersistency.java
示例4: activatedModuleIdsForUser
import play.db.DB; //导入依赖的package包/类
public static String[] activatedModuleIdsForUser(long userId) {
return DB.withConnection(conn -> {
String[] modules = new QueryRunner()
.query(conn,
"SELECT module_id FROM " + TABLE_NAME
+ " WHERE user_id = ?",
new ArrayListHandler(), userId).stream()
.map(array -> {
String module = (String) array[0];
return module;
}).toArray(String[]::new);
return modules;
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:18,代码来源:UserModuleActivationPersistency.java
示例5: userActivationsForModule
import play.db.DB; //导入依赖的package包/类
public static long[] userActivationsForModule(String moduleId) {
return DB.withConnection(conn -> {
Long[] userIds = new QueryRunner()
.query(conn,
"SELECT user_id FROM " + TABLE_NAME
+ " WHERE module_id = ?",
new ArrayListHandler(), moduleId).stream()
.map(array -> {
long id = (long) array[0];
return id;
}).toArray(Long[]::new);
return ArrayUtils.toPrimitive(userIds);
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:18,代码来源:UserModuleActivationPersistency.java
示例6: createAndUpdateIdOnSuccess
import play.db.DB; //导入依赖的package包/类
public static void createAndUpdateIdOnSuccess(User user, String password) {
String hashedPassword = hashPassword(password);
if (UserPersistency.doesUserWithEmailExist(user.email)) {
return;
}
DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement(
"INSERT INTO " + TABLE_NAME + " (email, password, joined_since) VALUES (?, ?, CURRENT_TIMESTAMP)",
Statement.RETURN_GENERATED_KEYS);
s.setString(1, user.email);
s.setString(2, hashedPassword);
int affectedRows = s.executeUpdate();
if (affectedRows != 0) {
ResultSet generatedKeys = s.getGeneratedKeys();
generatedKeys.next();
user.id = generatedKeys.getLong(1);
generatedKeys.close();
s.close();
}
});
}
示例7: getPasswordFromUserWithMail
import play.db.DB; //导入依赖的package包/类
public static String getPasswordFromUserWithMail(String email) {
return DB
.withConnection(conn -> {
PreparedStatement s = conn
.prepareStatement("SELECT password FROM " + TABLE_NAME + " WHERE email = ?");
s.setString(1, email);
ResultSet result = s.executeQuery();
if (result != null && result.next()) {
String hashedPw = result.getString(1);
return hashedPw;
}
return "";
});
}
示例8: setIsAlive
import play.db.DB; //导入依赖的package包/类
public static boolean setIsAlive(String moduleId) {
if (!doesModuleWithIdExist(moduleId)) {
return false;
}
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement(
"UPDATE " + TABLE_NAME + " SET is_alive = TRUE, last_alive_message = CURRENT_TIMESTAMP WHERE id = ?");
s.setString(1, moduleId);
int affectedRows = s.executeUpdate();
s.close();
return affectedRows != 0;
});
}
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:19,代码来源:ActiveAssistanceModulePersistency.java
示例9: update
import play.db.DB; //导入依赖的package包/类
/**
* Updates the device (according to id) with the provided spec.
*
* @param d
*/
public static void update(Device device) {
DB.withConnection(conn -> {
PreparedStatement s = conn
.prepareStatement("UPDATE "
+ TABLE_NAME
+ " SET os = ?, os_version = ?, device_identifier = ?, brand = ?, model = ? WHERE id = ?");
s.setString(1, device.operatingSystem);
s.setString(2, device.osVersion);
s.setString(3, device.deviceIdentifier);
s.setString(4, device.brand);
s.setString(5, device.model);
s.setLong(6, device.id);
s.executeUpdate();
s.close();
});
}
示例10: doesExist
import play.db.DB; //导入依赖的package包/类
/**
* Checks if the device with ID {id} exists
*
* @param id
* @return
*/
public static boolean doesExist(long id) {
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement("SELECT id FROM "
+ TABLE_NAME + " WHERE id = ?");
s.setLong(1, id);
ResultSet result = s.executeQuery();
boolean returnResult = result != null && result.next();
result.close();
s.close();
return returnResult;
});
}
示例11: ownedByUser
import play.db.DB; //导入依赖的package包/类
/**
* Checks if Device with id {deviceId} is owned by user with id {userId}
*
* @param deviceId
* @param userId
* @return TRUE if the specified device is owned by the specified user,
* otherwise FALSE
*/
public static boolean ownedByUser(long deviceId, long userId) {
return DB.withConnection(conn -> {
PreparedStatement s = conn.prepareStatement("SELECT id FROM "
+ TABLE_NAME + " WHERE user_id = ? AND id = ?");
s.setLong(1, userId);
s.setLong(2, deviceId);
ResultSet result = s.executeQuery();
boolean returnResult = result != null && result.next();
result.close();
s.close();
return returnResult;
});
}
示例12: initDB
import play.db.DB; //导入依赖的package包/类
public static void initDB()
throws IOException, SQLException {
String query = "";
FileInputStream inputStream = new FileInputStream(TEST_DATA_FILE);
try {
query = IOUtils.toString(inputStream);
} finally {
inputStream.close();
}
Connection connection = DB.getConnection();
try {
Statement statement = connection.createStatement();
statement.execute(query);
} finally {
connection.close();
}
}
示例13: onStart
import play.db.DB; //导入依赖的package包/类
@Override
public void onStart(Application app) {
super.onStart(app);
// DI初期化
List<Module> moduleList = new ArrayList<Module>();
DataSource dataSource = DB.getDataSource();
moduleList.add(new MirageCustomModule(dataSource));
moduleList.add(new TransactionModule(dataSource));
// Create Injector
if (app.isProd())
INJECTOR = Guice.createInjector(Stage.PRODUCTION, moduleList.toArray(new Module[] {}));
else
INJECTOR = Guice.createInjector(Stage.DEVELOPMENT, moduleList.toArray(new Module[] {}));
}
示例14: loadBitcoindClusters
import play.db.DB; //导入依赖的package包/类
public static int loadBitcoindClusters(){
Connection c = DB.getConnection();
try {
PreparedStatement ps = c.prepareStatement("SELECT id, conn_string, rpc_username, rpc_password FROM bitcoind_clusters ORDER BY id ASC");
ResultSet rs = ps.executeQuery();
while(rs.next()){
String id = rs.getString("id");
String connString = rs.getString("conn_string");
String rpcUsername = rs.getString("rpc_username");
String rpcPassword = rs.getString("rpc_password");
BitcoindClientFactory bcf = new BitcoindClientFactory(new URL(connString), rpcUsername, rpcPassword);
clusters.add( new ClusterInfo(id, connString, bcf) );
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
return clusters.size();
}
示例15: writeClusterAssignmentToDB
import play.db.DB; //导入依赖的package包/类
private static boolean writeClusterAssignmentToDB(String user, Integer clusterAssignment){
Connection c = DB.getConnection();
if(c == null)
return false;
try {
PreparedStatement ps =
c.prepareStatement("INSERT INTO account_holders" +
"(account_name, cluster_id, confirmed_satoshi_balance, unconfirmed_satoshi_balance) VALUES(?, ?, ?, ?)");
ps.setString(1, user);
ps.setInt(2, clusterAssignment);
ps.setLong(3, 0);
ps.setLong(4, 0);
int affectedRows = ps.executeUpdate();
c.close();
boolean res = (affectedRows == 1);
return res;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}