Thursday, July 28, 2011

Adding JAXB / jxc support in maven

Put your schemas (*.xsd) and bindings (*.xjb) into the src/main/resources folder.
Correct pom.xml as you add:
<build>
 <plugins>
  <plugin>
   <groupId>org.jvnet.jaxb2.maven2</groupId>
   <artifactId>maven-jaxb2-plugin</artifactId>
   <executions>
    <execution>
     <goals>
      <goal>generate</goal>
     </goals>
     <configuration>
      <args>
       <arg>-nv</arg><!-- this disable strict schema validation -->
      </args>
     </configuration>
    </execution>
   </executions>
  </plugin>
  <plugin>
   <inherited>true</inherited>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
 </plugins>
</build>

Wednesday, July 27, 2011

Extending enums in Java

public enum DataStatus
{
    DECLINED_BY_USER("DECLINED-BY-USER"),
    SUCCESSFUL("SUCCESSFUL"),
    SPAM("SPAM");

    private String code;
    
    private DataStatus(String code) {
         this.code = code;
    }
    
    public String getCode() { return code; }
    
    public String toString(){ return code; } // if you want it so
    
    public static DataStatus parse( String s ){
        s = s.toUpperCase();
        if( s.equals( "SUCCESSFUL" ) )
            return SUCCESSFUL;
        if( s.equals( "DECLINED-BY-USER" ) )
            return DECLINED_BY_USER;
        if( s.equals( "SPAM" ) )
            return SPAM;
        return null;
    }
}    

Monday, July 18, 2011

kickstart commands for mysql (create database & user)

mysql -u root -p --port=3306

CREATE DATABASE database_name;

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE       ON database_name.* TO 'user1'@'localhost';
GRANT SELECT,INSERT,UPDATE,DELETE,DROP,CREATE,ALTER,INDEX ON database_name.* TO 'user1'@'localhost';

FLUSH PRIVILEGES;


(mysql database) UPDATE user SET Password=PASSWORD('new_pass') WHERE User='username';

(mysql database) UPDATE user SET User='username_new' WHERE User='username_old';


For everyone host use '%' instead of 'localhost'