<commit_before>/* Generated By:JJTree: Do not edit this line. OAlterPropertyStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.sql.executor.OInternalResultSet;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;

public class OAlterPropertyStatement extends ODDLStatement {

  OIdentifier className;

  OIdentifier propertyName;
  OIdentifier customPropertyName;
  OExpression customPropertyValue;

  OIdentifier settingName;
  public OExpression settingValue;

  public OAlterPropertyStatement(int id) {
    super(id);
  }

  public OAlterPropertyStatement(OrientSql p, int id) {
    super(p, id);
  }

  @Override
  public OResultSet executeDDL(OCommandContext ctx) {
    ODatabase db = ctx.getDatabase();
    OClass clazz = db.getMetadata().getSchema().getClass(className.getStringValue());

    if (clazz == null) {
      throw new OCommandExecutionException("Invalid class name or class not found: " + clazz);
    }

    OProperty property = clazz.getProperty(propertyName.getStringValue());
    if (property == null) {
      throw new OCommandExecutionException("Property " + property + " not found on class " + clazz);
    }

    OResultInternal result = new OResultInternal();
    result.setProperty("class", className.getStringValue());
    result.setProperty("property", propertyName.getStringValue());

    if (customPropertyName != null) {
      String customName = customPropertyName.getStringValue();
      Object oldValue = property.getCustom(customName);
      Object finalValue = customPropertyValue.execute((OIdentifiable) null, ctx);
      property.setCustom(customName, finalValue == null ? null : "" + finalValue);

      result.setProperty("operation", "alter property custom");
      result.setProperty("customAttribute", customPropertyName.getStringValue());
      result.setProperty("oldValue", oldValue != null ? oldValue.toString() : null);
      result.setProperty("newValue", finalValue != null ? finalValue.toString() : null);
    } else {
      String setting = settingName.getStringValue();
      Object finalValue = settingValue.execute((OIdentifiable) null, ctx);

      OProperty.ATTRIBUTES attribute;
      try {
        attribute = OProperty.ATTRIBUTES.valueOf(setting.toUpperCase(Locale.ENGLISH));
      } catch (IllegalArgumentException e) {
        throw OException.wrapException(new OCommandExecutionException(
            "Unknown property attribute '" + setting + "'. Supported attributes are: " + Arrays
                .toString(OProperty.ATTRIBUTES.values())), e);
      }
      Object oldValue = property.get(attribute);<commit_msg>Fix ALTER PROPERTY with "name" to work also without quotes<commit_after>/* Generated By:JJTree: Do not edit this line. OAlterPropertyStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.sql.executor.OInternalResultSet;
import com.orientechnologies.orient.core.sql.executor.OResultInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;

public class OAlterPropertyStatement extends ODDLStatement {

  OIdentifier className;

  OIdentifier propertyName;
  OIdentifier customPropertyName;
  OExpression customPropertyValue;

  OIdentifier settingName;
  public OExpression settingValue;

  public OAlterPropertyStatement(int id) {
    super(id);
  }

  public OAlterPropertyStatement(OrientSql p, int id) {
    super(p, id);
  }

  @Override
  public OResultSet executeDDL(OCommandContext ctx) {
    ODatabase db = ctx.getDatabase();
    OClass clazz = db.getMetadata().getSchema().getClass(className.getStringValue());

    if (clazz == null) {
      throw new OCommandExecutionException("Invalid class name or class not found: " + clazz);
    }

    OProperty property = clazz.getProperty(propertyName.getStringValue());
    if (property == null) {
      throw new OCommandExecutionException("Property " + property + " not found on class " + clazz);
    }

    OResultInternal result = new OResultInternal();
    result.setProperty("class", className.getStringValue());
    result.setProperty("property", propertyName.getStringValue());

    if (customPropertyName != null) {
      String customName = customPropertyName.getStringValue();
      Object oldValue = property.getCustom(customName);
      Object finalValue = customPropertyValue.execute((OIdentifiable) null, ctx);
      property.setCustom(customName, finalValue == null ? null : "" + finalValue);

      result.setProperty("operation", "alter property custom");
      result.setProperty("customAttribute", customPropertyName.getStringValue());
      result.setProperty("oldValue", oldValue != null ? oldValue.toString() : null);
      result.setProperty("newValue", finalValue != null ? finalValue.toString() : null);
    } else {
      String setting = settingName.getStringValue();
      Object finalValue = settingValue.execute((OIdentifiable) null, ctx);
      if (finalValue == null && (setting.equalsIgnoreCase("name") || setting.equalsIgnoreCase("shortname"))) {
        finalValue = settingValue.toString();
        String stringFinalValue = (String) finalValue;
        if (stringFinalValue.startsWith("`") && stringFinalValue.endsWith("`") && stringFinalValue.length() > 2) {
          stringFinalValue = stringFinalValue.substring(1, stringFinalValue.length() - 1);
          finalValue = stringFinalValue;
        }
      }
      OProperty.ATTRIBUTES attribute;
      try {
        attribute = OProperty.ATTRIBUTES.valueOf(setting.toUpperCase(Locale.ENGLISH));
      } catch (IllegalArgumentException e) {
        throw OException.wrapException(new OCommandExecutionException(
            "Unknown property attribute '" + setting + "'. Supported attributes are: " + Arrays
                .toString(OProperty.ATTRIBUTES.values())), e);
      }
      Object oldValue = property.get(attribute);
{'fraction_non_alphanumeric': 0.10736562707365627, 'fraction_numerical': 0.0009289980092899801, 'mean_word_length': 4.730798479087452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6207486', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2093, 'n_words': 402}