Wednesday, December 2, 2015

Oracle 12c: Creating users without container database

So oracle released a database which is specifically designed and developed for cloud - Oracle 12c. Since its designed for cloud, its natural that there will be multiple databases for multiple applications in cloud and its logical only to have an infrastructure that can manage all these database instances. To address this Oracle 12c comes with features like container database and pluggable database. Without going into much of the details of CDB and PDB (which honestly I dont know either) what changed is how you create the users and also name your users. Like CDB users must start with C## or c## and PDB users must not start with C## or c##. What this means is all your scripts for 10g, 11g will fail if you plan to use Oracle 12c without container DB or say much like the way you are using 10g or 11g. Failure looks something like this.

SQL Error: ORA-65096: invalid common user or role name
65096. 00000 -  "invalid common user or role name"
*Cause:  An attempt was made to create a common user or role with a name
         that was not valid for common users or roles.  In addition to
         the usual rules for user and role names, common user and role
         names must start with C## or c## and consist only of ASCII
*Action: Specify a valid common user or role name.

So either you modify all your scripts to be env specific i.e. 10g, 11g or 12c which in many cases would be big task - change, test, maintain - if your project is too big. Another option is dont make any changes to your scripts but make 12c behave like 11g. Mine is later case i.e. just because client wants their product to be "latest Oracle release compliant" I've to ensure it does work with 12c although product itself is not cloud ready.

So in order to create users like 11g i.e. without creating container databases, for 12c trick is to set an undocumented parameter _ORACLE_SCRIPT to true. To avoid system level change, just set this for a session before executing CREATE USER statement.

$ sqlplus as sysdba
SQL> alter session set "_ORACLE_SCRIPT"=true;
SQL> create user foo identified by bar;
SQL> exit

Warning: _ORACLE_SCRIPT is undocumented parameter and is available at least with Oracle Use with caution, you never know when it might behave differently, not at all or just get dropped in future release. So use it at your own risk, convenience and wisely.

- Jay

Tuesday, February 17, 2015

Making IntelliJ Idea work with IBM JDK 7

[Update: December 22, 2015]: Below is not applicable for Intellij Idea 15. With Idea 15,  it seems guys at Jetbrains figured this out

Recently I was setting up IntelliJ IDEA and had to work with IBM JDK 7 and as soon as I imported my projects, I got this weird error Cannot resolve symbol 'String'. Now this was surprise/shock. How can a JDK doesn't have java.lang.String. Quick Google search also didn't tell much about this. If I change my JDK to Oracle then things work fine. So it has to do something with IBM JDK.

After digging around and asking friends/colleagues, finally the dark secret of IBM JDK revealed. Oracle provided runtime jar - rt.jar - is replaced by IBM's vm.jar. Story doesn't end here, this vm.jar is not even in its standard location i.e. <JDK_HOME>/jre/lib, but has been for some mysterious reason placed in <JDK_HOME>/jre/bin/default/jclSC170 directory. So to make IBM JDK 7 work with IntelliJ IDEA
  • Go to your Project Structure -> SDK
  • Select IBM JDK if not already selected
  • Under Classpath tab, add a new entry pointing to <JDK_HOME>/jre/bin/default/jclSC170/vm.jar
This should resolve all those compilation errors gone, and you should be back doing something productive. 

Cheers !
- Jay

P.S.: Eclipse is intelligent enough to resolve this vm.jar and have no such issues.

Wednesday, July 30, 2014

Linux: Splitting Large File Into Exact Number Of Character Chunks

Just as a NoteToSelf, Below is simple bash command line to create smaller chunks of files with specific number of characters from a huge text file.

  • Source text file is source.txt
  • Number of characters to split: 100
  • Command Line: cntr=1;for chunk in `sed -e 's/.\{100\}/&\n/g' source.txt`; do echo $chunk > chunk$cntr.txt; cntr=$(( $cntr + 1 )); done

Easy peasy

Cheers !!!
- Jay

Monday, April 14, 2014

Ever growing Java's Collection

With every major release of Java you get to see some really really useful collection classes addressing some real needs and use cases. But with this ever growing classes there is always a question which class is the best for your need. In general you can use couple of classes interchangeably. For example you can use ArrayList as well as LinkedList just to store random number of items in a list. But what if you are really dealing with huge list where you need random access to the list? Is ArrayList best? or LinkedList. To address such questions and help choose best collection class for your need, I stumbled upon this nice flowchart the other day while just going through my google+ stream. Found it useful and hence sharing it over here.

Cheers !!!
- Jay

Reference: From ImmaWake's G+ post 

