New Posts New Posts RSS Feed: Oracle 10 ID genaration how to?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Oracle 10 ID genaration how to?

 Post Reply Post Reply
Author
esharkin View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2010
Location: Other
Posts: 7
Post Options Post Options   Quote esharkin Quote  Post ReplyReply Direct Link To This Post Topic: Oracle 10 ID genaration how to?
    Posted: 26-Mar-2010 at 1:43am
Hello
Im try to make simpale hello dev force application in oracle and .net my version is 3.6.2
 
I read some PDF a bout IDGenration , Well in MSSQL all the things are easy and we do not need to do anything
But ...
Oracle use Sequance to Create ID Values and i dont know how to use it  in devfore any help please?
 
i was try to make Table as :

TBLSYSTEMTREE

and make

SEQTBLSYSTEMTREE

and something like

create or replace trigger USYSTEM.TRGIDTBLSYSTEMTREE

before insert on USYSTEM.TBLSYSTEMTREE FOR EACH ROW when (NEW.IDX is null)

BEGIN

select SEQTBLSYSTEMTREE.nextval into :NEW.idx from dual;

end;

but not working what should i do? 
Back to Top
esharkin View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2010
Location: Other
Posts: 7
Post Options Post Options   Quote esharkin Quote  Post ReplyReply Direct Link To This Post Posted: 26-Mar-2010 at 3:38am

maybe this question is funny but remmamber this is Getting Started Section.

Also I cant undestand why show me "Unable to locate a valid IdGenerator"?
if devforce ,Force select after insert and update is it possible to know why show me this error?
 
pressist manager make its storage and virtual IDs after insert its fire up trriger and select read data from DB and pressist manager is updated seems with vaid ID come from sequance , absolutly relational DevForce storage can be sync , i cant understand why it show me error and what is MSSQL give deveforce for ID genaration .
 
the problem whit sequance class that ship with product is use one mathod and one sequance so i have lot of lost number and have to use big intigers.
i think if i can define schema for each seuance 99% problam is solved. how can i do this please...
 
If i make sequance string and call it staticly for (Selecting from dual) im not sure this will workoffline.
 
Thank you.


Edited by esharkin - 27-Mar-2010 at 11:20am
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 30-Mar-2010 at 10:37am
You can use a custom IdGenerator.  We don't have a custom Oracle IdGenerator for WinClient, but you might want to look at the one for DevForce Classic which I have supplied below.  Look at both the example custom IdGenerator for WinClient in the Learning Resouirces and the custom Oracle IdGenerator below to understand how you might build your own custom Oracle IdGenerator for WinClient.
 
Back to Top
esharkin View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2010
Location: Other
Posts: 7
Post Options Post Options   Quote esharkin Quote  Post ReplyReply Direct Link To This Post Posted: 30-Mar-2010 at 11:30am

As  davidklitzke Say I can use Oracle ID Generation  Class , I have Made Some Changes to the Class and customize it more.

I make Bold Something You may want to change .  

/// <changelog>

///   <item who="jtraband" when="May-09-2002">Created</item>

///   <item who="jtraband" when="Mar-03-2003">Updated for new IIdGenerator signatures</item>

/// </changelog>

 

using System;

using System.Collections;

using System.Data;

using System.Data.Common;

using System.Data.OleDb;

using System.Data.SqlClient;

using System.Diagnostics;

 

using IdeaBlade.Util;

using IdeaBlade.Rdb;

using IdeaBlade.Persistence;

using System.Collections.Generic;

 

namespace MyEntity

{

    // Remember to set the namespace appropriately!

 

    [Serializable]

    public class OracleSequenceIdGenerator : IIdGenerator

    {

 

        public OracleSequenceIdGenerator() { }

        private static string StrSchemaSequance;

 

        /// <summary>

        /// Generates a new temporary id for a specified DataColumn

        /// Executed on the client only.

        /// </summary>

        /// <param name="pColumn">RdbColumn for which a new id should be generated</param>

        /// <returns>A new temporary id</returns>

        public object GetNextTempId(EntityColumn pColumn)

        {

            Object id = (int)-1 * (mTempIds.Count + 1);

            Decimal decimalId = System.Convert.ToDecimal(id);

            mTempIds.Add(new UniqueId(pColumn, decimalId));

            return decimalId;

        }

 

        /// <summary>

        /// Determines whether a given id is a temporary id

        /// Executed on the client only.

        /// </summary>

        /// <param name="pUniqueId">Id to be analyzed</param>

        /// <returns>true if the id is temporary; otherwise false</returns>

        public bool IsTempId(UniqueId pUniqueId)

        {

            Decimal id = (Decimal)pUniqueId.Value;

            return (id < 0);

        }

 

        /// <summary>

        /// Returns the temporary ids generated since instantiation of this class or the last reset

        /// Executed on the client only.

        /// </summary>

        public UniqueIdCollection TempIds

        {

            get { return mTempIds; }

        }

 

        /// <summary>

