quarta-feira, 23 de novembro de 2011

Estações Windows perdem a conexão com as undiades de rede.

Problema:
Estações Windows perdem a conexão com as undiades de rede.

Solução:
Setar o autodisconect para -1 no servidor: net config server /autodisconnect:-1

Obs: Testado no Windows 2008 R2 64Bits.

http://support.microsoft.com/default.aspx?scid=kb;en-us;138365


How Autodisconnect Works in Windows NT and Windows 2000

System TipThis article applies to a different version of Windows than the one you are using. Content in this article may not be relevant to you. Visit the Windows 7 Solution Center
This article was previously published under Q138365

SUMMARY

This article documents the Windows NT and Windows 2000 local area network (LAN)-related Autodisconnect parameter. 

Windows NT and Windows 2000 use two different Autodisconnect parameters; one for disconnecting Remote Access Service (RAS) connections and another for disconnecting LAN connections. The RAS Autodisconnect parameter is documented in the Microsoft Knowledge Base article Q153944, but the LAN version is undocumented. The only published reference to this Autodisconnect is in the Windows NT Resource Kit NT Registry Entries help file, in an overview of entries for the LanmanServer Parameters section.

MORE INFORMATION

You can find the LAN Autodisconnect parameter in the registry under the subtree HKEY_LOCAL_MACHINE under the subkey:
\System\CurrentControlSet\Services\LanmanServer\Parameters
NOTE: The preceding entry must be located on the computer that has the share or shares.

The purpose is to disconnect idle sessions after a set number of minutes. The number of minutes can be set at a command prompt using the net config server command.

For example, to set the Autodisconnect value to 30 minutes, you would run the following command line:
net config server /autodisconnect:30
The valid value range is -1 to 65535 minutes at the command line. To disable Autodisconnect set it to -1.

Setting Autodisconnect to 0 does not turn it off and results in very fast disconnects, within a few seconds of idle time. (However, the RAS Autodisconnect parameter is turned off if you set it to a value of 0.)

NOTES:
  • It is preferable to modify the LAN Autodisconnect directly in the registry. If you modify it at the command line, Windows NT and Windows 2000 may turn off its autotuning functions. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
    128167  Server Service Configuration and Tuning
    The valid value range if you edit the LAN Autodisconnect parameter in the registry is 0 to 4294967295 (Oxffffffff).
  • For a Windows 2000 Server in a Domain, running either as a domain controller or as a server, the maximum value is 65,535 (0xffff). Values set above this will be returned to 0xffff after policy refresh. Windows 2000 Servers in a workgroup may be set to any value as indicated.

    If you configure the Autodisconnect option to -1 at the command prompt, Autodisconnect is set to the upper value in the registry. This is approximately 8,171 years (not tested), which should be long enough to be the equivalent of turning Autodisconnect off.
  • The registry does not allow you to add a -1 value. However, that modification may be made at the command prompt with the following command:
    net config server /autodisconnect:-1
    When this is set, two additional registry keys are added:
    anndelta: REG_DWORD: 0xbb8
    announce: REG_DWORD: 0xf0
    Announce: Specifies the network announce rate, in seconds. This rate determines how often the server is announced to other computers on the network. 

    Anndelta: Specifies the delta value for the announce rate, in milliseconds. This value specifies how much the announce rate can vary from the period of time specified in the announce member. 

    The delta value allows randomly varied announce rates. For example, if the announce member has the value 10 and the anndelta member has the value 1, the announce rate can vary from 9.999 seconds to 10.001 seconds.
  • After a few minutes of idle time, your mapped drive or drives may be disconnected, and a red "X" may appear next to the mapped drives in Windows Explorer.For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
    305355  Some Compaq Programs Cause Mapped Drives to Be Disconnected

quinta-feira, 10 de novembro de 2011

Oracle - Select por mês/dia/ano


Selecionar todos os usuários cadastrados no mês de Janeiro/2011 (01/2011):

select
   usuario.nome
from
  usuario
where
to_char(insert_data, 'mm/yyyy') = '01/2011'

 
ou

select
   usuario.nome
from
  usuario
where
to_char(insert_data, 'mon/yyyy') = 'jan/2011'


Com uma pequena alteração você pode retornar todos os usuários cadastrados em Janeiro de qualquer ano:

select
   usuario.nome
from
  usuario
where
to_char(insert_data, 'mm') = '01'


terça-feira, 11 de outubro de 2011

