org.apache.gora.sql.store
Class SqlStore<K,T extends Persistent>

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:
java.io.Closeable, DataStore<K,T>, org.apache.hadoop.conf.Configurable, org.apache.hadoop.io.Writable

public class SqlStore<K,T extends Persistent>
extends DataStoreBase<K,T>

A DataStore implementation for RDBMS with a SQL interface. SqlStore uses JDBC drivers to communicate with the DB.


Nested Class Summary
static class SqlStore.DBVendor
          The vendor of the DB
 
Field Summary
protected static java.lang.String DEFAULT_MAPPING_FILE
           
protected static java.lang.String DRIVER_CLASS_PROPERTY
          The JDBC Driver class name
protected static java.lang.String PASSWORD_PROPERTY
          Password to access the database
protected static java.lang.String URL_PROPERTY
          JDBC Database access URL
protected static java.lang.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, persistentClass, properties, schema
 
Constructor Summary
SqlStore()
           
 
Method Summary
 void close()
           
 void createSchema()
           
protected  com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable createSqlTable(SqlMapping mapping)
           
 boolean delete(K key)
           
 long deleteByQuery(Query<K,T> query)
           
 void deleteSchema()
           
 Result<K,T> execute(Query<K,T> query)
           
 void flush()
           
 T get(K key, java.lang.String[] requestFields)
           
protected  byte[] getBytes(java.sql.ResultSet resultSet, int columnIndex, org.apache.avro.Schema schema, Column column)
           
protected  java.sql.Connection getConnection()
           
protected  java.lang.String getIdentifier(java.lang.String identifier)
           
 java.util.List<PartitionQuery<K,T>> getPartitions(Query<K,T> query)
           
 java.lang.String getSchemaName()
           
protected  void initDbMetadata()
           
 void initialize(java.lang.Class<K> keyClass, java.lang.Class<T> persistentClass, java.util.Properties properties)
           
 Query<K,T> newQuery()
           
 void put(K key, T persistent)
           
protected  java.lang.Object readField(java.sql.ResultSet resultSet, int columnIndex, java.lang.Object field, org.apache.avro.Schema schema, Column column)
           
protected  SqlMapping readMapping(java.lang.String filename)
           
 T readObject(java.sql.ResultSet rs, T persistent, java.lang.String[] requestFields)
           
 K readPrimaryKey(java.sql.ResultSet resultSet)
           
 boolean schemaExists()
           
protected  void setBytes(java.sql.PreparedStatement statement, Column column, int index, byte[] value)
           
protected  void setField(java.sql.PreparedStatement statement, Column column, org.apache.avro.Schema schema, int index, java.lang.Object object)
          Serializes the field using Avro to a BLOB field
 void setObject(java.sql.PreparedStatement statement, int index, java.lang.Object object, org.apache.avro.Schema schema, Column column)
          Sets the object to the preparedStatement by it's schema
protected
<V> void
setObject(java.sql.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, 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 java.lang.String DRIVER_CLASS_PROPERTY
The JDBC Driver class name

See Also:
Constant Field Values

URL_PROPERTY

protected static final java.lang.String URL_PROPERTY
JDBC Database access URL

See Also:
Constant Field Values

USERNAME_PROPERTY

protected static final java.lang.String USERNAME_PROPERTY
User name to access the database

See Also:
Constant Field Values

PASSWORD_PROPERTY

protected static final java.lang.String PASSWORD_PROPERTY
Password to access the database

See Also:
Constant Field Values

DEFAULT_MAPPING_FILE

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

SqlStore

public SqlStore()
Method Detail

initialize

public void initialize(java.lang.Class<K> keyClass,
                       java.lang.Class<T> persistentClass,
                       java.util.Properties properties)
                throws java.io.IOException
Specified by:
initialize in interface DataStore<K,T extends Persistent>
Overrides:
initialize in class DataStoreBase<K,T extends Persistent>
Throws:
java.io.IOException

getSchemaName

public java.lang.String getSchemaName()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

createSchema

public void createSchema()
                  throws java.io.IOException
Throws:
java.io.IOException

deleteSchema

public void deleteSchema()
                  throws java.io.IOException
Throws:
java.io.IOException

schemaExists

public boolean schemaExists()
                     throws java.io.IOException
Throws:
java.io.IOException

delete

public boolean delete(K key)
               throws java.io.IOException
Throws:
java.io.IOException

deleteByQuery

public long deleteByQuery(Query<K,T> query)
                   throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

get

public T get(K key,
             java.lang.String[] requestFields)
                         throws java.io.IOException
Throws:
java.io.IOException

execute

public Result<K,T> execute(Query<K,T> query)
                                       throws java.io.IOException
Throws:
java.io.IOException

readPrimaryKey

public K readPrimaryKey(java.sql.ResultSet resultSet)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

readObject

public T readObject(java.sql.ResultSet rs,
                    T persistent,
                    java.lang.String[] requestFields)
                                throws java.sql.SQLException,
                                       java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

getBytes

protected byte[] getBytes(java.sql.ResultSet resultSet,
                          int columnIndex,
                          org.apache.avro.Schema schema,
                          Column column)
                   throws java.sql.SQLException,
                          java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

readField

protected java.lang.Object readField(java.sql.ResultSet resultSet,
                                     int columnIndex,
                                     java.lang.Object field,
                                     org.apache.avro.Schema schema,
                                     Column column)
                              throws java.sql.SQLException,
                                     java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

getPartitions

public java.util.List<PartitionQuery<K,T>> getPartitions(Query<K,T> query)
                                                                     throws java.io.IOException
Throws:
java.io.IOException

newQuery

public Query<K,T> newQuery()

put

public void put(K key,
                T persistent)
         throws java.io.IOException
Throws:
java.io.IOException

setObject

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

Throws:
java.sql.SQLException
java.io.IOException

setObject

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

setBytes

protected void setBytes(java.sql.PreparedStatement statement,
                        Column column,
                        int index,
                        byte[] value)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

setField

protected void setField(java.sql.PreparedStatement statement,
                        Column column,
                        org.apache.avro.Schema schema,
                        int index,
                        java.lang.Object object)
                 throws java.io.IOException,
                        java.sql.SQLException
Serializes the field using Avro to a BLOB field

Throws:
java.io.IOException
java.sql.SQLException

getConnection

protected java.sql.Connection getConnection()
                                     throws java.io.IOException
Throws:
java.io.IOException

initDbMetadata

protected void initDbMetadata()
                       throws java.io.IOException
Throws:
java.io.IOException

getIdentifier

protected java.lang.String getIdentifier(java.lang.String identifier)

createSqlTable

protected com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable createSqlTable(SqlMapping mapping)

readMapping

protected SqlMapping readMapping(java.lang.String filename)
                          throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.