JBoss AS 7.1 with Mysql Server step-by-step

Today we’ve struggled for more then three hours figuring out how to use Mysql on our JBoss server. I am going to describe steps by step because I found this very confusing.

Lets get started. I assume you have downloaded and extracted JBoss 7.1 AS

There are two ways how you can use Mysql in JBoss. We are going the easier one because in the second one you have to edit 1400lines long XML (the bloody hell!!).

  1. download Mysql Java Connector
  2. extract .jar to separete folder (for example mysql-connector-java-5.1.22-bin.jar)
  3. in that folder create directory META-INF and inside that one create services and there create file called java.sql.Driver (so it will look META-INF/services/java.sql.Driver)
  4. into that driver write only this line:
    com.mysql.jdbc.Driver

  5. go back to the folder with .jar and run this command (replace name of your /jar accordingly):
    jar -uf mysql-connector-java-5.1.22-bin.jar  META-INF/services/java.sql.Driver

  6. go to your JBoss bin folder and run script add-user.bat (add-user-sh on unix)
  7. choose a) Management User (mgmt-users.properties) -> ENTER -> fill username -> fill password -> repeat password
  8. in your browser open http://localhost:9990/console/ and login using that username/password
  9. in administration console switch to Runtime (upper right corner) and then choose Manage Deployments. There click on the Add Content button and choose path the .jar extracted above. At last click on the enable button. Finally it should look like this:
    1
  10. switch to Profile (upper right corner http://localhost:9990/console/App.html#datasources) and open Connector / Datasources and click on the Add button
  11. specify name and JNDI name – you will fill this up in your persistent.xml. Remember that JNDI name must begin with java:/ … so for example java:/testDS
  12. in second step choose mysql-connector-java-5.1.22-bin.jar connector.
  13. connection URL will look like: jdbc:mysql://localhost/database_name
  14. fill also your mysql username and mysql password and click on Done (leave security domain blank).
  15. now click on the Enable button to enable datasource
  16. 2

    in your persistent.xml you can use created datasource like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<persistence version=”2.0″
   xmlns=”http://java.sun.com/xml/ns/persistence&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
   xsi:schemaLocation=”
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd“>
   <persistence-unit name=”primary”>
      <jta-data-source>java:/testDS</jta-data-source>
      <properties>
         <property name=”hibernate.hbm2ddl.auto” value=”create-drop” />
         <property name=”hibernate.archive.autodetection” value=”class” />
      </properties>
   </persistence-unit>
</persistence>

Source: https://community.jboss.org/wiki/DataSourceConfigurationInAS7

Disable keyboard in windows (with commandline script)

My cat loves my keybaord. Here is how to disable it:

  1. regedit … HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServiceskbdclassParameters
  2. create new DWORD value named AllowDisable and set value to 1
  3. reboot
  4. open Device manager and disable option will be visible.

You can also make a script using devcon from Windows Driver Kit. Its located in C:Program Files (x86)Windows Kits8.0Toolsx64devcon.exe

You will need device ID of your keyboard. You can get it from Device Manager or using devcon find * |  findstr /R /C:”board”

Script has to escalate priviledges so it looks like this:

@echo off

:: BatchGotAdmin
:————————————-
REM  –> Check for permissions
>nul 2>&1 “%SYSTEMROOT%system32cacls.exe” “%SYSTEMROOT%system32configsystem”

REM –> If error flag set, we do not have admin.
if ‘%errorlevel%’ NEQ ‘0’ (
    echo Requesting administrative privileges…
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^(“Shell.Application”^) > “%temp%getadmin.vbs”
    echo UAC.ShellExecute “%~s0”, “”, “”, “runas”, 1 >> “%temp%getadmin.vbs”

    “%temp%getadmin.vbs”
    exit /B

:gotAdmin
    if exist “%temp%getadmin.vbs” ( del “%temp%getadmin.vbs” )
    pushd “%CD%”
    CD /D “%~dp0”
:————————————–

devcon disable “HIDVID_045E&PID_00DB&MI_00*

Where HIDVID_045E&PID_00DB&MI_00* is my keyboard ID. It looks actually like this: USBVID_045E&PID_00DB&MI_007&28157AAF&0&0000 but using this the devcon fails to find it. So I used wildcard.

Search button in Jelly Bean navigation bar

1) added search button according to http://forum.xda-developers.com/showthread.php?t=1743979
2) builded new SystemUI
3) decompiled that new SystemUI so I have search button id hex value builded into (0x_______ in ids.xml and public.xml)
4) looked at id hex value of recent button and searched for it in smali files
5) found the part where buttons are being showed and hided
6) added getSearchButton method according to getHomeMethod
7) added similar code for showing and hiding button … there is condition to set visibility of homebutton (or recent I dont remember which I used) so I am basically setting the same value to the visibility of Search button

