Following query shows the latest analysis time of tables in Oracle:
SELECT distinct stattype_locked, table_name, last_analyzed
FROM dba_tab_statistics
WHERE owner = 'HR' order by last_analyzed desc;
8 Ocak 2011 Cumartesi
8 Ekim 2010 Cuma
Solaris: How To Download File In Command Prompt
wget command is used to download files in unix based operating systems. But in Solaris the command does not seem to exist:
# wget
wget: not found
Actually it exists in the file system. But it just isn't added into PATH by default. The location of command is /usr/sfw/bin/wget. Following is a usage example of wget in Solaris.
# wget
wget: not found
Actually it exists in the file system. But it just isn't added into PATH by default. The location of command is /usr/sfw/bin/wget. Following is a usage example of wget in Solaris.
# /usr/sfw/bin/wget google.com
--2010-10-08 11:15:20-- http://google.com/
Resolving google.com... 74.125.87.99, 74.125.87.104
Connecting to google.com|74.125.87.99|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2010-10-08 11:15:20-- http://www.google.com/
Resolving www.google.com... 74.125.87.104, 74.125.87.99
Reusing existing connection to google.com:80.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.com.tr/ [following]
--2010-10-08 11:15:20-- http://www.google.com.tr/
Resolving www.google.com.tr... 74.125.87.104, 74.125.87.99
Reusing existing connection to google.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.2'
[ <=> ] 9,005 --.-K/s in 0.01s
2010-10-08 11:15:20 (685 KB/s) - `index.html.2' saved [9005]
--2010-10-08 11:15:20-- http://google.com/
Resolving google.com... 74.125.87.99, 74.125.87.104
Connecting to google.com|74.125.87.99|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2010-10-08 11:15:20-- http://www.google.com/
Resolving www.google.com... 74.125.87.104, 74.125.87.99
Reusing existing connection to google.com:80.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.com.tr/ [following]
--2010-10-08 11:15:20-- http://www.google.com.tr/
Resolving www.google.com.tr... 74.125.87.104, 74.125.87.99
Reusing existing connection to google.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.2'
[ <=> ] 9,005 --.-K/s in 0.01s
2010-10-08 11:15:20 (685 KB/s) - `index.html.2' saved [9005]
Etiketler:
administration,
linux,
solaris,
unix,
wget
16 Ağustos 2010 Pazartesi
Use DbUnit With Maven
dbunit is a useful tool for populating test data into databases on the fly.
It is also useful to use this tool to populate application configuration information.
This article demonstrates how to use dbunit with maven.
We require jdbc drivers for our database. Assuming we are using oracle, dbunit plugin's dependency configuration will be as follows:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2.0</version>
</dependency>
We also need connection information for our database. We'll use following connection information in our dbunit configuration:
host: jdbc:oracle:thin:@localhost:1521:XE
username: hr
password: hr
driver: oracle.jdbc.driver.OracleDriver
Putting it all together, following is an example configuration for dbunit:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<configuration>
<dataTypeFactoryName>org.dbunit.ext.oracle.OracleDataTypeFactory</dataTypeFactoryName>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<username>hr</username>
<password>hr</password>
<url>jdbc:oracle:thin:@localhost:1521:XE</url>
<src>src/test/resources/sample-data.xml</src>
<type>CLEAN_INSERT</type>
<schema>HR</schema>
<skip>${skipTests}</skip>
<transaction>true</transaction>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2.0</version>
</dependency>
</dependencies>
</plugin>
Based on this configuration, our dataset file resides in src/test/resources/sample-data.xml file. This file contains our test data. Execute following command to persist the data inside sample-data.xml into the database.
> mvn dbunit:operation
Yet, we don't know how to prepare and/or what to put inside sample-data.xml. If you have a ready to use database, you may not need to prepare sample-data.xml file from scratch. There is another command to export database tables into a dataset file.
> mvn dbunit:export
Upon invoking this command, a new file will be generated under target/dbunit/export.xml which will contain all your test data. You can, later, use this file to reinitialize your test database using "mvn dbunit:operation" command.
Maven DBUnit Plugin Homepage:
http://mojo.codehaus.org/dbunit-maven-plugin
DBUnit Getting Started Guide:
http://www.dbunit.org/howto.html
DBUnit Best Practices:
http://www.dbunit.org/bestpractices.html
It is also useful to use this tool to populate application configuration information.
This article demonstrates how to use dbunit with maven.
We require jdbc drivers for our database. Assuming we are using oracle, dbunit plugin's dependency configuration will be as follows:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2.0</version>
</dependency>
We also need connection information for our database. We'll use following connection information in our dbunit configuration:
host: jdbc:oracle:thin:@localhost:1521:XE
username: hr
password: hr
driver: oracle.jdbc.driver.OracleDriver
Putting it all together, following is an example configuration for dbunit:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<configuration>
<dataTypeFactoryName>org.dbunit.ext.oracle.OracleDataTypeFactory</dataTypeFactoryName>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<username>hr</username>
<password>hr</password>
<url>jdbc:oracle:thin:@localhost:1521:XE</url>
<src>src/test/resources/sample-data.xml</src>
<type>CLEAN_INSERT</type>
<schema>HR</schema>
<skip>${skipTests}</skip>
<transaction>true</transaction>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2.0</version>
</dependency>
</dependencies>
</plugin>
Based on this configuration, our dataset file resides in src/test/resources/sample-data.xml file. This file contains our test data. Execute following command to persist the data inside sample-data.xml into the database.
> mvn dbunit:operation
Yet, we don't know how to prepare and/or what to put inside sample-data.xml. If you have a ready to use database, you may not need to prepare sample-data.xml file from scratch. There is another command to export database tables into a dataset file.
> mvn dbunit:export
Upon invoking this command, a new file will be generated under target/dbunit/export.xml which will contain all your test data. You can, later, use this file to reinitialize your test database using "mvn dbunit:operation" command.
Additional Resources:
http://mojo.codehaus.org/dbunit-maven-plugin
DBUnit Getting Started Guide:
http://www.dbunit.org/howto.html
DBUnit Best Practices:
http://www.dbunit.org/bestpractices.html
11 Kasım 2009 Çarşamba
Intellij IDEA 9 Community Edition Çıktı
Intellij, version 9 ile beraber community edition ve ultimate edition olarak dagitilmaya başladi:
http://blogs.jetbrains.com/idea/2009/10/intellij-idea-open-sourced/
Community edition'ı asagidaki linkten ucretsiz olarak indirebilirsiniz:
http://www.jetbrains.com/idea/nextversion/free_java_ide.html?utm_source=IDEA_BLOG&utm_media=Anouncement&utm_campaign=IDEA9_CE
10 Haziran 2009 Çarşamba
Obtaining Information About The Current User In Spring Security
The details of the principal currently interacting with the application is stored inside
SecurityContextHolder
. Spring Security uses an Authentication
object to represent this information. Use the following code block -from anywhere in your application- to obtain the name and the password of the currently authenticated user:Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
UserDetails principal = (UserDetails) authentication.getPrincipal();
String username = principal.getUsername();
String password = principal.getPassword();
6 Nisan 2009 Pazartesi
Oracle XE'de HTTP Portu Nasıl Değiştirilir?
Oracle XE, standart olarak 8080 no'lu HTTP portu olarak kullanır. Bu portu JBoss ve Tomcat de HTTP portu olarak kullandığı için, Oracle ile beraber bir application server çalıştırmak için, ya application server'in ya da Oracle'in HTTP portunun değiştirilmesi gerekiyor.
Oracle'de bu portu değiştirmek icin dbms_xdb.sethttpport() fonksiyonunu kullanabilirsiniz. Database'e system kullanıcısıyla giriş yaptıktan sonra aşağıdaki şekilde çalıştırabilirsiniz:
EXEC dbms_xdb.sethttpport(8090);
Oracle'de bu portu değiştirmek icin dbms_xdb.sethttpport() fonksiyonunu kullanabilirsiniz. Database'e system kullanıcısıyla giriş yaptıktan sonra aşağıdaki şekilde çalıştırabilirsiniz:
EXEC dbms_xdb.sethttpport(8090);
31 Mart 2009 Salı
Intellij Knows How To "Extract Method"
Intellij has a great refactoring feature called "Extract Method". You can convert a code piece into a method using this feature. In this process, Intellij can handle all method parameters and return values. You can use this feature first by selecting the code piece you wish to convert to method, and press CTRL+ALT+M.
I will explain what impressed me most about this feature using following example. In the following code, I am not comfortable with the first try/catch block and I want to hide this dirty code inside a method.

