<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Getting+Started">Getting Started</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~rareddy">Ramesh Reddy</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code:JAVA|title=Create a Resource Adapter(file)} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code:JAVA|title=Create a Resource Adapter(file) based Data source} <br></td></tr>
            <tr><td class="diff-unchanged" >connectAsAdmin(); <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>To learn the basics of <a href="http://groovy.codehaus.org/" class="external-link" rel="nofollow">Groovy</a> take a look at their documents and tutorials on their website.</p>

<p>Basic knowledge of the Java programming language and types is required in order to effectively design and develop scripts using the AdminShell. To learn Java language find learning resources at <a href="http://java.sun.com/" class="external-link" rel="nofollow">http://java.sun.com</a>.</p>

<p>You can learn about the Teiid AdminAPI either using “adminHelp&#40;)” function or by using the JavaDocs.</p>

<p>AdminShell is a specialized version of Groovy which works in several different modes: interactive shell, graphical console, or script run mode. In interactive shell mode &#40;launched via adminshell), the user can invoke connect to a live Teiid system and issue any ad&#45;hoc commands to control the system. The interactive buffer can be used to develop a script and the interactive session input and output can be captured into a log file, more on this later in the document.</p>

<p>In graphical mode &#40;lanched via adminshell&#45;console), the user can develop and run scripts using a text editor that supports syntax highlighting.</p>

<p>In the script run mode, the user can execute/play back previously developed scripts. This mode especially useful to automate any testing or to perform any repeated configurations/migrations changes to a Teiid system.</p>


<h1><a name="GettingStarted-EssentialRules"></a>Essential Rules</h1>
<p>To use AdminShell successfully, there are some basic syntactical rules to keep in mind.</p>

<ol>
        <li>In interactive shell mode, most commands &#40;as seen by the help command) are used to control shell behaviour and are not general Groovy scripting constructs. Admin methods will typically be called using functional notation:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">connectAsAdmin()</pre>
</div></div></li>
        <li>All commands and functions are case sensitive.</li>
        <li>An ending semicolon is optional for Groovy statements.</li>
        <li>If a function requires input parameter&#40;s), they should be declared inside "&#40;" and ")".  A function may have more than one parameter.  String parameters can be wrapped in double or single quotes.  Example:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
connectAsAdmin("localhost", "9999", "user", "password", "conn1")
</pre>
</div></div></li>
        <li>Other Java methods and classes can be used from your scripts, if the required Java class libraries are already in class path. You may place additional jars in the lib directory to have be automatically part of the class path.  An example showing an import:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
import my.package.*;
myObject = new MyClass();
myObject.doSomething();
</pre>
</div></div></li>
</ol>


<p>To execute the commands and arbitrary script in interactive mode you enter them first and press enter to execute, then enter the next line, so on.</p>

<p>To exit the tool in the interactive mode, first disconnect if you are connected to the Teiid system by executing “disconnect&#40;);” then type "exit". In the script mode, when execution of the script finishes the tool will exit automatically, however you still have to disconnect from Teiid system in the script.</p>

<p>Note: If SSL is turned on the Teiid server, you would need to adjust the connection URL and the client SSL settings as necessary &#40;typically this will only be needed for 2&#45;way SSL).</p>


<h1><a name="GettingStarted-Help"></a>Help</h1>
<p>The adminHelp&#40;) methods lists all the available administrative API methods in the AdminShell. Please note that none of the Groovy Shell commands or other available function calls will be shown in this list</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">adminHelp();</pre>
</div></div>
<p>To get a specific definition about a method and it's required input parameters, use adminHelp&#40;"method")</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">adminHelp("deploy");

/*
 *Deploy a VDB from file
 */
void deploy(
    String /* file name */)
  throws AdminException
  throws FileNotFoundException</pre>
</div></div>


<p>The sqlHelp&#40;) methods lists all Sql extension methods.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
sqlHelp();
</pre>
</div></div>

<p>To get a specific definition about a method and it's required input parameters, use sqlHelp&#40;"method")</p>




<h1><a name="GettingStarted-BasicCommands"></a>Basic Commands</h1>
<p>The list below contains some common commands used in AdminShell.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Basic Commands</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">   
println "xxx";   // print something to console

adminHelp();     // shows all the available admin commands; 

sql = connect(); // get an extended Groovy Sql connection using connection.properties file

sql.execute(&lt;SQL&gt;); // run any SQL command. 

connectAsAdmin(); // connect as admin; no need have the vdb name. SQL commands will not work under this connection

println getConnectionName();  // returns the current connection name

useConnection(&lt;connection name&gt;); // switches to using the given connection settings

disconnect();   // disconnects the current connection in the context
</pre>
</div></div>

<p>Some examples</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example of Deploying a VDB</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
connectAsAdmin();
deploy("/path/to/&lt;name&gt;.vdb");

// check to validate the deployment
VDB vdb = getVDB("&lt;name&gt;", 1);
if (vdb != null){
     print (vdb.getName()+"."+vdb.getVersion()+" is deployed";
}
else {
     print ("&lt;name&gt;.vdb failed to deploy";
}
</pre>
</div></div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Create a Datasource(oracle)</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
connectAsAdmin();

// first deploy the JDBC jar file for Oracle
deploy("ojdbc6.jar");

props = new Properties();
props.setProperty("connection-url","jdbc:oracle:thin:@&lt;host&gt;:1521:&lt;sid&gt;");
props.setProperty("user-name", "scott");
props.setProperty("password", "tiger");
        
createDataSource("oracleDS", "ojdbc6.jar", props);
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Create a Resource Adapter(file) based Data source</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
connectAsAdmin();

props = new Properties();
props.setProperty("jndi-name","java:/fileDS");
props.setProperty("ParentDirectory", "${jboss.server.base.dir}/myData");
props.setProperty("AllowParentPaths", "true");

// NOTE:  the 2nd argument, template-name, must match the 'id' of one of the resource-adapters that are currently defined in the server        
createDataSource("MyFile", "file", props);
</pre>
</div></div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Execute SQL Query against Teiid</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
sql = connect("jdbc:teiid:&lt;vdb&gt;@mm://&lt;host&gt;:31000", "user", "user");

// select
sql.eachRow("select * from sys.tables") { println "${it}" }

// update, insert, delete
sql.execute(&lt;sql command&gt;);
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Learn more about <a href="http://groovy.codehaus.org/Tutorial+6+-+Groovy+SQL" class="external-link" rel="nofollow">Groovy SQL</a></td></tr></table></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Getting+Started">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646080&revisedVersion=5&originalVersion=4">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Getting+Started?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>