<commit_before>package ragnardb.plugin;

import gw.lang.reflect.*;
import gw.lang.reflect.java.JavaTypes;
import ragnardb.runtime.*;

import java.io.IOException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SQLTypeInfo extends BaseTypeInfo {
  private List<IPropertyInfo> _propertiesList;
  private Map<String, IPropertyInfo> _propertiesMap;
  private MethodList _methodList;
  private List<IConstructorInfo> _constructorList;

  public SQLTypeInfo(ISqlTableType type) {
    super(type);
    resolveProperties(type);
  }

  public SQLTypeInfo(ISqlDdlType type) {
    super(type);
    resolveProperties(type);
  }

  private void resolveProperties(ISqlTableType type) {
    _propertiesList = new ArrayList<>();
    _propertiesMap = new HashMap<>();

    List<ColumnDefinition> columns = type.getColumnDefinitions();
    for(ColumnDefinition column : columns) {
      SQLColumnPropertyInfo prop = new SQLColumnPropertyInfo(column.getColumnName(), column.getPropertyName(),
          getGosuType(column.getSQLType()), this, column.getOffset(), column.getLength());
      _propertiesMap.put(prop.getName(), prop);
      _propertiesList.add( prop );
      _methodList = createMethodInfos();
      _constructorList = createConstructorInfos();
    }
  }

  private List<IConstructorInfo> createConstructorInfos() {
    List<IConstructorInfo> L = new ArrayList<>();

    IConstructorInfo constructorMethod = new ConstructorInfoBuilder()
            .withDescription( "Creates a new Table object" )
            .withParameters()
            .withConstructorHandler( ( args ) -> new SQLRecord( ((ISqlTableType)getOwnersType()).getTable().getTableName(),
                                                                "id" ) ).build( this );

    L.add( constructorMethod );

    return L;

  }

  /**
   * ISqlDdlType will have a single getter, SqlSource : String
   * @param type ISqlDdlType
   */
  private void resolveProperties(ISqlDdlType type) {
    _propertiesList = new ArrayList<>();
    _propertiesMap = new HashMap<>();

    IPropertyInfo prop = new PropertyInfoBuilder()
        .withName("SqlSource")
        .withDescription("Returns the source of this ISqlDdlType")
        .withStatic()
        .withWritable(false)
        .withType(JavaTypes.STRING())
        .withAccessor(new IPropertyAccessor() {
          @Override
          public Object getValue( Object ctx ) {
            try {
              return ((ISqlDdlType) getOwnersType()).getSqlSource();
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }

          @Override
          public void setValue( Object ctx, Object value ) {
            throw new IllegalStateException("Calling setter on readonly property");
          }
        })
        .build(this);

    _propertiesMap.put(prop.getName(), prop);
    _propertiesList.add( prop );
  }<commit_msg>Accomodate gosu-custom-types-plugin by providing empty list of constructors and methods for DdlTypes<commit_after>package ragnardb.plugin;

import gw.lang.reflect.*;
import gw.lang.reflect.java.JavaTypes;
import ragnardb.runtime.*;

import java.io.IOException;
import java.sql.Types;
import java.util.*;

public class SQLTypeInfo extends BaseTypeInfo {
  private List<IPropertyInfo> _propertiesList;
  private Map<String, IPropertyInfo> _propertiesMap;
  private MethodList _methodList;
  private List<IConstructorInfo> _constructorList;

  public SQLTypeInfo(ISqlTableType type) {
    super(type);
    decorateDdlType(type);
  }

  public SQLTypeInfo(ISqlDdlType type) {
    super(type);
    decorateDdlType(type);
  }

  private void decorateDdlType( ISqlTableType type ) {
    _propertiesList = new ArrayList<>();
    _propertiesMap = new HashMap<>();

    List<ColumnDefinition> columns = type.getColumnDefinitions();
    for(ColumnDefinition column : columns) {
      SQLColumnPropertyInfo prop = new SQLColumnPropertyInfo(column.getColumnName(), column.getPropertyName(),
          getGosuType(column.getSQLType()), this, column.getOffset(), column.getLength());
      _propertiesMap.put(prop.getName(), prop);
      _propertiesList.add( prop );
      _methodList = createMethodInfos();
      _constructorList = createConstructorInfos();
    }
  }

  private List<IConstructorInfo> createConstructorInfos() {
    List<IConstructorInfo> L = new ArrayList<>();

    IConstructorInfo constructorMethod = new ConstructorInfoBuilder()
            .withDescription( "Creates a new Table object" )
            .withParameters()
            .withConstructorHandler(( args ) -> new SQLRecord(((ISqlTableType) getOwnersType()).getTable().getTableName(),
                "id")).build(this);

    L.add( constructorMethod );

    return L;

  }

  /**
   * ISqlDdlType will have a single getter, SqlSource : String
   * @param type ISqlDdlType
   */
  private void decorateDdlType( ISqlDdlType type ) {
    _propertiesList = new ArrayList<>();
    _propertiesMap = new HashMap<>();

    IPropertyInfo prop = new PropertyInfoBuilder()
        .withName("SqlSource")
        .withDescription("Returns the source of this ISqlDdlType")
        .withStatic()
        .withWritable(false)
        .withType(JavaTypes.STRING())
        .withAccessor(new IPropertyAccessor() {
          @Override
          public Object getValue( Object ctx ) {
            try {
              return ((ISqlDdlType) getOwnersType()).getSqlSource();
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }

          @Override
          public void setValue( Object ctx, Object value ) {
            throw new IllegalStateException("Calling setter on readonly property");
          }
        })
        .build(this);

    _propertiesMap.put(prop.getName(), prop);
    _propertiesList.add(prop);
    _methodList = new MethodList();
    _constructorList = Collections.emptyList();
  }
{'fraction_non_alphanumeric': 0.10443514644351465, 'fraction_numerical': 0.0, 'mean_word_length': 3.048780487804878, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6610528', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1603, 'n_words': 377}