use of com.infiniteautomation.mango.db.query.SQLStatement in project ma-core-public by infiniteautomation.
the class DataPointDao method bulkClearPermissions.
/**
* @param node
* @param updateSetPermissions - true will update set, false will update read
* @return
*/
public long bulkClearPermissions(ASTNode root, boolean updateSetPermissions) {
long count;
if (root == null) {
// All points
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
} else {
switch(Common.databaseProxy.getType()) {
case H2:
case DERBY:
case MSSQL:
case MYSQL:
case POSTGRES:
default:
final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
select.build();
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
break;
}
}
return count;
}
use of com.infiniteautomation.mango.db.query.SQLStatement in project ma-core-public by infiniteautomation.
the class DataPointDao method bulkUpdatePermissions.
/**
* @param node
* @param permissions
* @param updateSetPermissions - true will update set, false will update read
* @return
*/
public long bulkUpdatePermissions(ASTNode root, String uncleanPermissions, boolean updateSetPermissions) {
// Anything to do?
if (StringUtils.isEmpty(uncleanPermissions))
return 0;
// Trim off any ending commas
if (uncleanPermissions.endsWith(",")) {
uncleanPermissions = uncleanPermissions.substring(0, uncleanPermissions.length() - 1);
}
final String newPermissions = uncleanPermissions;
long count;
if (root == null) {
// All points
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
} else {
switch(Common.databaseProxy.getType()) {
case H2:
case DERBY:
case MSSQL:
case MYSQL:
case POSTGRES:
default:
final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
select.build();
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
break;
}
}
return count;
}
use of com.infiniteautomation.mango.db.query.SQLStatement in project ma-core-public by infiniteautomation.
the class AbstractBasicDao method createQuery.
/**
* @param root
* @param selectCallback
* @param countCallback
* @param modelMap
* @param modifiers
* @param applyLimitToSelectSql
* @return
*/
public StreamableSqlQuery<T> createQuery(ASTNode root, StreamableRowCallback<T> selectCallback, StreamableRowCallback<Long> countCallback, Map<String, String> modelMap, Map<String, SQLColumnQueryAppender> modifiers, boolean applyLimitToSelectSql) {
SQLStatement statement;
if (useSubQuery) {
statement = new SQLSubQuery(SELECT_ALL_BASE, COUNT_BASE, joins, getTableName(), TABLE_PREFIX, applyLimitToSelectSql, Common.envProps.getBoolean("db.forceUseIndex", false), null, this.indexes, this.databaseType);
} else {
statement = new SQLStatement(SELECT_ALL_BASE, COUNT_BASE, joins, getTableName(), TABLE_PREFIX, applyLimitToSelectSql, Common.envProps.getBoolean("db.forceUseIndex", false), this.indexes, this.databaseType);
}
if (root != null)
root.accept(new RQLToSQLSelect<T>(this, modelMap, modifiers), statement);
statement.build();
return new StreamableSqlQuery<T>(this, Common.envProps.getBoolean("db.stream", false), statement, selectCallback, countCallback);
}
use of com.infiniteautomation.mango.db.query.SQLStatement in project ma-core-public by infiniteautomation.
the class AbstractBasicDao method createQuery.
/**
* @param root
* @param applyLimitToSelectSql
* @return
*/
public BaseSqlQuery<T> createQuery(ASTNode root, boolean applyLimitToSelectSql) {
SQLStatement statement = new SQLStatement(SELECT_ALL_BASE, COUNT_BASE, joins, getTableName(), TABLE_PREFIX, applyLimitToSelectSql, Common.envProps.getBoolean("db.forceUseIndex", false), this.indexes, this.databaseType);
if (root != null)
root.accept(new RQLToSQLSelect<T>(this), statement);
statement.build();
return new BaseSqlQuery<T>(this, statement);
}
Aggregations