Wednesday, July 31, 2013

Keys table EJB | script to correct counter values

When you do migration from one version of commerce to the next or any other scenarios or due to data load scenarios some times the keys table counters are messed and causes lot of errors in application server logs when using those corresponding EJB's.

A lot of discretion is warranted when doing stuff to the keys table e.g. counter should be greater than the lower bound and lesser than the upper bound
You can generate the SQL statements from the script below and run them against the corresponding commerce schema where the issue was found.

SQL Script to see which tables might need to be fixed:

select 'select max(' || columnname||')+1 - (select counter from keys where tablename = '''|| tablename||'''), '''|| tablename || ''' from ' || tablename from keys

 SQL script to do the actual updates:
select concat(concat(concat('update keys set counter=',concat(concat(
concat(concat('(select max(',columnname),')+1 from ' ),tablename),') where tablename=''')),tablename),''' and counter <= '|| '(select max('||columnname||') from '|| tablename||')' ||';') from keys

7 comments:

  1. Wonderful post! Youve made some very astute observations and I am thankful for the the effort you have put into your writing. Its clear that you know what you are talking about. I am looking forward to reading more of your sites content.
    Hadoop training

    ReplyDelete
  2. The organization's advancement group will survey your work to check whether it addresses their issues and may then contract you. When you are employed, you generally fill in as a consultant, being sent or getting your "end of the week heap" of contents when they reach you. script coverage

    ReplyDelete
  3. Me encanta el articulo, es super interesante y curioso, se lee genial con mucha fluidez. Estoy deseando leer más artículos vuestros, sois geniales.

    ReplyDelete
  4. La verdad es que la información es buena y amena, su fácil comprensión me ha atrapado desde el primer momento y ha conseguido que me informe de lo que quería saber. Se nota que estás encantado con lo que haces. =)

    ReplyDelete
  5. No es lo que estaba buscando ahora mismo, pero el post me ha llamado bastante la atención ya que te cuenta cosas interesantes que pueden ser útiles, encima se nota que le has puesto mucho esfuerzo ¡felicidades!

    ReplyDelete
  6. Muy chulo el artículo, contiene información muy interesante, gracias por tu interés.

    ReplyDelete
  7. Me encanta todo lo que cuentas en el post, es muy interesante y me encantaría que explicaras más sobre el tema.

    ReplyDelete