Permalink
Browse files

1) Paramterized constructor for all databases for client type

2) Fixed HBaseSchemaManagerTest.
  • Loading branch information...
1 parent 66c7740 commit 397ddd6a52f8c3c803f9bfeb7621391b7d52d5ca @kkmishra kkmishra committed Apr 11, 2012
View
7 kundera-cassandra/src/main/java/com/impetus/client/cassandra/pelops/PelopsClientFactory.java
@@ -30,6 +30,7 @@
import com.impetus.client.cassandra.schemamanager.CassandraSchemaManager;
import com.impetus.kundera.PersistenceProperties;
import com.impetus.kundera.client.Client;
+import com.impetus.kundera.client.ClientType;
import com.impetus.kundera.configure.schema.api.SchemaManager;
import com.impetus.kundera.index.IndexManager;
import com.impetus.kundera.index.LuceneIndexer;
@@ -75,8 +76,8 @@ public void initialize()
reader = new CassandraEntityReader();
- schemaManager = new CassandraSchemaManager();
-// schemaManager.exportSchema();
+ schemaManager = new CassandraSchemaManager(ClientType.PELOPS);
+ schemaManager.exportSchema();
}
/*
@@ -139,7 +140,7 @@ public boolean isThreadSafe()
public void destroy()
{
indexManager.close();
-// schemaManager.dropSchema();
+ schemaManager.dropSchema();
// Pelops.shutdown();
}
View
13 ...ndra/src/main/java/com/impetus/client/cassandra/schemamanager/CassandraSchemaManager.java
@@ -61,14 +61,23 @@
*/
private static final Logger logger = LoggerFactory.getLogger(CassandraSchemaManager.class);
+ /**
+ * Instantiates a new cassandra schema manager.
+ *
+ * @param client the client
+ */
+ public CassandraSchemaManager(ClientType client)
+ {
+ super(client);
+ }
+
@Override
/**
* Export schema handles the handleOperation method.
*/
public void exportSchema()
{
- super.exportSchema(ClientType.PELOPS);
-
+ super.exportSchema();
}
/**
View
19 kundera-core/src/main/java/com/impetus/kundera/configure/schema/ColumnInfo.java
@@ -42,7 +42,8 @@ public ColumnInfo()
}
/**
- * Equals method compare two object of columnInfo on the basis of their name.
+ * Equals method compare two object of columnInfo on the basis of their
+ * name.
*
* @param Object
* instance.
@@ -52,15 +53,13 @@ public ColumnInfo()
@Override
public boolean equals(Object obj)
{
-
- /// if object's class and column name matches then return true;
-
- return obj != null &&
- obj instanceof ColumnInfo &&
- ((ColumnInfo) obj).columnName != null
- ? this.columnName != null && this.columnName.equals(((ColumnInfo) obj).columnName)
- : false;
-
+
+ // / if object's class and column name matches then return true;
+
+ return obj != null && obj instanceof ColumnInfo && ((ColumnInfo) obj).columnName != null ? this.columnName != null
+ && this.columnName.equals(((ColumnInfo) obj).columnName) && this.type.equals(((ColumnInfo) obj).type)
+ : false;
+
}
/**
View
49 kundera-core/src/main/java/com/impetus/kundera/configure/schema/TableInfo.java
@@ -65,27 +65,34 @@ public TableInfo()
@Override
public boolean equals(Object obj)
{
- boolean result = false;
- if (obj == null)
- {
- result = false;
- }
- else if (getClass() != obj.getClass())
- {
- result = false;
- }
- else
- {
- TableInfo tableInfo = (TableInfo) obj;
-
- if (this.tableName != null && this.tableName.equals(tableInfo.tableName)
- && this.type.equals(tableInfo.type) && this.tableIdType.equals(tableInfo.tableIdType))
- {
-
- result = true;
- }
- }
- return result;
+
+ return obj != null && obj instanceof TableInfo && ((TableInfo) obj).tableName != null ? this.tableName != null
+ && this.tableName.equals(((TableInfo) obj).tableName)
+ && this.tableIdType.equals(((TableInfo) obj).tableIdType) : false;
+
+ // boolean result = false;
+ // if (obj == null)
+ // {
+ // result = false;
+ // }
+ // else if (getClass() != obj.getClass())
+ // {
+ // result = false;
+ // }
+ // else
+ // {
+ // TableInfo tableInfo = (TableInfo) obj;
+ //
+ // if (this.tableName != null &&
+ // this.tableName.equals(tableInfo.tableName)
+ // && this.type.equals(tableInfo.type) &&
+ // this.tableIdType.equals(tableInfo.tableIdType))
+ // {
+ //
+ // result = true;
+ // }
+ // }
+ // return result;
}
/**
View
13 ...ra-core/src/main/java/com/impetus/kundera/configure/schema/api/AbstractSchemaManager.java
@@ -61,13 +61,18 @@
/** The use secondry index variable. */
protected boolean useSecondryIndex = false;
+ public AbstractSchemaManager(ClientType client)
+ {
+ kundera_client = client.name();
+ }
+
// @Override
/**
* Export schema handles the handleOperation method.
*
* @param hbase
*/
- protected void exportSchema(ClientType client)
+ protected void exportSchema()
{
ApplicationMetadata appMetadata = KunderaMetadata.INSTANCE.getApplicationMetadata();
@@ -79,9 +84,9 @@ protected void exportSchema(ClientType client)
{
// Get persistence unit metadata
puMetadata = KunderaMetadata.INSTANCE.getApplicationMetadata().getPersistenceUnitMetadata(pu);
-
- kundera_client = puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_CLIENT);
- if (kundera_client.equalsIgnoreCase(client.toString()))
+ if (kundera_client != null
+ && kundera_client.equalsIgnoreCase(puMetadata.getProperties().getProperty(
+ PersistenceProperties.KUNDERA_CLIENT)))
{
port = puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_PORT);
host = puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_NODES);
View
3 kundera-hbase/src/main/java/com/impetus/client/hbase/HBaseClientFactory.java
@@ -25,6 +25,7 @@
import com.impetus.client.hbase.schemamanager.HBaseSchemaManager;
import com.impetus.kundera.PersistenceProperties;
import com.impetus.kundera.client.Client;
+import com.impetus.kundera.client.ClientType;
import com.impetus.kundera.configure.schema.api.SchemaManager;
import com.impetus.kundera.index.IndexManager;
import com.impetus.kundera.index.LuceneIndexer;
@@ -95,7 +96,7 @@ public void initialize()
conf = new HBaseConfiguration(hadoopConf);
reader = new HBaseEntityReader();
- schemaManager = new HBaseSchemaManager();
+ schemaManager = new HBaseSchemaManager(ClientType.HBASE);
schemaManager.exportSchema();
}
View
7 kundera-hbase/src/main/java/com/impetus/client/hbase/schemamanager/HBaseSchemaManager.java
@@ -56,13 +56,18 @@
*/
private static final Logger logger = LoggerFactory.getLogger(HBaseSchemaManager.class);
+ public HBaseSchemaManager(ClientType client)
+ {
+ super(client);
+ }
+
@Override
/**
* Export schema handles the handleOperation method.
*/
public void exportSchema()
{
- super.exportSchema(ClientType.HBASE);
+ super.exportSchema();
}
/**
View
86 ...schemaManager/HbaseSchemaManagerTest.java → ...schemaManager/HBaseSchemaManagerTest.java
@@ -35,6 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.impetus.client.hbase.junits.HBaseCli;
import com.impetus.kundera.Constants;
import com.impetus.kundera.PersistenceProperties;
import com.impetus.kundera.configure.SchemaConfiguration;
@@ -45,15 +46,17 @@
import com.impetus.kundera.metadata.model.PersistenceUnitMetadata;
import com.impetus.kundera.metadata.processor.TableProcessor;
import com.impetus.kundera.persistence.EntityManagerFactoryImpl;
+
/**
- * HbaseSchemaManagerTest class test the auto creation schema property in hbase data store.
+ * HbaseSchemaManagerTest class test the auto creation schema property in hbase
+ * data store.
*
* @author Kuldeep.Kumar
- *
+ *
*/
-public class HbaseSchemaManagerTest
+public class HBaseSchemaManagerTest
{
-
+
/** The pu metadata. */
private PersistenceUnitMetadata puMetadata;
@@ -70,43 +73,48 @@
private static HBaseAdmin admin;
/** The Constant logger. */
- private static final Logger logger = LoggerFactory.getLogger(HbaseSchemaManagerTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(HBaseSchemaManagerTest.class);
/**
* Sets the up.
- *
- * @throws Exception the exception
+ *
+ * @throws Exception
+ * the exception
*/
@Before
public void setUp() throws Exception
{
- // HBaseCli.startCluster();
+ HBaseCli.startCluster();
configuration = new SchemaConfiguration("hbase");
getEntityManagerFactory();
- puMetadata = KunderaMetadata.INSTANCE.getApplicationMetadata().getPersistenceUnitMetadata("hbase");
- port = puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_PORT);
- host = puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_NODES);
- Configuration hadoopConf = new Configuration();
- hadoopConf.set("hbase.master", host + ":" + port);
- HBaseConfiguration conf = new HBaseConfiguration(hadoopConf);
- try
- {
- admin = new HBaseAdmin(conf);
- }
- catch (MasterNotRunningException e)
- {
- logger.equals("master not running exception" + e.getMessage());
- }
- catch (ZooKeeperConnectionException e)
- {
- logger.equals("zookeeper connection exception" + e.getMessage());
- }
+ // puMetadata =
+ // KunderaMetadata.INSTANCE.getApplicationMetadata().getPersistenceUnitMetadata("hbase");
+ // port =
+ // puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_PORT);
+ // host =
+ // puMetadata.getProperties().getProperty(PersistenceProperties.KUNDERA_NODES);
+ // Configuration hadoopConf = new Configuration();
+ // hadoopConf.set("hbase.master", host + ":" + port);
+ // HBaseConfiguration conf = new HBaseConfiguration(hadoopConf);
+ // try
+ // {
+ // admin = new HBaseAdmin(conf);
+ // }
+ // catch (MasterNotRunningException e)
+ // {
+ // logger.equals("master not running exception" + e.getMessage());
+ // }
+ // catch (ZooKeeperConnectionException e)
+ // {
+ // logger.equals("zookeeper connection exception" + e.getMessage());
+ // }
}
/**
* Tear down.
- *
- * @throws Exception the exception
+ *
+ * @throws Exception
+ * the exception
*/
@After
public void tearDown() throws Exception
@@ -121,16 +129,16 @@ public void testSchemaOperation()
{
try
{
- Assert.assertTrue(admin.isTableAvailable("HbaseEntitySimple"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntitySuper"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityAddressUni1To1"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityAddressUniMTo1"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityAddressUni1ToM"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityPersonUni1ToM"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityPersonUni1To1"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityPersonUniMto1"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityAddressUni1To1PK"));
- Assert.assertTrue(admin.isTableAvailable("HbaseEntityPersonUni1To1PK"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntitySimple"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntitySuper"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityAddressUni1To1"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityAddressUniMTo1"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityAddressUni1ToM"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityPersonUni1ToM"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityPersonUni1To1"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityPersonUniMto1"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityAddressUni1To1PK"));
+ Assert.assertTrue(HBaseCli.utility.getHBaseAdmin().isTableAvailable("HbaseEntityPersonUni1To1PK"));
}
catch (IOException e)
{
@@ -140,7 +148,7 @@ public void testSchemaOperation()
/**
* Gets the entity manager factory.
- *
+ *
* @return the entity manager factory
*/
private EntityManagerFactoryImpl getEntityManagerFactory()
View
6 kundera-mongo/pom.xml
@@ -26,6 +26,12 @@
<artifactId>mongo</artifactId>
<version>2.5.3</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!-- Assembly build -->
View
3 kundera-mongo/src/main/java/com/impetus/client/mongodb/MongoDBClientFactory.java
@@ -27,6 +27,7 @@
import com.impetus.client.mongodb.schemamanager.MongoDBSchemaManager;
import com.impetus.kundera.PersistenceProperties;
import com.impetus.kundera.client.Client;
+import com.impetus.kundera.client.ClientType;
import com.impetus.kundera.configure.schema.api.SchemaManager;
import com.impetus.kundera.index.IndexManager;
import com.impetus.kundera.index.LuceneIndexer;
@@ -68,7 +69,7 @@ public void initialize()
indexManager = new IndexManager(LuceneIndexer.getInstance(new StandardAnalyzer(Version.LUCENE_34),
luceneDirPath));
reader = new MongoEntityReader();
- schemaManager = new MongoDBSchemaManager();
+ schemaManager = new MongoDBSchemaManager(ClientType.MONGODB);
schemaManager.exportSchema();
}
View
9 ...ra-mongo/src/main/java/com/impetus/client/mongodb/schemamanager/MongoDBSchemaManager.java
@@ -55,13 +55,18 @@
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(MongoDBSchemaManager.class);
+ public MongoDBSchemaManager(ClientType client)
+ {
+ super(client);
+ }
+
@Override
/**
* Export schema handles the handleOperation method.
*/
public void exportSchema()
{
- super.exportSchema(ClientType.MONGODB);
+ super.exportSchema();
}
/**
@@ -126,7 +131,7 @@ protected void validate(List<TableInfo> tableInfos)
if (db == null)
{
-
+
logger.error("database " + databaseName + "does not exist");
throw new SchemaGenerationException("mongoDb", databaseName);
}

0 comments on commit 397ddd6

Please sign in to comment.