org.apache.gora.sql.store
Class SqlStore<K,T extends org.apache.gora.persistency.impl.PersistentBase>

java.lang.Object
  extended by org.apache.gora.store.impl.DataStoreBase<K,T>
      extended by org.apache.gora.sql.store.SqlStore<K,T>
All Implemented Interfaces:
Closeable, org.apache.gora.store.DataStore<K,T>, org.apache.hadoop.conf.Configurable, org.apache.hadoop.io.Writable

public class SqlStore<K,T extends org.apache.gora.persistency.impl.PersistentBase>
extends org.apache.gora.store.impl.DataStoreBase<K,T>

A DataStore implementation for RDBMS with a SQL interface. SqlStore uses the JOOQ API and various JDBC drivers to communicate with the DB. Through use of the JOOQ API this SqlStore aims to support numerous SQL database stores namely; DB2 9.7 Derby 10.8 H2 1.3.161 HSQLDB 2.2.5 Ingres 10.1.0 MySQL 5.1.41 and 5.5.8 Oracle XE 10.2.0.1.0 and 11g PostgreSQL 9.0 SQLite with inofficial JDBC driver v056 SQL Server 2008 R8 Sybase Adaptive Server Enterprise 15.5 Sybase SQL Anywhere 12 This DataStore is currently in development, and requires a complete re-write as per GORA-86 Please see https://issues.apache.org/jira/browse/GORA-86


Nested Class Summary
static class SqlStore.DBVendor
          The vendor of the DB
 
Field Summary
protected static String DEFAULT_MAPPING_FILE
           
protected static String DRIVER_CLASS_PROPERTY
          The JDBC Driver class name
protected static String PASSWORD_PROPERTY
          Password to access the database
protected static String URL_PROPERTY
          JDBC Database access URL
protected static String USERNAME_PROPERTY
          User name to access the database
 
Fields inherited from class org.apache.gora.store.impl.DataStoreBase
autoCreateSchema, beanFactory, conf, datumReader, datumWriter, fieldMap, keyClass, LOG, persistentClass, properties, schema
 
Constructor Summary
SqlStore()
           
 
Method Summary
 void close()
           
 void createSchema()
           
protected  void createSqlTable()
           
 boolean delete(K key)
           
 long deleteByQuery(org.apache.gora.query.Query<K,T> query)
           
 void deleteSchema()
           
 org.apache.gora.query.Result<K,T> execute(org.apache.gora.query.Query<K,T> query)
           
 void flush()
           
 T get(K key, String[] requestFields)
           
protected  byte[] getBytes()
           
protected  Connection getConnection()
           
protected  String getIdentifier()
           
 List<org.apache.gora.query.PartitionQuery<K,T>> getPartitions(org.apache.gora.query.Query<K,T> query)
           
 String getSchemaName()
           
protected  void initDbMetadata()
           
 void initialize()
           
 org.apache.gora.query.Query<K,T> newQuery()
           
 void put(K key, T persistent)
           
protected  Object readField()
           
protected  SqlMapping readMapping()
           
 T readObject(ResultSet rs, T persistent, String[] requestFields)
           
 K readPrimaryKey(ResultSet resultSet)
           
 boolean schemaExists()
           
protected  void setBytes()
           
protected  void setField()
          Serializes the field using Avro to a BLOB field
 void setObject(PreparedStatement statement, int index, Object object, org.apache.avro.Schema schema, Column column)
          Sets the object to the preparedStatement by it's schema
protected
<V> void
setObject(PreparedStatement statement, int index, V object, int objectType, Column column)
           
 
Methods inherited from class org.apache.gora.store.impl.DataStoreBase
equals, get, getBeanFactory, getConf, getFieldsToQuery, getKeyClass, getOrCreateConf, getPersistentClass, getSchemaName, initialize, newKey, newPersistent, readFields, setBeanFactory, setConf, setKeyClass, setPersistentClass, truncateSchema, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRIVER_CLASS_PROPERTY

protected static final String DRIVER_CLASS_PROPERTY
The JDBC Driver class name

See Also:
Constant Field Values

URL_PROPERTY

protected static final String URL_PROPERTY
JDBC Database access URL

See Also:
Constant Field Values

USERNAME_PROPERTY

protected static final String USERNAME_PROPERTY
User name to access the database

See Also:
Constant Field Values

PASSWORD_PROPERTY

protected static final String PASSWORD_PROPERTY
Password to access the database

See Also:
Constant Field Values

DEFAULT_MAPPING_FILE

protected static final String DEFAULT_MAPPING_FILE
See Also:
Constant Field Values
Constructor Detail

SqlStore

public SqlStore()
Method Detail

initialize

public void initialize()
                throws IOException
Throws:
IOException

getSchemaName

public String getSchemaName()

close

public void close()

createSchema

public void createSchema()

deleteSchema

public void deleteSchema()

schemaExists

public boolean schemaExists()

delete

public boolean delete(K key)

deleteByQuery

public long deleteByQuery(org.apache.gora.query.Query<K,T> query)

flush

public void flush()

get

public T get(K key,
             String[] requestFields)

execute

public org.apache.gora.query.Result<K,T> execute(org.apache.gora.query.Query<K,T> query)

readPrimaryKey

public K readPrimaryKey(ResultSet resultSet)
                 throws SQLException
Throws:
SQLException

readObject

public T readObject(ResultSet rs,
                    T persistent,
                    String[] requestFields)
                                                                     throws SQLException,
                                                                            IOException
Throws:
SQLException
IOException

getBytes

protected byte[] getBytes()
                   throws SQLException,
                          IOException
Throws:
SQLException
IOException

readField

protected Object readField()
                    throws SQLException,
                           IOException
Throws:
SQLException
IOException

getPartitions

public List<org.apache.gora.query.PartitionQuery<K,T>> getPartitions(org.apache.gora.query.Query<K,T> query)
                                                                                                                      throws IOException
Throws:
IOException

newQuery

public org.apache.gora.query.Query<K,T> newQuery()

put

public void put(K key,
                T persistent)

setObject

public void setObject(PreparedStatement statement,
                      int index,
                      Object object,
                      org.apache.avro.Schema schema,
                      Column column)
               throws SQLException,
                      IOException
Sets the object to the preparedStatement by it's schema

Throws:
SQLException
IOException

setObject

protected <V> void setObject(PreparedStatement statement,
                             int index,
                             V object,
                             int objectType,
                             Column column)
                  throws SQLException,
                         IOException
Throws:
SQLException
IOException

setBytes

protected void setBytes()
                 throws SQLException
Throws:
SQLException

setField

protected void setField()
                 throws IOException,
                        SQLException
Serializes the field using Avro to a BLOB field

Throws:
IOException
SQLException

getConnection

protected Connection getConnection()
                            throws IOException
Throws:
IOException

initDbMetadata

protected void initDbMetadata()
                       throws IOException
Throws:
IOException

getIdentifier

protected String getIdentifier()

createSqlTable

protected void createSqlTable()

readMapping

protected SqlMapping readMapping()
                          throws IOException
Throws:
IOException


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.