use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class T_CreateConglomRet method isdbActive.
/**
* Check wheather the database is active or not
* @return {@code true} if the database is active, {@code false} otherwise
*/
public boolean isdbActive() {
LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
Database db = (Database) (lcc != null ? lcc.getDatabase() : null);
return (db != null ? db.isActive() : false);
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class XPLAINDefaultVisitor method doXPLAIN.
public void doXPLAIN(RunTimeStatistics rss, Activation activation) {
LanguageConnectionContext lcc;
try {
lcc = ConnectionUtil.getCurrentLCC();
HeaderPrintWriter istream = lcc.getLogQueryPlan() ? Monitor.getStream() : null;
if (istream != null) {
istream.printlnWithHeader(LanguageConnectionContext.xidStr + lcc.getTransactionExecute().getTransactionIdString() + "), " + LanguageConnectionContext.lccStr + lcc.getInstanceNumber() + "), " + rss.getStatementText() + " ******* " + rss.getStatementExecutionPlanText());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class XPLAINFactory method getXPLAINVisitor.
/**
* the factory method, which gets called to determine
* and return an appropriate XPLAINVisitor instance
*/
public XPLAINVisitor getXPLAINVisitor() throws StandardException {
try {
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
String schema = lcc.getXplainSchema();
if (schema != currentSchema) {
currentSchema = schema;
if (currentSchema == null)
currentVisitor = new XPLAINDefaultVisitor();
else
currentVisitor = new XPLAINSystemTableVisitor();
}
} catch (SQLException e) {
throw StandardException.plainWrapException(e);
}
return currentVisitor;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class GenericPrivilegeInfo method executeGrantRevoke.
// /////////////////////////////////////////////////////////////////////////////////
//
// PrivilegeInfo BEHAVIOR
//
// /////////////////////////////////////////////////////////////////////////////////
/**
* This is the guts of the Execution-time logic for GRANT/REVOKE generic privileges.
*
* @param activation
* @param grant true if grant, false if revoke
* @param grantees a list of authorization ids (strings)
*
* @exception StandardException Thrown on failure
*/
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
// Check that the current user has permission to grant the privileges.
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
String currentUser = lcc.getCurrentUserId(activation);
TransactionController tc = lcc.getTransactionExecute();
SchemaDescriptor sd = _tupleDescriptor.getSchemaDescriptor();
UUID objectID = _tupleDescriptor.getUUID();
String objectTypeName = _tupleDescriptor.getObjectTypeName();
// Check that the current user has permission to grant the privileges.
checkOwnership(currentUser, (TupleDescriptor) _tupleDescriptor, sd, dd);
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
PermDescriptor permDesc = ddg.newPermDescriptor(null, objectTypeName, objectID, _privilege, currentUser, null, false);
dd.startWriting(lcc);
for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
// Keep track to see if any privileges are revoked by a revoke
// statement. If a privilege is not revoked, we need to raise a
// warning.
boolean privileges_revoked = false;
String grantee = (String) itr.next();
if (dd.addRemovePermissionsDescriptor(grant, permDesc, grantee, tc)) {
//
// We fall in here if we are performing REVOKE.
//
privileges_revoked = true;
int invalidationType = _restrict ? DependencyManager.REVOKE_PRIVILEGE_RESTRICT : DependencyManager.REVOKE_PRIVILEGE;
dd.getDependencyManager().invalidateFor(permDesc, invalidationType, lcc);
// Now invalidate all GPSs refering to the object.
dd.getDependencyManager().invalidateFor(_tupleDescriptor, invalidationType, lcc);
}
addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class SetRoleConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for SET ROLE.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc;
DataDictionary dd;
// find the language context.
lcc = activation.getLanguageConnectionContext();
dd = lcc.getDataDictionary();
String thisRoleName = roleName;
final String currentAuthId = lcc.getCurrentUserId(activation);
final String dbo = lcc.getDataDictionary().getAuthorizationDatabaseOwner();
TransactionController tc = lcc.getTransactionExecute();
// SQL 2003, section 18.3, General rule 1:
if (!tc.isIdle()) {
throw StandardException.newException(SQLState.INVALID_TRANSACTION_STATE_ACTIVE_CONNECTION);
}
if (type == StatementType.SET_ROLE_DYNAMIC) {
ParameterValueSet pvs = activation.getParameterValueSet();
DataValueDescriptor dvs = pvs.getParameter(0);
// SQL 2003, section 18.3, GR2: trim whitespace first, and
// interpret as identifier, then we convert it to case normal form
// here.
String roleId = dvs.getString();
if (roleId == null) {
throw StandardException.newException(SQLState.ID_PARSE_ERROR);
}
thisRoleName = IdUtil.parseRoleId(roleId);
}
RoleGrantDescriptor rdDef = null;
try {
String oldRole = lcc.getCurrentRoleId(activation);
if (oldRole != null && !oldRole.equals(thisRoleName)) {
rdDef = dd.getRoleDefinitionDescriptor(oldRole);
if (rdDef != null) {
dd.getDependencyManager().invalidateFor(rdDef, DependencyManager.RECHECK_PRIVILEGES, lcc);
}
// else: old role else no longer exists, so ignore.
}
if (thisRoleName != null) {
rdDef = dd.getRoleDefinitionDescriptor(thisRoleName);
// SQL 2003, section 18.3, General rule 4:
if (rdDef == null) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, thisRoleName);
}
if (!lcc.roleIsSettable(activation, thisRoleName)) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION_NOT_GRANTED, thisRoleName);
}
}
} finally {
// reading above changes idle state, so reestablish it
lcc.userCommit();
}
lcc.setCurrentRole(activation, rdDef != null ? thisRoleName : null);
}
Aggregations