Exemplo de herença no Hibernate

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.CHAR,length=1,name="tipo_pessoa")
@DiscriminatorValue(value="0")
@DiscriminatorFormula(value = "case when tipo_pessoa is null then 'F' end")
// Outro exemplo de @DiscriminatorFormula
//@DiscriminatorFormula(value = "case when tipo_pessoa in ('X', 'Y', 'Z') then 'F' end")
@SequenceGenerator(name="seq", sequenceName="seq", allocationSize=1)
public class Pessoa{
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq")
   private int id;
   private String tipo_pessoa;
}

@Entity
@SequenceGenerator(name="seq", sequenceName="seq", allocationSize=1)
@DiscriminatorValue(value="J")
public class PessoaJuridica Extendes Pessoa{
   private Integer cnpj;
}

@Entity
@SequenceGenerator(name="seq", sequenceName="seq", allocationSize=1)
@DiscriminatorValue(value="F")
public class PessoaFisica Extendes Pessoa{
   private Integer cpf;
}

segunda-feira, 10 de outubro de 2011

window.confirm em a4j:commandButton

<a4j:commandButton
        reRender="rdtFollowp"
        onclick="if (! window.confirm('Confirma?') ) {return false}"
        actionListener="#{processoImportacaoMB.deleteRegFlp}"
        image="/imagens/ImagensUtilizadas/16x16/remove.png"
        title="Excluir" >  
    <a4j:actionparam id="deleteRegFlp" value="#{flp.id}" name="pDelteteFlp"/>
</a4j:commandButton>

quarta-feira, 28 de setembro de 2011

java.sql.SQLException: ORA-01445

Erro:

java.sql.SQLException: ORA-01445: não é possível selecionar nem gerar amostragem para ROWID em uma view de junção sem uma tabela preservada com chaves.

Esse é um Bug do Oracle que afeta ao menos as versões:
9.2.0.6
10.1.0.4
10.2.0.1

O erro ocorre quando o retorno da SQL excede certo número de colunas.  Esse número excessivo de colunas é geralmente  causado por joins (principalmente quando utiliza-se um framework de persistência ex: Hibernate).

Para resolver o problema:

1) Atualize a versão do Oracle:
9.2.0.8
10.1.0.5
10.2.0.2
11g 
Ou

2)  Adicione @Fetch(FetchMode.SELECT)a alguns de seus relacionamentos. Com isso, será gerado um SQL a parte, o que fará com que o primeiro SQL não tenha o limite de coluna excedido.

Ex:

@OneToOne
@Fetch(FetchMode.SELECT)
@JoinColumn(name="agentecarga_id", insertable=false,updatable=false)
private Contato agenteCarga;

sexta-feira, 5 de agosto de 2011

h:inputTextarea sem rolagem e bordas

Útil para impressão de campos BLOB/CLOB, pois preserva as quebras de linhas.


<h:inputTextarea
  rows="10"
  cols="120"
  readonly="true"
  value=""
  style="overflow:auto;height:200px;width:400px;border-style:hidden;margin:0px;padding:0px;"/>

segunda-feira, 1 de agosto de 2011

Oracle: Expressoes Regulares (REGEXP)


REGEXP_LIKE (telefone, '^\d*[0-9](\.\d*[0-9])?$'). Em um where, retorna os registros que contenham apenas números no campo telefone.

Exemplos:
Tipo
EXPRESSAO REGULAR
Examplo
Data (dd/mm/aaaa)
^([0-9]|[0,1,2][0-9]|3[0,1])/([\d]|1[0,1,2])/\d{4}$
21/12/2007

Numero Decimal
^\d*[0-9](\.\d*[0-9])?$
234.342

Arquivos Documentos
^[a-zA-Z0-9-_\.]+\.(pdf|txt|doc|csv)$
world-domination.pdf

E-mail
^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$
info@lymas.com.br

Codigo Cor HTML
^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$
#00ccff

Arquivo de Imagem
^[a-zA-Z0-9-_\.]+\.(jpg|gif|png)$
new-pic_company.jpg

Endereco IP
^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$
192.168.0.1

Arquivos Multimedia
^[a-zA-Z0-9-_\.]+\.(swf|mov|wma|mpg|mp3|wav)$
company-presentation.swf

Data Formato Mysql
^\d{4}-(0[0-9]|1[0,1,2])-([0,1,2][0-9]|3[0,1])$
2005-09-02

Telefone (BR)
^\(?\d{2}\)?[\s-]?\d{4}-?\d{4}$
(11) 5555-1977

