// $LastChangedRevision: 4748 $ DO NOT EDIT.  Make changes to WiwoUser.java instead.
package mildo.wiwo.data;

import com.webobjects.eoaccess.*;
import com.webobjects.eocontrol.*;
import com.webobjects.foundation.*;
import java.math.*;
import java.util.*;

public abstract class _WiwoUser extends  EOGenericRecord {
	public static final String ENTITY_NAME = "WiwoUser";

	// Attributes
	public static final String LAST_LOGIN_KEY = "lastLogin";
	public static final String LOGIN_KEY = "login";
	public static final String PASSWORD_KEY = "password";
	public static final String USER_ROLE_KEY = "userRole";

	// Relationships
	public static final String USER_PAGES_KEY = "userPages";
	public static final String WIWO_NAME_SPACES_KEY = "wiwoNameSpaces";

  public WiwoUser localInstanceOfWiwoUserIn(EOEditingContext editingContext) {
    WiwoUser localInstance = (WiwoUser)EOUtilities.localInstanceOfObject(editingContext, this);
    if (localInstance == null) {
      throw new IllegalStateException("You attempted to localInstance " + this + ", which has not yet committed.");
    }
    return localInstance;
  }

  public NSTimestamp lastLogin() {
    return (NSTimestamp) storedValueForKey("lastLogin");
  }

  public void setLastLogin(NSTimestamp value) {
    takeStoredValueForKey(value, "lastLogin");
  }

  public String login() {
    return (String) storedValueForKey("login");
  }

  public void setLogin(String value) {
    takeStoredValueForKey(value, "login");
  }

  public String password() {
    return (String) storedValueForKey("password");
  }

  public void setPassword(String value) {
    takeStoredValueForKey(value, "password");
  }

  public String userRole() {
    return (String) storedValueForKey("userRole");
  }

  public void setUserRole(String value) {
    takeStoredValueForKey(value, "userRole");
  }

  public NSArray userPages() {
    return (NSArray)storedValueForKey("userPages");
  }

  public NSArray userPages(EOQualifier qualifier) {
    return userPages(qualifier, null, false);
  }

  public NSArray userPages(EOQualifier qualifier, boolean fetch) {
    return userPages(qualifier, null, fetch);
  }

  public NSArray userPages(EOQualifier qualifier, NSArray sortOrderings, boolean fetch) {
    NSArray results;
    if (fetch) {
      EOQualifier fullQualifier;
      EOQualifier inverseQualifier = new EOKeyValueQualifier(mildo.wiwo.data.WiwoPage.USER_KEY, EOQualifier.QualifierOperatorEqual, this);
    	
      if (qualifier == null) {
        fullQualifier = inverseQualifier;
      }
      else {
        NSMutableArray qualifiers = new NSMutableArray();
        qualifiers.addObject(qualifier);
        qualifiers.addObject(inverseQualifier);
        fullQualifier = new EOAndQualifier(qualifiers);
      }

      results = mildo.wiwo.data.WiwoPage.fetchWiwoPages(editingContext(), fullQualifier, sortOrderings);
    }
    else {
      results = userPages();
      if (qualifier != null) {
        results = (NSArray)EOQualifier.filteredArrayWithQualifier(results, qualifier);
      }
      if (sortOrderings != null) {
        results = (NSArray)EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
      }
    }
    return results;
  }
  
