Tuesday 14 July 2015

How to set timezone in Weblogic?

1. Open file in Notepad
../{your_weblogic_folder}/user_projects/domains/{your_domain_name}/bin/setDomainEnv.cmd

2. Add to the property %JAVA_PROPERTIES% -Duser.timezone=GMT.
Line should look the following way:
set JAVA_PROPERTIES=%JAVA_PROPERTIES% %EXTRA_JAVA_PROPERTIES% -Duser.timezone=GMT

Friday 3 July 2015

How to write / read BLOB to / from Oracle database?

WRITE:

To transform String value into blob just execute your_string.getBytes();

String blobValue = "long blob";
bytes[] bytes = blobValue.getBytes();
int rows = getJdbcTemplate().update("update MY_TABLE set BLOB_COLUMN = ? where ROWID = '1'", bytes);

READ:

we can either read blob from database in Blob class or transform into String. To transform it into String we will need additional custom method:

public static String sqlBlobToString(Blob blob) {

StringBuilder stringBuilder = new StringBuilder();

try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(blob.getBinaryStream())) {
       while ((string = bufferedReader.readLine()) != null) {
              stringBuilder.append(string);
       }
 } catch (IOException e) {
       throw new RuntimeException(e);
}
return stringBuilder;
}


Querying from database:

String s = sqlBlobToString(getJdbcTemplate().queryForObject("select BLOB_COLUMN from MY_TABLE where ROWID = '1'", Blob.class));

Note: I am using java.sql.Blob

How to write / read CLOB to / from Oracle database?

WRITE:

there is no problems with clob saving into db - just keep it in String value and regularly save it:

String clobValue = "long clob";
int rows = getJdbcTemplate().update("update MY_TABLE set CLOB_COLUMN = ? where ROWID = '1'", clobValue);

READ:

we can either read clob from database in Clob class or transform into String. To transform it into String we will need additional custom method:

public static String sqlClobToString(Clob clob) {

StringBuilder stringBuilder = new StringBuilder();

try(BufferedReader bufferedReader = new BufferedReader(clob.getCharacterStream()) {
       while ((string = bufferedReader.readLine()) != null) {
              stringBuilder.append(string);
       }
 } catch (IOException e) {
       throw new RuntimeException(e);
}
return stringBuilder;
}

Querying from database:

String s = sqlClobToString(getJdbcTemplate().queryForObject("select CLOB_COLUMN from MY_TABLE where ROWID = '1'", Clob.class));

Note: I am using java.sql.Clob

Thursday 2 July 2015

How to switch to debug mode without application re-deploy in Intellij Idea for Weblogic?

1. Open file in Notepad
../{your_weblogic_folder}/user_projects/domains/{your_domain_name}/bin/setDomainEnv.cmd

2. Set the following value for JAVA_DEBUG variable, line will look this way:
set JAVA_DEBUG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=50000,server=y,suspend=n

where 50000 is any port number you wish to use for debug.

3. In Intellij Idea Run -> Edit Configuration ->click + and add 'Remote' configuration.

4. Configure Remote configuration: add 'Name', set 'Port' number, the same you have indicated in point 2.

Run application in regular mode and when needed switch to debug.

Wednesday 1 July 2015

How to start / stop weblogic manually?

START: Run ../user_projects/domains/your_domain_name/startWeblogic.cmd
or ../user_projects/domains/your_domain_name/bin/startWeblogic.cmd

STOP: Run ../user_projects/domains/your_domain_name/bin/stopWeblogic.cmd

How to create domain in weblogic?

1. Run ../oracle_common/common/bin/config.cmd
2. Configuration Wizard will open
3. CREATE DOMAIN: Choose "Create new domain" option and specify desired domain location with domain name in the end.
(Ex: C:\Users\arina\user_projects\domains\base_domain, where base_domain is our new domain name)
4. TEMPLATES: Leave as it is and click Next.
5. ADMINISTRATOR ACCOUNT: Enter administrator credentials and click Next
6. DOMAIN MODE and JDK: I choose Development for Domain Mode, and leave embedded Weblogic JDK, and click Next
7. ADVANCED CONFIGURATIONS: Mostly I usually need only Administration Server, chose it and click Next
8. ADMINISTRATION SERVER: Usually I leave Server Name as is "AdminServer" but it's optional. Listen port: specify which port you want weblogic to use, let's say 7171, 9191 or any you like, and click Next.
9. CONFIGURATION SUMMARY: review your configurations and click Create
10. After progress bar reached 100% and Next button activated, click Next.
11. Review Domain Location, Admin Server URL, if you need to start Start Admin Server right away select appropriate checkbox and click Finish.

How to clone specific branch in git?

If git repository is too big and you can't clone (or don't want to) all of it, you can clone specific branch:
git clone -b [branch_name] --single-branch http://arina.git