Revision: 14316
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=14316&view=rev
Author: andy_jefferson
Date: 2012-02-17 14:21:27 +0000 (Fri, 17 Feb 2012)
Log Message:
-----------
[NUCMONGODB-50] Make use of NamingFactory for getting table/column names, now respecting JDO/JPA conventions
Modified Paths:
--------------
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBPersistenceHandler.java
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBStoreManager.java
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBUtils.java
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/FetchFieldManager.java
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/StoreFieldManager.java
platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/query/QueryToMongoDBMapper.java
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBPersistenceHandler.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBPersistenceHandler.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBPersistenceHandler.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -57,6 +57,7 @@
import org.datanucleus.store.fieldmanager.DeleteFieldManager;
import org.datanucleus.store.mongodb.fieldmanager.FetchFieldManager;
import org.datanucleus.store.mongodb.fieldmanager.StoreFieldManager;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.util.Localiser;
import org.datanucleus.util.NucleusLogger;
import org.datanucleus.util.StringUtils;
@@ -117,7 +118,7 @@
AbstractClassMetaData cmd = ops[i].getClassMetaData();
if (!cmd.pkUsesIdentityValueGenerator())
{
- String tableName = MongoDBUtils.getCollectionName(cmd);
+ String tableName = storeMgr.getNamingFactory().getTableName(cmd);
Set<ObjectProvider> opsForTable = opsByTable.get(tableName);
if (opsForTable == null)
{
@@ -237,7 +238,7 @@
op.toPrintableID(), op.getInternalObjectId()));
}
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(storeMgr.getNamingFactory().getTableName(cmd));
DBObject dbObject = getDBObjectForObjectProviderToInsert(op, !cmd.pkUsesIdentityValueGenerator());
NucleusLogger.DATASTORE_NATIVE.debug("Persisting object " + op + " as " + dbObject);
@@ -337,7 +338,7 @@
cmd.getIdentityMetaData().getValueStrategy() != IdentityStrategy.IDENTITY)
{
// Add surrogate datastore identity field (if using identity then just uses "_id" MongoDB special)
- String fieldName = MongoDBUtils.getFieldName(cmd.getIdentityMetaData());
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN);
OID oid = (OID) op.getInternalObjectId();
Object key = oid.getKeyValue();
dbObject.put(fieldName, key);
@@ -347,7 +348,7 @@
{
// Add discriminator field
DiscriminatorMetaData discmd = cmd.getDiscriminatorMetaData();
- String fieldName = MongoDBUtils.getFieldName(discmd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DISCRIMINATOR_COLUMN);
Object discVal = null;
if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.CLASS_NAME)
{
@@ -369,7 +370,7 @@
}
else
{
- String fieldName = MongoDBUtils.getFieldNameForMultitenancy(cmd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.MULTITENANCY_COLUMN);
dbObject.put(fieldName, storeMgr.getStringProperty(PropertyNames.PROPERTY_TENANT_ID));
}
}
@@ -401,7 +402,7 @@
else
{
// Surrogate version
- String fieldName = MongoDBUtils.getFieldName(vermd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN);
dbObject.put(fieldName, new Long(versionNumber));
}
}
@@ -420,7 +421,7 @@
else
{
// Surrogate version
- String fieldName = MongoDBUtils.getFieldName(vermd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN);
dbObject.put(fieldName, ts);
}
}
@@ -465,7 +466,7 @@
op.toPrintableID(), op.getInternalObjectId(), fieldStr.toString()));
}
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(storeMgr.getNamingFactory().getTableName(cmd));
DBObject dbObject = MongoDBUtils.getObjectForObjectProvider(collection, op, true);
if (dbObject == null)
{
@@ -497,7 +498,7 @@
else
{
// Update the stored surrogate value
- String fieldName = MongoDBUtils.getFieldName(vermd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN);
dbObject.put(fieldName, nextVersion);
}
}
@@ -556,7 +557,7 @@
op.toPrintableID(), op.getInternalObjectId()));
}
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(storeMgr.getNamingFactory().getTableName(cmd));
DBObject dbObject = MongoDBUtils.getObjectForObjectProvider(collection, op, true);
if (dbObject == null)
{
@@ -633,7 +634,7 @@
op.toPrintableID(), op.getInternalObjectId()));
}
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(storeMgr.getNamingFactory().getTableName(cmd));
DBObject dbObject = MongoDBUtils.getObjectForObjectProvider(collection, op, false);
if (dbObject == null)
{
@@ -654,7 +655,7 @@
else
{
// Surrogate version
- String fieldName = MongoDBUtils.getFieldName(vermd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN);
Object datastoreVersion = dbObject.get(fieldName);
op.setVersion(datastoreVersion);
}
@@ -695,7 +696,7 @@
try
{
DB db = (DB)mconn.getConnection();
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(storeMgr.getNamingFactory().getTableName(cmd));
DBObject dbObject = MongoDBUtils.getObjectForObjectProvider(collection, op, false);
if (dbObject == null)
{
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBStoreManager.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBStoreManager.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBStoreManager.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -42,6 +42,7 @@
import org.datanucleus.store.StoreData;
import org.datanucleus.store.connection.ManagedConnection;
import org.datanucleus.store.schema.SchemaAwareStoreManager;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.util.Localiser;
import org.datanucleus.util.NucleusLogger;
@@ -181,7 +182,7 @@
protected void createSchemaForClass(AbstractClassMetaData cmd, DB db)
{
- String collectionName = MongoDBUtils.getCollectionName(cmd);
+ String collectionName = getNamingFactory().getTableName(cmd);
DBCollection collection = null;
if (autoCreateTables)
{
@@ -213,7 +214,7 @@
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- idxmds[i].getName(), MongoDBUtils.getCollectionName(cmd), idxObj));
+ idxmds[i].getName(), collectionName, idxObj));
}
collection.ensureIndex(idxObj, idxmds[i].getName(), idxmds[i].isUnique());
}
@@ -227,7 +228,7 @@
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- unimds[i].getName(), MongoDBUtils.getCollectionName(cmd), uniObj));
+ unimds[i].getName(), collectionName, uniObj));
}
collection.ensureIndex(uniObj, unimds[i].getName(), true);
}
@@ -247,7 +248,7 @@
applyIndex = false;
break;
}
- query.append(MongoDBUtils.getFieldName(pkMmd), 1);
+ query.append(getNamingFactory().getColumnName(pkMmd, ColumnType.COLUMN), 1);
}
if (applyIndex)
{
@@ -255,7 +256,7 @@
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- pkName, MongoDBUtils.getCollectionName(cmd), query));
+ pkName, collectionName, query));
}
collection.ensureIndex(query, pkName, true);
}
@@ -269,12 +270,12 @@
else
{
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(cmd.getIdentityMetaData()), 1);
+ query.append(getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN), 1);
String pkName = (cmd.getPrimaryKeyMetaData() != null ? cmd.getPrimaryKeyMetaData().getName() : cmd.getName() + "_PK");
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- pkName, MongoDBUtils.getCollectionName(cmd), query));
+ pkName, collectionName, query));
}
collection.ensureIndex(query, pkName, true);
}
@@ -285,15 +286,16 @@
{
for (int i=0;i<mmds.length;i++)
{
+ String colName = getNamingFactory().getColumnName(mmds[i], ColumnType.COLUMN);
IndexMetaData idxmd = mmds[i].getIndexMetaData();
if (idxmd != null)
{
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(mmds[i]), 1);
+ query.append(colName, 1);
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- idxmd.getName(), MongoDBUtils.getCollectionName(cmd), query));
+ idxmd.getName(), collectionName, query));
}
collection.ensureIndex(query, idxmd.getName(), idxmd.isUnique());
}
@@ -301,11 +303,11 @@
if (unimd != null)
{
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(mmds[i]), 1);
+ query.append(colName, 1);
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled())
{
NucleusLogger.DATASTORE_SCHEMA.debug(LOCALISER.msg("MongoDB.SchemaCreate.Class.Index",
- unimd.getName(), MongoDBUtils.getCollectionName(cmd), query));
+ unimd.getName(), collectionName, query));
}
collection.ensureIndex(query, unimd.getName(), true);
}
@@ -332,7 +334,7 @@
{
String memberName = idxmmds[j].getName();
AbstractMemberMetaData mmd = cmd.getMetaDataForMember(memberName);
- idxObj.append(MongoDBUtils.getFieldName(mmd), 1);
+ idxObj.append(getNamingFactory().getColumnName(mmd, ColumnType.COLUMN), 1);
}
}
return idxObj;
@@ -356,7 +358,7 @@
{
String memberName = unimmds[j].getName();
AbstractMemberMetaData mmd = cmd.getMetaDataForMember(memberName);
- uniObj.append(MongoDBUtils.getFieldName(mmd), 1);
+ uniObj.append(getNamingFactory().getColumnName(mmd, ColumnType.COLUMN), 1);
}
}
return uniObj;
@@ -380,7 +382,7 @@
AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(className, clr);
if (cmd != null)
{
- DBCollection collection = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection collection = db.getCollection(getNamingFactory().getTableName(cmd));
collection.dropIndexes();
collection.drop();
}
@@ -412,7 +414,7 @@
if (cmd != null)
{
// Validate the schema for the class
- String tableName = MongoDBUtils.getCollectionName(cmd);
+ String tableName = getNamingFactory().getTableName(cmd);
if (!db.collectionExists(tableName))
{
success = false;
@@ -484,7 +486,7 @@
for (int i=0;i<pkFieldNumbers.length;i++)
{
AbstractMemberMetaData pkMmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNumbers[i]);
- query.append(MongoDBUtils.getFieldName(pkMmd), 1);
+ query.append(getNamingFactory().getColumnName(pkMmd, ColumnType.COLUMN), 1);
}
String pkName = (cmd.getPrimaryKeyMetaData() != null ? cmd.getPrimaryKeyMetaData().getName() : cmd.getName() + "_PK");
DBObject indexObj = getIndexObjectForIndex(indices, pkName, query, true);
@@ -512,7 +514,7 @@
{
// Check unique index on PK
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(cmd.getIdentityMetaData()), 1);
+ query.append(getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN), 1);
String pkName = (cmd.getPrimaryKeyMetaData() != null ? cmd.getPrimaryKeyMetaData().getName() : cmd.getName() + "_PK");
DBObject indexObj = getIndexObjectForIndex(indices, pkName, query, true);
if (indexObj != null)
@@ -540,7 +542,7 @@
if (idxmd != null)
{
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(mmds[i]), 1);
+ query.append(getNamingFactory().getColumnName(mmds[i], ColumnType.COLUMN), 1);
DBObject indexObj = getIndexObjectForIndex(indices, idxmd.getName(), query, true);
if (indexObj != null)
{
@@ -560,7 +562,7 @@
if (unimd != null)
{
BasicDBObject query = new BasicDBObject();
- query.append(MongoDBUtils.getFieldName(mmds[i]), 1);
+ query.append(getNamingFactory().getColumnName(mmds[i], ColumnType.COLUMN), 1);
DBObject indexObj = getIndexObjectForIndex(indices, unimd.getName(), query, true);
if (indexObj != null)
{
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBUtils.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBUtils.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/MongoDBUtils.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -33,9 +33,7 @@
import org.datanucleus.metadata.AbstractClassMetaData;
import org.datanucleus.metadata.AbstractMemberMetaData;
import org.datanucleus.metadata.ColumnMetaData;
-import org.datanucleus.metadata.DiscriminatorMetaData;
import org.datanucleus.metadata.EmbeddedMetaData;
-import org.datanucleus.metadata.IdentityMetaData;
import org.datanucleus.metadata.IdentityStrategy;
import org.datanucleus.metadata.IdentityType;
import org.datanucleus.metadata.MetaDataUtils;
@@ -44,7 +42,9 @@
import org.datanucleus.store.ExecutionContext;
import org.datanucleus.store.FieldValues;
import org.datanucleus.store.ObjectProvider;
+import org.datanucleus.store.StoreManager;
import org.datanucleus.store.mongodb.fieldmanager.FetchFieldManager;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.util.NucleusLogger;
import com.mongodb.BasicDBObject;
@@ -75,121 +75,6 @@
}
/**
- * Accessor for the MongoDB collection name for this class.
- * Takes the table name if provided, otherwise uses the (short-form) class name
- * @param cmd Metadata for the class
- * @return The collection name
- */
- public static String getCollectionName(AbstractClassMetaData cmd)
- {
- if (cmd.getTable() != null)
- {
- return cmd.getTable();
- }
- return cmd.getName();
- }
-
- /**
- * Accessor for the MongoDB "field" name to store this member under. Takes the column name if provided
- * otherwise the (short-form) member name.
- * @param mmd Metadata for the member
- * @return The field name
- */
- public static String getFieldName(AbstractMemberMetaData mmd)
- {
- // Try the first column if specified
- ColumnMetaData[] colmds = mmd.getColumnMetaData();
- if (colmds != null && colmds.length > 1)
- {
- return colmds[0].getName();
- }
-
- // Fallback to the member name
- return mmd.getName();
- }
-
- /**
- * Accessor for the MongoDB "field" name to store the datastore id under. Takes the column name if provided
- * otherwise "IDENTITY".
- * @param idmd Metadata for the identity
- * @return The field name
- */
- public static String getFieldName(IdentityMetaData idmd)
- {
- if (idmd.getValueStrategy() == IdentityStrategy.IDENTITY)
- {
- // Make use of MongoDB "_id" field
- return "_id";
- }
- else
- {
- ColumnMetaData colmd = idmd.getColumnMetaData();
- if (colmd != null && colmd.getName() != null)
- {
- return colmd.getName();
- }
-
- // Fallback to "IDENTITY"
- return "IDENTITY";
- }
- }
-
- /**
- * Accessor for the MongoDB "field" name to store the surrogate version under. Takes the column name if provided
- * otherwise "VERSION".
- * @param mmd Metadata for the version
- * @return The field name
- */
- public static String getFieldName(VersionMetaData vermd)
- {
- ColumnMetaData colmd = vermd.getColumnMetaData();
- if (colmd != null && colmd.getName() != null)
- {
- return colmd.getName();
- }
-
- // Fallback to "VERSION"
- return "VERSION";
- }
-
- /**
- * Accessor for the MongoDB "field" name to store the discriminator under. Takes the column name if provided
- * otherwise "DISCRIM".
- * @param discmd Metadata for the discriminator
- * @return The field name
- */
- public static String getFieldName(DiscriminatorMetaData discmd)
- {
- // Try the first column if specified
- ColumnMetaData colmd = discmd.getColumnMetaData();
- if (colmd != null && colmd.getName() != null)
- {
- return colmd.getName();
- }
-
- // Fallback to "DISCRIM"
- return "DISCRIM";
- }
-
- /**
- * Accessor for the MongoDB "field" name to store the multitenancy discriminator under.
- * Takes the column name if provided otherwise "TENANT_ID".
- * @param cmd Metadata for the class
- * @return The field name
- */
- public static String getFieldNameForMultitenancy(AbstractClassMetaData cmd)
- {
- // Try the first column if specified
- if (cmd.hasExtension("multitenancy-column-name"))
- {
- return cmd.getValueForExtension("multitenancy-column-name");
- }
-
- // Fallback to "TENANT_ID"
- return "TENANT_ID";
- }
-
- /**
* Accessor for the MongoDB field for the field of this embedded field.
* Uses the column name from the embedded definition (if present), otherwise falls back to
* the column name of the field in its own class definition, otherwise uses its field name.
@@ -239,6 +124,7 @@
// Build query object to use as template for the find
BasicDBObject query = new BasicDBObject();
AbstractClassMetaData cmd = op.getClassMetaData();
+ StoreManager storeMgr = op.getExecutionContext().getStoreManager();
if (cmd.getIdentityType() == IdentityType.APPLICATION)
{
@@ -259,7 +145,7 @@
}
else
{
- query.put(MongoDBUtils.getFieldName(pkMmd), value);
+ query.put(storeMgr.getNamingFactory().getColumnName(pkMmd, ColumnType.COLUMN), value);
}
}
}
@@ -279,14 +165,14 @@
}
else
{
- query.put(MongoDBUtils.getFieldName(cmd.getIdentityMetaData()), value);
+ query.put(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN), value);
}
}
if (cmd.hasDiscriminatorStrategy())
{
// Add discriminator to the query object
- query.put(MongoDBUtils.getFieldName(cmd.getDiscriminatorMetaData()), cmd.getDiscriminatorValue());
+ query.put(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DISCRIMINATOR_COLUMN), cmd.getDiscriminatorValue());
}
if (checkVersion && cmd.isVersioned())
{
@@ -297,13 +183,13 @@
{
// Version field in class
AbstractMemberMetaData verMmd = cmd.getMetaDataForMember(vermd.getFieldName());
- String fieldName = MongoDBUtils.getFieldName(verMmd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(verMmd, ColumnType.COLUMN);
query.put(fieldName, currentVersion);
}
else
{
// Surrogate version field
- String fieldName = MongoDBUtils.getFieldName(vermd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN);
query.put(fieldName, currentVersion);
}
}
@@ -334,6 +220,7 @@
// TODO Allow for subclasses sharing the same table so just doing a single query but with discriminator filtering
Iterator<AbstractClassMetaData> cmdIter = cmds.iterator();
List results = new ArrayList();
+ StoreManager storeMgr = ec.getStoreManager();
ClassLoaderResolver clr = ec.getClassLoaderResolver();
while (cmdIter.hasNext())
{
@@ -360,7 +247,7 @@
if (nested)
{
// Nested Embedded field, so include field
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
fieldsSelection.append(fieldName, 1);
}
else
@@ -371,18 +258,18 @@
}
else
{
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
fieldsSelection.append(fieldName, 1);
}
}
}
if (cmd.getIdentityType() == IdentityType.DATASTORE)
{
- fieldsSelection.append(MongoDBUtils.getFieldName(cmd.getIdentityMetaData()), 1);
+ fieldsSelection.append(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN), 1);
}
if (cmd.isVersioned())
{
- fieldsSelection.append(MongoDBUtils.getFieldName(cmd.getVersionMetaDataForClass()), 1);
+ fieldsSelection.append(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN), 1);
}
BasicDBObject query = new BasicDBObject();
@@ -399,10 +286,10 @@
if (cmd.hasDiscriminatorStrategy())
{
// Discriminator present : Add restriction on the discriminator value for this class
- query.put(MongoDBUtils.getFieldName(cmd.getDiscriminatorMetaData()), cmd.getDiscriminatorValue());
+ query.put(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DISCRIMINATOR_COLUMN), cmd.getDiscriminatorValue());
}
- if (ec.getStoreManager().getStringProperty(PropertyNames.PROPERTY_TENANT_ID) != null)
+ if (storeMgr.getStringProperty(PropertyNames.PROPERTY_TENANT_ID) != null)
{
// Multitenancy discriminator present : Add restriction for this tenant
if ("true".equalsIgnoreCase(cmd.getValueForExtension("multitenancy-disable")))
@@ -411,19 +298,20 @@
}
else
{
- String fieldName = MongoDBUtils.getFieldNameForMultitenancy(cmd);
- String value = ec.getStoreManager().getStringProperty(PropertyNames.PROPERTY_TENANT_ID);
+ String fieldName = storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.MULTITENANCY_COLUMN);
+ String value = storeMgr.getStringProperty(PropertyNames.PROPERTY_TENANT_ID);
query.put(fieldName, value);
}
}
+ String collectionName = storeMgr.getNamingFactory().getTableName(cmd);
if (NucleusLogger.DATASTORE_RETRIEVE.isDebugEnabled())
{
- NucleusLogger.DATASTORE_RETRIEVE.debug("Fetching instances of collection " + MongoDBUtils.getCollectionName(cmd) +
+ NucleusLogger.DATASTORE_RETRIEVE.debug("Fetching instances of collection " + collectionName +
" fields=" + fieldsSelection + " with filter=" + query);
}
- DBCollection dbColl = db.getCollection(MongoDBUtils.getCollectionName(cmd));
+ DBCollection dbColl = db.getCollection(collectionName);
Object val = (options != null ? options.get("slave-ok") : Boolean.FALSE);
if (val == Boolean.TRUE)
{
@@ -487,6 +375,7 @@
Object id = IdentityUtils.getApplicationIdentityForResultSetRow(ec, cmd, null,
false, new FetchFieldManager(ec, dbObject, cmd));
+ StoreManager storeMgr = ec.getStoreManager();
Class type = ec.getClassLoaderResolver().classForName(cmd.getFullClassName());
Object pc = ec.findObject(id,
new FieldValues()
@@ -520,7 +409,7 @@
else
{
// Get the surrogate version from the datastore
- version = dbObject.get(MongoDBUtils.getFieldName(vermd));
+ version = dbObject.get(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN));
}
sm.setVersion(version);
}
@@ -531,6 +420,7 @@
final ExecutionContext ec, boolean ignoreCache, final int[] fpMembers)
{
Object idKey = null;
+ StoreManager storeMgr = ec.getStoreManager();
if (cmd.getIdentityMetaData().getValueStrategy() == IdentityStrategy.IDENTITY)
{
idKey = dbObject.get("_id");
@@ -541,7 +431,7 @@
}
else
{
- idKey = dbObject.get(MongoDBUtils.getFieldName(cmd.getIdentityMetaData()));
+ idKey = dbObject.get(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.DATASTOREID_COLUMN));
}
OID oid = OIDFactory.getInstance(ec.getNucleusContext(), cmd.getFullClassName(), idKey);
Class type = ec.getClassLoaderResolver().classForName(cmd.getFullClassName());
@@ -578,7 +468,7 @@
else
{
// Get the surrogate version from the datastore
- version = dbObject.get(MongoDBUtils.getFieldName(vermd));
+ version = dbObject.get(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN));
}
sm.setVersion(version);
}
@@ -611,6 +501,7 @@
{
// Set the version on the retrieved object
ObjectProvider sm = ec.findObjectProvider(pc);
+ StoreManager storeMgr = ec.getStoreManager();
Object version = null;
VersionMetaData vermd = cmd.getVersionMetaDataForClass();
if (vermd.getFieldName() != null)
@@ -622,7 +513,7 @@
else
{
// Get the surrogate version from the datastore
- version = dbObject.get(MongoDBUtils.getFieldName(vermd));
+ version = dbObject.get(storeMgr.getNamingFactory().getColumnName(cmd, ColumnType.VERSION_COLUMN));
}
sm.setVersion(version);
}
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/FetchFieldManager.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/FetchFieldManager.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/FetchFieldManager.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -45,6 +45,7 @@
import org.datanucleus.store.fieldmanager.AbstractFieldManager;
import org.datanucleus.store.fieldmanager.FieldManager;
import org.datanucleus.store.mongodb.MongoDBUtils;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.store.types.converters.TypeConverter;
import org.datanucleus.store.types.sco.SCOUtils;
import org.datanucleus.util.NucleusLogger;
@@ -348,7 +349,8 @@
protected String getFieldName(int fieldNumber)
{
- return MongoDBUtils.getFieldName(cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber));
+ return ec.getStoreManager().getNamingFactory().getColumnName(
+ cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber), ColumnType.COLUMN);
}
@Override
@@ -432,7 +434,7 @@
}
}
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
if (!dbObject.containsField(fieldName))
{
return null;
@@ -478,7 +480,7 @@
{
if (mmd.hasCollection())
{
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
if (!dbObject.containsField(fieldName))
{
return null;
@@ -518,7 +520,7 @@
}
else if (mmd.hasArray())
{
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
if (!dbObject.containsField(fieldName))
{
return null;
@@ -543,7 +545,7 @@
}
else
{
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
if (!dbObject.containsField(fieldName))
{
return null;
@@ -618,7 +620,7 @@
}
}
- String fieldName = MongoDBUtils.getFieldName(mmd);
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
if (!dbObject.containsField(fieldName))
{
return null;
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/StoreFieldManager.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/StoreFieldManager.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/fieldmanager/StoreFieldManager.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -43,7 +43,7 @@
import org.datanucleus.store.ObjectProvider;
import org.datanucleus.store.fieldmanager.AbstractFieldManager;
import org.datanucleus.store.fieldmanager.FieldManager;
-import org.datanucleus.store.mongodb.MongoDBUtils;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.store.types.TypeManager;
import org.datanucleus.store.types.converters.TypeConverter;
@@ -205,7 +205,8 @@
protected String getFieldName(int fieldNumber)
{
- return MongoDBUtils.getFieldName(cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber));
+ return op.getExecutionContext().getStoreManager().getNamingFactory().getColumnName(
+ cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber), ColumnType.COLUMN);
}
@Override
@@ -217,8 +218,8 @@
return;
}
- String fieldName = MongoDBUtils.getFieldName(mmd);
ExecutionContext ec = op.getExecutionContext();
+ String fieldName = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
ClassLoaderResolver clr = ec.getClassLoaderResolver();
int relationType = mmd.getRelationType(clr);
@@ -292,7 +293,7 @@
{
if (nested)
{
- dbObject.removeField(MongoDBUtils.getFieldName(mmd));
+ dbObject.removeField(fieldName);
return;
}
else
@@ -326,7 +327,7 @@
{
if (value == null)
{
- dbObject.removeField(MongoDBUtils.getFieldName(mmd));
+ dbObject.removeField(fieldName);
return;
}
Modified: platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/query/QueryToMongoDBMapper.java
===================================================================
--- platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/query/QueryToMongoDBMapper.java 2012-02-17 14:19:34 UTC (rev 14315)
+++ platform/store.mongodb/trunk/src/java/org/datanucleus/store/mongodb/query/QueryToMongoDBMapper.java 2012-02-17 14:21:27 UTC (rev 14316)
@@ -41,6 +41,7 @@
import org.datanucleus.store.mongodb.query.expression.MongoLiteral;
import org.datanucleus.store.mongodb.query.expression.MongoOperator;
import org.datanucleus.store.query.Query;
+import org.datanucleus.store.schema.naming.ColumnType;
import org.datanucleus.util.NucleusLogger;
import org.datanucleus.util.StringUtils;
@@ -556,10 +557,10 @@
}
else
{
- return embeddedNestedField + "." + MongoDBUtils.getFieldName(mmd);
+ return embeddedNestedField + "." + ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
}
}
- return MongoDBUtils.getFieldName(mmd);
+ return ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
}
else if (mmd.isEmbedded())
{
@@ -578,11 +579,11 @@
{
if (embeddedNestedField == null)
{
- embeddedNestedField = MongoDBUtils.getFieldName(mmd);
+ embeddedNestedField = ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN);
}
else
{
- embeddedNestedField += ("." + MongoDBUtils.getFieldName(mmd));
+ embeddedNestedField += ("." + ec.getStoreManager().getNamingFactory().getColumnName(mmd, ColumnType.COLUMN));
}
}
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|