  public void addToUserPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    addObjectToBothSidesOfRelationshipWithKey(object, "userPages");
  }

  public void removeFromUserPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "userPages");
  }

  public mildo.wiwo.data.WiwoPage createUserPagesRelationship() {
    EOClassDescription eoClassDesc = EOClassDescription.classDescriptionForEntityName("WiwoPage");
    EOEnterpriseObject eo = eoClassDesc.createInstanceWithEditingContext(editingContext(), null);
    editingContext().insertObject(eo);
    addObjectToBothSidesOfRelationshipWithKey(eo, "userPages");
    return (mildo.wiwo.data.WiwoPage) eo;
  }

  public void deleteUserPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "userPages");
    editingContext().deleteObject(object);
  }

  public void deleteAllUserPagesRelationships() {
    Enumeration objects = userPages().immutableClone().objectEnumerator();
    while (objects.hasMoreElements()) {
      deleteUserPagesRelationship((mildo.wiwo.data.WiwoPage)objects.nextElement());
    }
  }

  public NSArray wiwoNameSpaces() {
    return (NSArray)storedValueForKey("wiwoNameSpaces");
  }

  public NSArray wiwoNameSpaces(EOQualifier qualifier) {
    return wiwoNameSpaces(qualifier, null);
  }

  public NSArray wiwoNameSpaces(EOQualifier qualifier, NSArray sortOrderings) {
    NSArray results;
      results = wiwoNameSpaces();
      if (qualifier != null) {
        results = (NSArray)EOQualifier.filteredArrayWithQualifier(results, qualifier);
      }
      if (sortOrderings != null) {
        results = (NSArray)EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
      }
    return results;
  }
  
  public void addToWiwoNameSpacesRelationship(mildo.wiwo.data.WiwoNameSpace object) {
    addObjectToBothSidesOfRelationshipWithKey(object, "wiwoNameSpaces");
  }

  public void removeFromWiwoNameSpacesRelationship(mildo.wiwo.data.WiwoNameSpace object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "wiwoNameSpaces");
  }

  public mildo.wiwo.data.WiwoNameSpace createWiwoNameSpacesRelationship() {
    EOClassDescription eoClassDesc = EOClassDescription.classDescriptionForEntityName("WiwoNameSpace");
    EOEnterpriseObject eo = eoClassDesc.createInstanceWithEditingContext(editingContext(), null);
    editingContext().insertObject(eo);
    addObjectToBothSidesOfRelationshipWithKey(eo, "wiwoNameSpaces");
    return (mildo.wiwo.data.WiwoNameSpace) eo;
  }

  public void deleteWiwoNameSpacesRelationship(mildo.wiwo.data.WiwoNameSpace object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "wiwoNameSpaces");
    editingContext().deleteObject(object);
  }

  public void deleteAllWiwoNameSpacesRelationships() {
    Enumeration objects = wiwoNameSpaces().immutableClone().objectEnumerator();
    while (objects.hasMoreElements()) {
      deleteWiwoNameSpacesRelationship((mildo.wiwo.data.WiwoNameSpace)objects.nextElement());
    }
  }


  public static WiwoUser createWiwoUser(EOEditingContext editingContext, String login
, String password
, String userRole
) {
    WiwoUser eo = (WiwoUser) EOUtilities.createAndInsertInstance(editingContext, _WiwoUser.ENTITY_NAME);    
		eo.setLogin(login);
		eo.setPassword(password);
		eo.setUserRole(userRole);
    return eo;
  }

  public static NSArray fetchAllWiwoUsers(EOEditingContext editingContext) {
    return _WiwoUser.fetchAllWiwoUsers(editingContext, null);
  }

  public static NSArray fetchAllWiwoUsers(EOEditingContext editingContext, NSArray sortOrderings) {
    return _WiwoUser.fetchWiwoUsers(editingContext, null, sortOrderings);
  }

  public static NSArray fetchWiwoUsers(EOEditingContext editingContext, EOQualifier qualifier, NSArray sortOrderings) {
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_WiwoUser.ENTITY_NAME, qualifier, sortOrderings);
    fetchSpec.setIsDeep(true);
    NSArray eoObjects = (NSArray)editingContext.objectsWithFetchSpecification(fetchSpec);
    return eoObjects;
  }

  public static WiwoUser fetchWiwoUser(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoUser.fetchWiwoUser(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

  public static WiwoUser fetchWiwoUser(EOEditingContext editingContext, EOQualifier qualifier) {
    NSArray eoObjects = _WiwoUser.fetchWiwoUsers(editingContext, qualifier, null);
    WiwoUser eoObject;
    int count = eoObjects.count();
    if (count == 0) {
      eoObject = null;
    }
    else if (count == 1) {
      eoObject = (WiwoUser)eoObjects.objectAtIndex(0);
    }
    else {
      throw new IllegalStateException("There was more than one WiwoUser that matched the qualifier '" + qualifier + "'.");
    }
    return eoObject;
  }

  public static WiwoUser fetchRequiredWiwoUser(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoUser.fetchRequiredWiwoUser(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

  public static WiwoUser fetchRequiredWiwoUser(EOEditingContext editingContext, EOQualifier qualifier) {
    WiwoUser eoObject = _WiwoUser.fetchWiwoUser(editingContext, qualifier);
    if (eoObject == null) {
      throw new NoSuchElementException("There was no WiwoUser that matched the qualifier '" + qualifier + "'.");
    }
    return eoObject;
  }

  public static WiwoUser localInstanceOfWiwoUserIn(EOEditingContext editingContext, WiwoUser eo) {
    WiwoUser localInstance = (eo == null) ? null : (WiwoUser)EOUtilities.localInstanceOfObject(editingContext, eo);
    if (localInstance == null && eo != null) {
      throw new IllegalStateException("You attempted to localInstance " + eo + ", which has not yet committed.");
    }
    return localInstance;
  }
}
