Skip to content

Commit

Permalink
Merge pull request #5 from vhalbert/teiid-2258
Browse files Browse the repository at this point in the history
TEIID-2258 - initial creation of the connector-infinispan to support the...
  • Loading branch information
rareddy committed Oct 15, 2012
2 parents a81d210 + b8fec5c commit c2f71f9
Show file tree
Hide file tree
Showing 16 changed files with 1,220 additions and 0 deletions.
113 changes: 113 additions & 0 deletions connectors/connector-infinispan/pom.xml
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>connectors</artifactId>
<groupId>org.jboss.teiid</groupId>
<version>8.2.0.Beta1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector-infinispan</artifactId>
<groupId>org.jboss.teiid.connectors</groupId>
<packaging>rar</packaging>
<name>Infinispan Connector</name>
<description>This connector creates the connection to the Infinispan Cache</description>
<properties>
<version.infinispan>5.1.2.FINAL</version.infinispan>
</properties>
<dependencies>

<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-common-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.teiid.connectors</groupId>
<artifactId>translator-object</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<version>1.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${version.infinispan}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
<version>${version.infinispan}</version>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-hotrod</artifactId>
<version>${version.org.infinispan}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>build_jar</id>
<phase>process-classes</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestFile>src/main/rar/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</execution>
<execution>
<id>deploy_jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>lib</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@@ -0,0 +1,103 @@
/*
* JBoss, Home of Professional Open Source.
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/

package org.teiid.resource.adapter.infinispan;

import java.util.Map;

import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.resource.spi.BasicConnection;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.ObjectConnection;


/**
* Represents a connection to an Infinispan cache.
*/
public class InfinispanConnectionImpl extends BasicConnection implements ObjectConnection {

private InfinispanManagedConnectionFactory config;

public InfinispanConnectionImpl(InfinispanManagedConnectionFactory config) {
this.config = config;

LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Infinispan Connection has been newly created."); //$NON-NLS-1$
}

/**
* Close the connection, if a connection requires closing.
* (non-Javadoc)
*/
@Override
public void close() {
config = null;
}

/**
* Will return <code>true</true> if the CacheContainer has been started.
* @return boolean true if CacheContainer has been started
*/
public boolean isAlive() {
boolean alive = (config == null ? false : config.getCacheManager() != null);
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Infinispan Cache Connection is alive: " + alive); //$NON-NLS-1$
return (alive);
}

@Override
public Map<?, ?> getMap(String name) throws TranslatorException {
Map<?,?> m = null;
LogManager
.logTrace(LogConstants.CTX_CONNECTOR, "=== GetMap : " + name + "==="); //$NON-NLS-1$

m = config.getCacheManager().getCache();

if (name == null) {
m = config.getCacheManager().getCache();
} else {
m = config.getCacheManager().getCache(name);
}

if (m == null) {
final String msg = InfinispanPlugin.Util.getString("InfinispanConnection.cacheNotDefined", (name != null ? name : "Default") ); //$NON-NLS-1$
throw new TranslatorException(msg);
}

return m;
}

@Override
public Class<?> getType(String name) throws TranslatorException {
LogManager
.logTrace(LogConstants.CTX_CONNECTOR,
"=== GetType : " + name + "==="); //$NON-NLS-1$

Class<?> type = config.getCacheType(name);
if (type != null) {
return type;
}
final String msg = InfinispanPlugin.Util.getString("InfinispanConnection.typeNotFound", (name != null ? name : "Default") ); //$NON-NLS-1$
throw new TranslatorException(msg);
}


}

0 comments on commit c2f71f9

Please sign in to comment.