Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Wednesday, June 26, 2013

Using VIRTUAL Column in JPA Entity


While working with Java Persistence using ORM Layer, new feature from Oralce 11g can be useful.
E.g. Virtual Column.
 
Whenever want to use Virtual Column in JPA Entity, it should follow:
  • Field should not be Updatable.
  • Field should not be populated while creating the entity.

For such scenario, one has to use below annotation on field:
@Column(insertable=false, updatable=false)

Below is Detailed Example JPA Entity with Virtual Column usage:

Virtual Column Should be added like:
alter table cosnumers add(
     IS_ADMIN GENERATED ALWAYS AS ( CASE WHEN CONSUMER_ID IS NOT NULL THEN 1 ELSE 0 END)
);

JPA Entity Should define field for Virtual Column as shown below:
Package com.acp.jpa;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Consumer {

       private Long consumerID;

       @Column(insertable=false, updatable=false)
       private boolean isAdmin;
      
       /**
       * @return the consumerID
       */
       public Long getConsumerID() {
              return consumerID;
       }

       /**
       * @param consumerID the consumerID to set
       */
       public void setConsumerID(Long consumerID) {
              this.consumerID = consumerID;
       }

       //--- For Virtual Column - Provide only Getters.
       /**
       * @return the isAdmin
       */
       public boolean isAdmin() {
              return isAdmin;
       }

}



--
III  Cheers!

Thursday, June 20, 2013

Using Oracle SQL Developer as MySQL IDE

Need to follow below steps:

- Download desired MySQL connector, unzip and place to desired directory.
- From SQLDeveloper -> Tools -> Preferences -> Databases -> Third party JDBC driver.
  "Add Entry" for desired MySQL connector.

That's It!!!

Now you can observe MySQL tab in the DB Connections SQLDeveloper window.


References:
http://www.techrepublic.com/blog/programming-and-development/configuring-sql-developer-for-mysql/564


Cheers!

Wednesday, September 14, 2011

Dropping all DB tables, views, indexes, sequences in one query.

Most of the time one faces the issues like one need to delete all the tables, views, indexes or sequences in the database.
So following the query which generates DROP statements for all the components present in the Oracle database:

SELECT 'DROP TABLE ' || table_name || ';' AS statement FROM user_tables
Union
SELECT 'DROP VIEW ' || view_name || ';' AS statement from user_views
Union
SELECT 'DROP INDEX ' || index_name || ';' AS statement from user_indexes
Union
SELECT 'DROP SEQUENCE ' || sequence_name || ';' AS statement from user_sequences
Union
SELECT 'DROP SYNONYM ' || SYNONYM_name || ';' AS statement from user_SYNONYMs;

Cheers :)

Friday, November 12, 2010

Replacing carriage-returns & line-feeds from a string/column in Oracle/Database.

To replace the carriage-returns & line-feeds from a string in Oracle or database, replace() does not work properly.

There is a special handling required to replace new line or carriage-returns.


If the data in your database is POSTED from HTML form TextArea controls, different browsers use different New Line characters:
  • Firefox separates lines with CHR(10) only
  • Internet Explorer separates lines with CHR(13) + CHR(10)
  • Apple (pre-OSX) separates lines with CHR(13) only
So you may need something like:

  • update table_name set col_name = replace(replace(col_name, CHR(13), ''), CHR(10), '') ;
 

- Cheers!!!