<commit_before>/*
Copyright (c) 2000-2013 "independIT Integrative Technologies GmbH",
Authors: <NAME>, <NAME>

schedulix Enterprise Job Scheduling System

independIT Integrative Technologies GmbH [http://www.independit.de]
mailto:<EMAIL>

This file is part of schedulix

schedulix is free software: 
you can redistribute it and/or modify it under the terms of the 
GNU Affero General Public License as published by the 
Free Software Foundation, either version 3 of the License, 
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.independit.scheduler.server.repository;

import java.lang.*;
import java.util.*;
import java.io.*;

import de.independit.scheduler.server.*;
import de.independit.scheduler.server.exception.*;
import de.independit.scheduler.server.output.*;
import de.independit.scheduler.server.util.*;
import de.independit.scheduler.server.locking.*;

public class SDMSIndex
{

	public final static String __version = "@(#) $Id: SDMSIndex.java,v 2.7.2.3 2013/06/07 18:48:36 dieter Exp $";

	public static final int ORDINARY = 0;

	public static final int UNIQUE   = 1;

	public static final int IDUNIQUE = 3;

	private SDMSIndexMap hashMap;
	private int type;
	private boolean isVersioned;

	public SDMSTable table;
	public String indexName;

	private static final Comparator objectIdComparator = new ObjectIdComparator();

	public SDMSIndex (SystemEnvironment env, int t, boolean versioned, SDMSTable table, String indexName)
	throws SDMSException
	{
		if(t != ORDINARY &&
		   t != UNIQUE   &&
		   t != IDUNIQUE) {
			throw new FatalException(new SDMSMessage(env,
						"03110181526", "Invalid Indextype $1", new Integer(t)));

		}
		this.table = table;
		this.indexName = indexName;
		hashMap = new SDMSIndexMap(this);
		type = t;
		isVersioned = versioned;
	}

	public void put (SystemEnvironment env, Object key, SDMSObject o)
		throws SDMSException
	{
		put (env, key, o, true);
	}

	public void put (SystemEnvironment env, Object key, SDMSObject o, boolean doLockBucket)
		throws SDMSException
	{
		SDMSIndexBucket v = null;
		synchronized(hashMap) {
			v = (SDMSIndexBucket) hashMap.get(key);
			if(v == null) {
				v = new SDMSIndexBucket(this, key);
				synchronized(v) {
					v.modCnt ++;
				}
				hashMap.put(key, v);
			} else
				synchronized(v) {
					v.modCnt ++;
				}
		}

		if (env.maxWriter > 1 && doLockBucket) {
			try {
				LockingSystem.lock(env, v, ObjectLock.EXCLUSIVE);
			} catch (Exception e) {
				synchronized(v) {
					v.modCnt --;
				}
				throw e;
			}
		}

		boolean newBucket = false;
		synchronized (v) {
			if (v.size() == 0) {
				v.add(o);
				v.modCnt --;
				newBucket = true;
			}
		}
		if (newBucket) {
			if (env.maxWriter > 1)
				LockingSystem.release(env, v);
			return;
		}

		if(doLockBucket && (type&UNIQUE) > 0) {

			SDMSThread t = null;
			if (env.maxWriter > 1 ) {
				t = (SDMSThread)Thread.currentThread();
				if (t.lockThread != null) t = t.lockThread;
			}

			SDMSObject old;
			long checkPoint = env.newLockCp();

			Object va[];
			synchronized(v) {
				va = v.toArray();
			}

			HashSet versionsChecked = new HashSet();
			for (int i = 0; i < va.length; ++i) {
				old = (SDMSObject) va[i];
				SDMSVersions ov = old.versions;

				if (env.maxWriter > 1) {
					LockingSystem.lock(env, ov, ((SDMSThread)Thread.currentThread()).readLock);
				}

				if (!old.isCurrent) {

					if (env.maxWriter > 1) {

						old = ov.getRaw(env, true);
						if (old != null) {

							synchronized(v) {
								if (! v.contains(old))
									old = null;
							}
						}
					}
				}

				if (old != null && old.isCurrent) {

					synchronized (v) {
						v.modCnt --;<commit_msg>bugfix: prevent incorrect "non-current object" error messages<commit_after>/*
Copyright (c) 2000-2013 "independIT Integrative Technologies GmbH",
Authors: <NAME>, <NAME>

schedulix Enterprise Job Scheduling System

independIT Integrative Technologies GmbH [http://www.independit.de]
mailto:<EMAIL>

This file is part of schedulix

schedulix is free software: 
you can redistribute it and/or modify it under the terms of the 
GNU Affero General Public License as published by the 
Free Software Foundation, either version 3 of the License, 
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.independit.scheduler.server.repository;

import java.lang.*;
import java.util.*;
import java.io.*;

import de.independit.scheduler.server.*;
import de.independit.scheduler.server.exception.*;
import de.independit.scheduler.server.output.*;
import de.independit.scheduler.server.util.*;
import de.independit.scheduler.server.locking.*;

public class SDMSIndex
{

	public final static String __version = "@(#) $Id: SDMSIndex.java,v 2.7.2.3 2013/06/07 18:48:36 dieter Exp $";

	public static final int ORDINARY = 0;

	public static final int UNIQUE   = 1;

	public static final int IDUNIQUE = 3;

	private SDMSIndexMap hashMap;
	private int type;
	private boolean isVersioned;

	public SDMSTable table;
	public String indexName;

	private static final Comparator objectIdComparator = new ObjectIdComparator();

	public SDMSIndex (SystemEnvironment env, int t, boolean versioned, SDMSTable table, String indexName)
	throws SDMSException
	{
		if(t != ORDINARY &&
		   t != UNIQUE   &&
		   t != IDUNIQUE) {
			throw new FatalException(new SDMSMessage(env,
						"03110181526", "Invalid Indextype $1", new Integer(t)));

		}
		this.table = table;
		this.indexName = indexName;
		hashMap = new SDMSIndexMap(this);
		type = t;
		isVersioned = versioned;
	}

	public void put (SystemEnvironment env, Object key, SDMSObject o)
		throws SDMSException
	{
		put (env, key, o, true);
	}

	public void put (SystemEnvironment env, Object key, SDMSObject o, boolean doLockBucket)
		throws SDMSException
	{
		SDMSIndexBucket v = null;
		synchronized(hashMap) {
			v = (SDMSIndexBucket) hashMap.get(key);
			if(v == null) {
				v = new SDMSIndexBucket(this, key);
				synchronized(v) {
					v.modCnt ++;
				}
				hashMap.put(key, v);
			} else
				synchronized(v) {
					v.modCnt ++;
				}
		}

		if (env.maxWriter > 1 && doLockBucket) {
			try {
				LockingSystem.lock(env, v, ObjectLock.EXCLUSIVE);
			} catch (Exception e) {
				synchronized(v) {
					v.modCnt --;
				}
				throw e;
			}
		}

		boolean newBucket = false;
		synchronized (v) {
			if (v.size() == 0) {
				v.add(o);
				v.modCnt --;
				newBucket = true;
			}
		}
		if (newBucket) {
			if (env.maxWriter > 1)
				LockingSystem.release(env, v);
			return;
		}

		if(doLockBucket && (type&UNIQUE) > 0) {

			SDMSThread t = null;
			if (env.maxWriter > 1 ) {
				t = (SDMSThread)Thread.currentThread();
				if (t.lockThread != null) t = t.lockThread;
			}

			SDMSObject old;
			long checkPoint = env.newLockCp();

			Object va[];
			synchronized(v) {
				va = v.toArray();
			}

			HashSet versionsChecked = new HashSet();
			for (int i = 0; i < va.length; ++i) {
				old = (SDMSObject) va[i];
				SDMSVersions ov = old.versions;

				if (env.maxWriter > 1) {
					LockingSystem.lock(env, ov, ((SDMSThread)Thread.currentThread()).readLock);
				}

				if (!old.isCurrent) {

					if (env.maxWriter > 1) {

						old = ov.getRaw(env, true);
						if (old != null) {

							synchronized(v) {
								if (! v.contains(old))
									old = null;
							}
						}
					}
				}

				if (old != null && old.isCurrent && o.isCurrent) {

					synchronized (v) {
						v.modCnt --;
{'fraction_non_alphanumeric': 0.1153987956249232, 'fraction_numerical': 0.012289541600098316, 'mean_word_length': 3.1711942593541775, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, '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': '1993063', 'n_tokens_mistral': 3296, 'n_tokens_neox': 2720, 'n_words': 805}