Then, press CTRL+ALT+M. Notice that, the return type of the method is boolean. Click OK and see what we'll get:

Following is the refactored version of our code. Let's see what happened. Intellij put the code inside a method which returns boolean and wrapped the method call inside an if statement. This was the only possible solution which wouldn't violate the flow of program:).
I will explain what impressed me most about this feature using following example. In the following code, I am not comfortable with the first try/catch block and I want to hide this dirty code inside a method.
1 public static void main(String[] args) {To achieve this, position the cursor over 5th line and press CTRL+W. By the way, this is another nice Intellij feature called "Incremental Select" :).
2 Connection conn = null;
3
4 //I am not comfortable with following try/catch block
5 try {
6 Class.forName("com.mysql.jdbc.Driver");
7 } catch (ClassNotFoundException e) {
8 e.printStackTrace();
9 System.out.println("Driver not found");
10 return;
11 }
12
13 try {
14 conn = DriverManager.getConnection(
15 "jdbc:mysql://localhost/petshop", "root", "changeme");
16 Statement statement = conn.createStatement();
17 } catch (SQLException e) {
18 e.printStackTrace();
19 }
20 }
21
Then, press CTRL+ALT+M. Notice that, the return type of the method is boolean. Click OK and see what we'll get:
Following is the refactored version of our code. Let's see what happened. Intellij put the code inside a method which returns boolean and wrapped the method call inside an if statement. This was the only possible solution which wouldn't violate the flow of program:).
1 public static void main(String[] args) {
2 Connection conn = null;
3
4 //I am comfortable now
5 if (lookupClass()) return;
6
7 try {
8 conn = DriverManager.getConnection(
9 "jdbc:mysql://localhost/petshop", "root", "changeme");
10 Statement statement = conn.createStatement();
11 } catch (SQLException e) {
12 e.printStackTrace();
13 }
14 }
15
16 private static boolean lookupClass() {
17 try {
18 Class.forName("com.mysql.jdbc.Driver");
19 } catch (ClassNotFoundException e) {
20 e.printStackTrace();
21 System.out.println("Driver not found");
22 return true;
23 }
24 return false;
25 }
26
Kaydol:
Kayıtlar (Atom)