<commit_before>package ru.ydn.wicket.wicketorientdb;

import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference;

import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.metadata.security.OSecurityUser;
import com.orientechnologies.orient.core.metadata.security.OUser;

/**
 * Implementation of {@link IRequestCycleListener} for starting and stoping transactions just for pages and dynamic resources
 */
public class TransactionRequestCycleListener extends
		AbstractContentAwareTransactionRequestCycleListener {
	@Override
	public void start(RequestCycle cycle) {
		OrientDbWebSession session = OrientDbWebSession.get();
		ODatabaseDocument db = session.getDatabase();
		//It's required to have ability to check security rights locally
		OSecurityUser oUser = db.getUser();
		if(oUser.getDocument()!=null && oUser.getDocument().getIdentity()!=null && !oUser.getDocument().getIdentity().isValid())
		{
			db.setUser(db.getMetadata().getSecurity().getUser(oUser.getName()));
		}
		db.begin();
	}
	

	@Override
	public void end(RequestCycle cycle) {
		ODatabaseRecordThreadLocal.INSTANCE.get().commit();
	}
	
	@Override
	public void onDetach(RequestCycle cycle) {
		ODatabaseRecordThreadLocal.INSTANCE.get().close();
		ODatabaseRecordThreadLocal.INSTANCE.remove();
	}
	
	

	@Override<commit_msg>Corrections for db.getUser() - additional checks for null<commit_after>package ru.ydn.wicket.wicketorientdb;

import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.lang.Objects;

import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.metadata.security.OSecurityUser;
import com.orientechnologies.orient.core.metadata.security.OUser;

/**
 * Implementation of {@link IRequestCycleListener} for starting and stoping transactions just for pages and dynamic resources
 */
public class TransactionRequestCycleListener extends
		AbstractContentAwareTransactionRequestCycleListener {
	@Override
	public void start(RequestCycle cycle) {
		OrientDbWebSession session = OrientDbWebSession.get();
		ODatabaseDocument db = session.getDatabase();
		//It's required to have ability to check security rights locally
		OSecurityUser oUser = session.getUser();
		OSecurityUser dbUser = db.getUser();
		if(oUser!=null && oUser.getDocument()!=null 
				&& oUser.getDocument().getIdentity()!=null 
				&& (!oUser.getDocument().getIdentity().isValid() || dbUser==null || !Objects.equal(dbUser.getName(), oUser.getName())))
		{
			db.setUser(db.getMetadata().getSecurity().getUser(oUser.getName()));
		}
		db.begin();
	}
	

	@Override
	public void end(RequestCycle cycle) {
		ODatabaseRecordThreadLocal.INSTANCE.get().commit();
	}
	
	@Override
	public void onDetach(RequestCycle cycle) {
		ODatabaseRecordThreadLocal.INSTANCE.get().close();
		ODatabaseRecordThreadLocal.INSTANCE.remove();
	}
	
	

	@Override
{'fraction_non_alphanumeric': 0.11057173678532901, 'fraction_numerical': 0.0, 'mean_word_length': 6.187984496124031, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1924137', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1086, 'n_words': 184}