Codigo Postal (EUA)
^([A-Z][0-9]){3}$
V2B2S3

Hora (HH:MM)
^([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}$
12:29

URL
^(http[s]?://|ftp://)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov|br)$
http://www.google.com

Telefone Internacional
^(([0-9]{1})*[- .(]*([0-9a-zA-Z]{3})*[- .)]*[0-9a-zA-Z]{3}[- .]*[0-9a-zA-Z]{4})+$
1.245.532.3422

Fonte: http://tools.lymas.com.br/regexp_br.php

quarta-feira, 18 de maio de 2011

java.lang.NoClassDefFoundError: Could not initialize class

Erro:
java.lang.NoClassDefFoundError: Could not initialize class br.com.teste.ganymede.util.HibernateUtil

15:36:30,543 INFO  [CollectionBinder] Mapping collection: br.com.teste.ganymede.modelo.operacional.Mawb.hawbs -> AbreProcesso
15:36:30,549 INFO  [Version] Hibernate Validator 3.1.0.GA
15:36:30,637 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.NoClassDefFoundError: Could not initialize class br.com.teste.ganymede.util.HibernateUtil
      at br.com.teste.ganymede.util.HibernateSessionfilter.doFilter(HibernateSessionfilter.java:29)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Unknown Source)

Origem do problema:
public class DespesaHawb implements Serializable{
            
      @ManyToOne
      // Origem do problema aqui!
      @JoinColumn(name="hawb_id")
      private AbreProcesso hawb;
    
      @OneToOne
      // Assim funciona!
      @JoinColumn(name="despesa_id",insertable=false,updatable=false)
      private Despesa despesa;
     
      @OneToOne
      // Assim funciona, pois a propriedade usuario esta anotada!
      @JoinColumn(name="insert_usuario")
      private Usuario usuario;
     
      @Id
      @GeneratedValue
     
generator="seq_despesahawb",strategy=GenerationType.SEQUENCE)
      private int id;
      private Integer despesa_id;
      private Double valor;
      private String moeda_codigo;
      private Double valor_moeda;
      private Double taxa_conversao;
      private Double valor_real;
      @Column(insertable=false,updatable=false)
      private Integer insert_usuario;
      @Column(insertable=false,updatable=false)
      private Date insert_data;
      private String hawb_id;
      private String tipo;   

Solução:
1)       Remover a propriedade hawb_id deixando somente o objeto hawb.

Ou
2)       Anotar a propridade hawb_id com @Column(insertable=false,updatable=false)
   Ou
3) Alterar o @ManyToOne para:@ManyToOne@JoinColumn(name="hawb_id",insertable=false,updatable=false)private AbreProcesso hawb;

quarta-feira, 2 de fevereiro de 2011

Exemplo de configuração do Hibernate com Firebird

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD/EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>


<session-factory name="firebird">
<property name="hibernate.dialect">org.hibernate.dialect.FirebirdDialect </property>
<property name="hibernate.connection.username">SYSDBA</property>
<property name="hibernate.connection.driver_class">org.firebirdsql.jdbc.FBDriver</property>
<property name="hibernate.connection.password">masterkey</property>
<property name="hibernate.connection.url">jdbc:firebirdsql:127.0.0.1:banco</property>


<!--
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
-->


<!--
Pool de Conexões - C3P0 Colocar JARs na pasta server/default/lib do
JBoss
-->


<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<property name="hibernate.org.c3p0.min_size">2</property>
<property name="hibernate.org.c3p0.max_size">10</property>
<property name="hibernate.org.c3p0.timeout">180</property>
<property name="hibernate.org.c3p0.idle_test_period">100</property>


<!--
Cache de Segundo Nível - EhCache Colocar JARs na pasta
server/default/lib do JBoss Criar arquivo ehcache.xml na pasta
web-inf da aplicacao
-->

<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>

<!-- Classes -->
<mapping class="modelo.cadastro.Banco" />
<mapping class="modelo.cadastro.Cidade" />
<mapping class="modelo.cadastro.Pais" />
<mapping class="modelo.cadastro.Contato" />

</session-factory>

</hibernate-configuration>

terça-feira, 4 de janeiro de 2011

Localizar duplicatas no Oracle / Find duplicate records in Oracle

Lozalizar registros duplicados no Oracle:


select 
  c.cnpj,
  count(*)
from
  contato c
  having count(c.cnpj) > 1
  group by c.cnpj