Package org.xBaseJ.micro.fields

Examples of org.xBaseJ.micro.fields.Field


   */

  public void addField(Field aField)
    throws xBaseJException, IOException
  {
    Field bField[] = new Field[1];
    bField[0] = aField;
    addField(bField);

  }
View Full Code Here


      { if ((fldcount + aField.length) > 255)
         throw new xBaseJException("Number of fields exceed limit of 255.  New Field count is " + (fldcount + aField.length));
      }

    int i, j;
    Field tField;

    boolean oldMemo = false;
    for (j = 0; j < aField.length; j++)
    {
      for (i = 1; i <= fldcount; i++)
      {
        tField = getField(i);
          if (tField instanceof MemoField || tField instanceof PictureField)
             oldMemo = true;
        if (aField[j].getName().equalsIgnoreCase(tField.getName()))
          throw new xBaseJException("Field: " + aField[j].getName() + " already exists.");
      }
    }

    short newRecl = lrecl;
    boolean newMemo = false;

    for (j = 1; j <= aField.length; j++)
    {
      newRecl += aField[j-1].getLength();
      if ((dbtobj == null) &&
             ((aField[j-1] instanceof MemoField) || (aField[j-1] instanceof PictureField)))
        newMemo = true;
      if (aField[j-1] instanceof PictureField)
          version = FOXPRO_WITH_MEMO;
      else if ( (aField[j-1] instanceof MemoField) &&
                (
            ((MemoField) aField[j-1]).isFoxPro()
            )
            )
          version = FOXPRO_WITH_MEMO;
    }

    if (newRecl > 4000)
      throw new xBaseJException("Record length of 4000 exceeded.  New calculated length is " + newRecl);

    boolean createTemp = false;
    DBF tempDBF = null;
    String newName = "";

    if (fldcount > 0) createTemp = true;

    if (createTemp)
    {

          Random r = new Random();
        while (true){


            int ir  =  r.nextInt();
            if (ir < 1000  || ir > 9999999)
                continue;
            newName = ir+".dbf";
            File f = new File(newName);
            if (f.exists() == false)
                break;
        // as of 12/27/2005



      //pos = dosname.toUpperCase().lastIndexOf(".DBF");
      //newName = new String(dosname.substring(0, pos) + ".tmd");
      int format = version;
      if ((format == DBASEIII) && (MDX_exist == 1))
        format = DBASEIV;

      tempDBF = new DBF(newName, format, true);



      tempDBF.version = (byte) format;
      tempDBF.MDX_exist = MDX_exist;

    }


    if (newMemo)
      {
      if (createTemp)
             {
             if (( version == DBASEIII || version == DBASEIII_WITH_MEMO) && (MDX_exist == 0))
                 tempDBF.dbtobj = new DBT_iii(this, newName, true);
           else
             if ( version == FOXPRO_WITH_MEMO)
                 tempDBF.dbtobj = new DBT_fpt(this, newName, true);
           else
                 tempDBF.dbtobj = new DBT_iv(this, newName, true);
             }
          else
      {
           if ((version == DBASEIII ||version == DBASEIII_WITH_MEMO) &&(MDX_exist == 0))
          dbtobj = new DBT_iii(this, dosname, true);
           else
             if (version == FOXPRO_WITH_MEMO)
                dbtobj = new DBT_fpt(this, dosname, true);
           else
        dbtobj = new DBT_iv(this, dosname, true);
         }
         }
         else if (createTemp && oldMemo)
             {
             if (( version == DBASEIII || version == DBASEIII_WITH_MEMO) && (MDX_exist == 0))
                 tempDBF.dbtobj = new DBT_iii(this, newName, true);
           else
             if ( version == FOXPRO_WITH_MEMO)
                 tempDBF.dbtobj = new DBT_fpt(this, newName, true);
           else
                 tempDBF.dbtobj = new DBT_iv(this, newName, true);
       }



    if (createTemp)
    {
      tempDBF.db_offset(version, newMemo||(dbtobj!=null));
      tempDBF.update_dbhead();
      tempDBF.offset = offset;
      tempDBF.lrecl = newRecl;
      tempDBF.fldcount = fldcount;


           for (i=1; i<=fldcount;i++) {
        try {
          tField = (Field) getField(i).clone();
        }
        catch (CloneNotSupportedException e)
        {

          throw new xBaseJException("Clone not supported logic error");
        }
        if (tField instanceof MemoField)
          ((MemoField) tField).setDBTObj(tempDBF.dbtobj);
        if (tField instanceof PictureField)
          ((PictureField) tField).setDBTObj(tempDBF.dbtobj);
        tField.setFile(tempDBF.file);
        tempDBF.fld_root.addElement(tField);
        tempDBF.write_Field_header(tField);
      }

      for (i=0; i<aField.length;i++) {
        aField[i].setFile(tempDBF.file);
        tempDBF.fld_root.addElement(aField[i]);
        tempDBF.write_Field_header(aField[i]);
        tField = (Field) aField[i];
        if (tField instanceof MemoField)
          ((MemoField) tField).setDBTObj(tempDBF.dbtobj);
        if (tField instanceof PictureField)
          ((PictureField) tField).setDBTObj(tempDBF.dbtobj);

      }

      tempDBF.file.writeByte(13);
      tempDBF.file.writeByte(26);
      tempDBF.fldcount += aField.length;
      tempDBF.offset += (aField.length * 32);
    }
    else
    {
      lrecl = newRecl;
      int savefldcnt = fldcount;
      fldcount += aField.length;
      offset += (32 * aField.length);
      if (newMemo) {
          if (dbtobj instanceof DBT_iii)
              version = DBASEIII_WITH_MEMO ;
                else if (dbtobj instanceof DBT_iv) // if it's not dbase 3 format make it at least dbaseIV format.
          version =  DBASEIV_WITH_MEMO;
        else if (dbtobj instanceof DBT_fpt) // if it's not foxpro format make it at least dbaseIV format.
          version =  FOXPRO_WITH_MEMO;
              }
      update_dbhead();

      for (i=1; i<=savefldcnt;i++) {
        tField = (Field) getField(i);
        if (tField instanceof MemoField)
          ((MemoField) tField).setDBTObj(dbtobj);
        if (tField instanceof PictureField)
          ((PictureField) tField).setDBTObj(tempDBF.dbtobj);
        write_Field_header(tField);
      }

      for (i=0; i<aField.length;i++)
                          {
        aField[i].setFile(file);
        tField = (Field) aField[i];
        if (tField instanceof MemoField)
          ((MemoField) tField).setDBTObj(dbtobj);
        if (tField instanceof PictureField) {
                   ((PictureField) tField).setDBTObj(dbtobj);
        }
        fld_root.addElement(aField[i]);
        write_Field_header(aField[i]);
                        }
      file.writeByte(13);
      file.writeByte(26);
      return// nothing left to do, no records to write
    }


    for (j=1; j<=count; j++)
    {
      Field old1;
      Field new1;
      gotoRecord(j);
      for (i=1; i<=fldcount; i++)
                          {
        old1 = getField(i);
        new1 = tempDBF.getField(i);
        new1.put(old1.get());
      }
      for (i=0; i<aField.length;i++)
                         {
                          new1 = aField[i];
                          new1.put("");
                         }

      tempDBF.write();
    }

View Full Code Here

public NodeKey build_key() throws xBaseJException
{

  NodeKey dataptr;
  int i;
  Field f;
  double doubleer = 0.0;
  switch (keyType)
   {
      case 'F':
        for (i = 0; i < keyControl.size(); i++)
         {
             f = (Field) keyControl.elementAt(i);
             if (f.get() == null);
             else if (f.get().length() == 0);
             else if (f.getType() == 'D')
                    doubleer +=  Util.doubleDate(f.get());
             else doubleer +=  Double.valueOf(f.get() ).doubleValue() ;
       }           /* endfor */
       dataptr = new NodeKey(new NodeFloat(doubleer));
        break;
     case 'N':
         for (i = 0; i < keyControl.size(); i++)
          {
              f = (Field) keyControl.elementAt(i);
              if (f.get() == null);
              else if (f.get().length() == 0);
              else if (f.getType() == 'D')
                     doubleer +=  Util.doubleDate(f.get());
              else doubleer +=  Double.valueOf(f.get() ).doubleValue() ;
        }           /* endfor */
        dataptr = new NodeKey(new Double(doubleer));
         break;
      default:
           StringBuffer sb = new StringBuffer();
           for (i = 0; i < keyControl.size(); i++)
                {
                  f = (Field) keyControl.elementAt(i);

                   sb.append(f.get());
                 /* endfor */
           dataptr = new NodeKey(new String(sb));
         break;
      }
  return dataptr;
View Full Code Here

  int reading;
  int i;
  String wb;
  Node lNode = null;
  int Index_record;
  Field Field = null;
  dosname = filename;
  database = indatabase;

  file = new File(filename);
View Full Code Here

  unique_key = (byte) (unique ? 64 : 0);
  while (strtok.hasMoreElements())
  {
    char type;
    tempch1 = (String) strtok.nextElement();
    Field Field = database.getField(tempch1);
    type = Field.getType();
     if (type == 'M')
  throw new xBaseJException("Can't make memo field part of a key");
      if (type == 'L')
  throw new xBaseJException("Can't make logical ield part of a key");
      if (type == 'F')
  throw new xBaseJException("Can't make float field part of a key");

    if (key_type == ' ')
      key_type = type;
    else
    if (key_type == 'D' && type == 'N')
      key_type = 'N';
    else
    if (key_type == 'N' && type == 'D')
      key_type = 'N';   // date key type really doesn't change
    else
    if (key_type != type)
  key_type = 'C';

     key_length += Field.getLength();
     keyControl.addElement(Field);
  }

  if (key_type == 'D' || key_type == 'N')
    {
View Full Code Here

    public void createPersonInfo() throws xBaseJException, IOException, ClipsException {
        openPersonInfo();
        personF = new PersonFields();
        try {
            for (int i = 0; i < personF.getFields().length; i++) {
                Field f = personF.getFields()[i];
                regPin.addField(f);
            }
        } catch (xBaseJException ex) {
            throw new ClipsException("Ошибка при чтении данных из файла " + regPin.getName(), ex);
        }
View Full Code Here

    public void createRecipeInfo() throws xBaseJException, IOException, ClipsException {
        openRecipeInfo();
        recipeF = new RecipeFields();
        try {
            for (int i = 0; i < recipeF.getFields().length; i++) {
                Field f = recipeF.getFields()[i];
                adPr.addField(f);
            }
        } catch (xBaseJException ex) {
            throw new ClipsException("Ошибка при чтении данных из файла " + adPr.getName(), ex);
        }
View Full Code Here

  public void dropField(Field aField)
    throws xBaseJException, IOException
  {
    int i;
    Field tField;
    for (i = 0; i < fldcount; i++)
    {
      tField = getField(i);
      if (aField.getName().equalsIgnoreCase(tField.getName()))
        break;
    }
    if (i > fldcount)
      throw new xBaseJException("Field: " + aField.getName() + " does not exist.");
  }
View Full Code Here

   */
  public void changeField(Field oldField, Field newField)
    throws xBaseJException, IOException
  {
    int i, j;
    Field tField;
    for (i = 0; i < fldcount; i++)
    {
      tField = getField(i);
      if (oldField.getName().equalsIgnoreCase(tField.getName()))
        break;
    }
    if (i > fldcount)
      throw new xBaseJException("Field: " + oldField.getName() + " does not exist.");

    for (j = 0; j < fldcount; j++)
    {
      tField = getField(j);
      if (newField.getName().equalsIgnoreCase(tField.getName()) && (j != i))
        throw new xBaseJException("Field: " + newField.getName() + " already exists.");
    }

  }
View Full Code Here

  public  void  gotoRecord(int recno) throws xBaseJException, IOException
  {
    /** goes to a specific record in the database */
    int i;
    Field tField;
    if ((recno > count) || (recno < 1) )
    {
      throw new xBaseJException("Invalid Record Number " + recno);
    }
    current_record = recno;

    seek(recno-1);

    delete_ind = file.readByte();
    for (i=0; i < fldcount; i++)
    {
      tField = (Field) fld_root.elementAt(i);
      tField.read();
    }

    Index NDXes;
    for (i=1; i<= jNDXes.size(); i++)
    {
View Full Code Here

TOP

Related Classes of org.xBaseJ.micro.fields.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.