Wednesday, March 6, 2013

Creating large dummy files for test

At times during development we need to create some large files regardless of what data is there inside. For e.g. to see if your program can handle insanely large file or to see how long it takes to transfer a particular size on a network or on your JMS queue etc. For such matter almost all OS provides some nice ways - which sadly I was not aware till now :-(. Anyway here are the different ways you can create such files under different OS

  • Windows:
    • Open the command shell - cmd
    • Execute the following command in order to create a file of 1mb
      fsutil file createnew ./test.tmp 1048576
  • Linux:
    • Use convert and copy command - dd
    • dd if=/dev/zero of=test.tmp bs=1M count=1
  • OS X & Solaris:
    • mkfile 1m test.tmp
Go fill your disk with insanely large files :-)

 Cheers !!!
- Jay

Friday, February 8, 2013

Import Oracle dump with different table space, schema , roles with imp utility

At (bad)times it happens that for a nasty bug happening only in client environment, we receive dump file (exported using Oracle's exp utility) from client or say from different environment where table space, schema and roles are different from the one we use in development environment. In such a case it becomes difficult or impossible to import such dump file using oracle's imp utility. To tackle such situation there is a kind of workaround.

Note: Base assumption over here is you already have a local database in your development environment having the structurally same schema as you wish to import from the dump file. If this is the case below are the steps
  1. Disable all the constraints: Below script will give you ALTER TABLE scripts to disable all the constraints in your schema (the one to which you want to import the data from dump)
    SELECT 'ALTER TABLE'||' '||owner||'.'||table_name||' DISABLE CONSTRAINT '||constraint_name||' ;' FROM dba_constraints WHERE constraint_type = 'R' and owner='<OWNER>' and status = 'ENABLED';
  2. Truncate all the tables: Below script will give you TRUNCATE TABLE scripts for all the tables in your schema (the one to which you want to import the data from dump)
  3. Import data from the dump: Now you have a clean schema with only structure. Now you need to import ONLY data from the dump. No structure, constraints etc. Below is the script to import only data using imp utility.
    imp <USER>/<PASSWORD>@<SCHEMA_NAME> file=<DUMPFILE_NAME> INDEXES=y full=y data_only=y
  4. Enable all constraints: Below script will give you ALTER TABLE scripts to enable all the constraints in your schema
    SELECT 'ALTER TABLE'||' '||owner||'.'||table_name||' ENABLE CONSTRAINT '||constraint_name||' ;' FROM dba_constraints WHERE constraint_type = 'R' and owner='<OWNER>' and status = 'DISABLED';
  5. Done
Cheers !!!
- Jay

Ref: Got scripts in step 1, 2 and 4 from Sergey. Thanks Sergey

Monday, October 1, 2012

Importing Eclipse Workspace Settings From An Old Workspace

This is a classic problem I guess any java developer or better say any eclipse developer would have faced or is facing every other day. I've been using eclipse as my primary IDE for years and like most of the users, I also have multiple workspaces to manage my code base depending upon the trunk/branch or any particular release I'm working on. Having multiple workspaces makes life so easy and work so hassle free, but it also comes with some "extra overhead" of having consistence settings across the workspace and at time across the instances (home/work). Until sometime back I used to set all the configuration (except formatters) each time I create new workspace and also had to update any settings I change in workspace to another. Recently I found a easy way to have same settings in matter of seconds from an existing workspace to the new workspace. This is what I'm going to show you here in this post. To do so follow the below mentioned simple steps.

  1. Create the new workspace.
  2. Close your eclipse instance having this new workspace open.
  3. Go to your old workspace file system from which you want your preferences Copy the directory <oldworkspaceroot>\.metadata\.plugins\org.eclipse.core.runtime\.settings to your <newworkspaceroot>\.metadata\.plugins\org.eclipse.core.runtime\
  4. Start your eclipse. 
  5. Done!!!
Cheers !!!
- Jay
Disclaimer : This is a personal blog and all content represent what I think and it does not advocate/support/advertise any other person/company. I do not earn money or intended to do so with this blog or any of the contents the blog hosts (except the google ads which you see). If I post something here that you find helpful, that's wonderful. Just in case, if I say something stupid, the stupidity is mine, and mine alone and I can not be held for anything if you fall for such stupidity :-). I cannot be held responsible for any kind of damage that may be caused by downloading or viewing the files or information provided herewith. Anybody and everybody can use/refer the contents of this blog at their own will and of course at own risk. There is no need for any kind of approval of the author. Although it would be great if feedback is left for any such usage to the author.