Device-2012-07-05-004254
Device-2012-07-05-004317

Download for [ROM][GSM] Jellybean 4.1 JRN84D: Stock Rooted Busybox Deodexed – v2 (6/29/12): https://dl.dropbox.com/u/16217558/navbar.zip

Levensteinova vzdalenost v MySQL

Potreboval jsem pouzit v SELECTu Levensteinovu vzdalenost, abych neukladal do databaze data podobna tem, ktere tam uz jsou. Nastesti jsem nebyl prvni, kdo to resil a na netu jsem nasel:

Definice funkce pro Levensteinovu vzdalenost v MySQL:

DELIMITER //
CREATE FUNCTION LEVENSHTEIN (s1 VARCHAR(255), s2 VARCHAR(255))
RETURNS INT
DETERMINISTIC
BEGIN
  DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
  DECLARE s1_char CHAR;
  DECLARE cv0, cv1 VARBINARY(256);
  SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0;
  IF s1 = s2 THEN
    RETURN 0;
  ELSEIF s1_len = 0 THEN
    RETURN s2_len;
  ELSEIF s2_len = 0 THEN
    RETURN s1_len;
  ELSE
    WHILE j <= s2_len DO
      SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
    END WHILE;
    WHILE i <= s1_len DO
      SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
      WHILE j <= s2_len DO
        SET c = c + 1;
        IF s1_char = SUBSTRING(s2, j, 1) THEN SET cost = 0; ELSE SET cost = 1; END IF;
        SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
        IF c > c_temp THEN SET c = c_temp; END IF;
        SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
        IF c > c_temp THEN SET c = c_temp; END IF;
        SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
      END WHILE;
      SET cv1 = cv0, i = i + 1;
    END WHILE;
  END IF;
  RETURN c;
END//

Dotaz, ktery vypise zaznamy s levensteinovou vzdalnosti 0 az 3:

SELECT * FROM tabulka WHERE levenshtein(‘vstup’, jmeno_sloupce) BETWEEN 0 AND 3

Prodam HTC Desire Z – prodano

Prodano

Nabizim HTC Desire Z v perfektnim stavu. Velice zachovaly, protoze byl nosen celou dobu v kozenem pouzdre. Na zadnim krytu je nepatrne skrabnuti (fotil jsem proti svetlu, aby to bylo videt). Kupovany v brand shopu HTC za 12 900,- v listopadu 2010, tzn nejedna se o sedy dovoz a telefon je do listopadu v zaruce.

Pridavam take rozsirenou baterii Mugen 1800 mAh kupovanou u Sunnysoft 29.8.2011 – jedna se tedy  o celkem novou baterii. Samozrejme prikladam i originalni baterii.

Take pridam kolebku pro telefon kupovanou take u Sunnysoft se slotem pro nabijeni druhe baterie. Mohu pridat jeste pouzite kozene pouzdro Krusell, ktere je ve vyrazne horsim stavu. Vse vcetne dokladu.

Sitovy adapter, USB kabel, mikroSD karta a sluchatka jsou samozrejmosti.

Duvod prodeje: v unoru jsem vyhral Galaxy Nexus a od te doby Ztko prakticky nepouzivam.

Cena kompletu: 5500,-

Preferuji osobni predani v Praze, popr Ceska Trebova.

Desire_z-1
Desire_z-2
Desire_z-3

 

Vodafone Park ochrana proti spam botum

Snazim se aplikacim jako Free SMS Sender umoznit odesilani zprav pres Vodafone Park, protoze Vodafone odmita poskytnout pro tyto aplikace API.

Vse uz je hotove, ale potrebuji na testovani vic vzorku kodu z Vodafone Parku, protoze jsou pro kazdeho uzivatele jine. K odeslani kodu pouzijte prosim:

http://ww.nuc.cz/vodafone.php

Postup:

  1. na strance Vodafone parku, kde je sms brana, kliknout nekam pravym tlacitkem a v nabidce vybrat “zobrazit zdrojovy kod”
  2. v te hromade textu najit pomoci CTRL-F toto: proof:field
  3. zkopirovat (CTRL+C) nasledujici radek. Zacina … bude asi dost dlouhy a ten vlozit (CTRL+V) do nasledujiciho pole a stisknout tlacitko Odeslat.

 

Dekuji za pomoc.