        /// Reset temporary id generation back to initial state.

        /// Executed on the client only.

        /// *** Do not call this method if there are any pending temporary ids! ***

        /// </summary>

        public void Reset()

        {

            mTempIds.Clear();

        }

 

        /// <summary>

        /// Returns a dictionary that maps temporary ids to real ids; key = temporary id; value = real id

        /// *** Executed on the server-side by the IdeaBlade PersistenceServer ***

        /// </summary>

        /// <remarks>

        /// The requesting client-side PersistenceManager uses the returned map

        /// to replace all occurrences of each temporary id (including foreign key references) with its

        /// corresponding permanent (real) id.

        /// </remarks>

        /// <param name="pTempIds">Temporary ids (from client) to map to permanent (real) ids</param>

        /// <param name="pAdoHelper">Provides ADO access to the database of this PersistenceServer</param>

        /// <returns>An IdeaBlade UniqueIdMap, pairs of {TempIds, PermIds}</returns>

 

        // This method will only be called from the PersistenceServer;

        public UniqueIdMap GetRealIdMap(UniqueIdCollection pTempIds, IDataSourceKey pDataSourceKey)

        {

            UniqueIdMap idMap = new UniqueIdMap();

            RdbKey aRdbKey = pDataSourceKey as RdbKey;

            mAdoHelper = aRdbKey.AdoHelper;

            IList<Decimal> nextIds = GetNextIds(mAdoHelper, pTempIds.Count);

            int index = 0;

            object nextId;

            foreach (UniqueId aUniqueId in pTempIds)

            {

                if (aUniqueId.Column.DataType == typeof(int))

                {

                    nextId = Convert.ToInt32(nextIds[index]);

                } if (aUniqueId.Column.DataType == typeof(Decimal))

                {

                    nextId = Convert.ToDecimal(nextIds[index]);

                }

                else

                {

                    nextId = nextIds[index];

                }

                index++;

                idMap.Add(aUniqueId, nextId);

            }

            return idMap;

        }

 

        public bool IsApplicable(IDataSourceKey pDsKey)

        {

            return true;

        }

 

        public static string SequanceSchema

        {

            set { StrSchemaSequance = value; }

            get { return StrSchemaSequance; }

        }

 

        //***********************************

        // Private & Protected

        //***********************************

 

        private IList<Decimal> GetNextIds(AdoHelper pAdoHelper, int pCount)

        {

            String sqlSelect = string.Empty;

 

 

            sqlSelect = "SELECT " + StrSchemaSequance + ".NEXTVAL FROM DUAL";

           

 

            List<Decimal> results = new List<Decimal>();

            IDbConnection aConnection = pAdoHelper.CreateDbConnection(true);

            using (aConnection)

            {

                aConnection.Open();

                IDbCommand aCommand = mAdoHelper.CreateDbCommand(aConnection);

                aCommand.CommandText = sqlSelect;

                for (int i = 0; i < pCount; i++)

                {

                    Decimal nextId = (Decimal)aCommand.ExecuteScalar();

                    results.Add(nextId);

                }

            }

            return results;

        }

 

        private UniqueIdCollection mTempIds = new UniqueIdCollection(); // Temporary Ids

 

        [NonSerialized]

        private AdoHelper mAdoHelper;

 

    }

}

 

 

OK that is fine now, I add it to the Entity Project.

New I can call it from Create Method for Call Insert for example:

 

public static TBLTREE Create(PersistenceManager p, int Idxparent, string Title, int Isform, string Asmname,string Formname, int Isuniq)

    {

        TBLSYSTEMTREE a = (TBLSYSTEMTREE)p.CreateEntity(typeof(TBLSYSTEMTREE));

        MyEntity.OracleSequenceIdGenerator.SequanceSchema = "USYSTEM.IDGENERATORSEQUENCE";

        p.GenerateId(a, TBLSYSTEMTREE.IdxEntityColumn);

        a.AddToManager();       

        a.Title = Title;

        a.Isform = 0;

        a.Asmname = "[test]";

        a.Formname = "[no]";

        a.Isuniq=0;       

        return a;

       

    }

   

You know what is "USYSTEM.IDGENERATORSEQUENCE”yes my Sequance in Oracle Server.

Usystem is Schema for User name “usystem” something like :

CREATE USER usystem

IDENTIFIED BY <Enter User Password Here>

DEFAULT TABLESPACE

TEMPORARY TABLESPACE

 

And sequance can me make in this Schema:

CREATE SEQUENCE USYSTEM.IDGENERATOR_SEQUENCE

  INCREMENT BY 1

  START WITH 10

  MINVALUE 1

  MAXVALUE 999999999999999999999999999

  NOCYCLE

  NOORDER

  CACHE 20

 

 That will work but i want more about when Devforce go from offline to online mode and id mapping, semms it is hard to think how it can work In online transactional system , however I think it might be handel with trigger also small number of records should be added in offline mode, so it might be optional to select statagy from triger or genarator class. Any idea?

Thanks

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down