public static boolean isParentPKField(AbstractMemberMetaData ammd) { return ammd.hasExtension(DatastoreManager.PARENT_PK); }
public static boolean isEncodedPKField(AbstractMemberMetaData ammd) { return ammd.hasExtension(DatastoreManager.ENCODED_PK); }
public static boolean isPKNameField(AbstractMemberMetaData ammd) { return ammd.hasExtension(DatastoreManager.PK_NAME); }
public static boolean isPKIdField(AbstractMemberMetaData ammd) { return ammd.hasExtension(DatastoreManager.PK_ID); }
@Override public Boolean getUseDefaultConversion() { if (getInternal().hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED)) { String val = getInternal().getValueForExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_DISABLED); return Boolean.valueOf(val); } else if (getInternal().hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)) { return false; } return true; }
@Override public boolean useBackedSCOWrapperForMember(AbstractMemberMetaData mmd, ExecutionContext ec) { if ((mmd.hasCollection() || mmd.hasMap()) && mmd.hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)) { // The only case where we don't use backed wrappers is for a Collection/Map that is using a converter for the whole field (so storing as a single column) return false; } return true; }
if (ammd.hasExtension("namespace")) if (ammd.hasExtension("name")) if (ammd.hasExtension("required"))
public static boolean isRelationByAttribute(AbstractMemberMetaData mmd, MetaDataManager mmgr) { if (mmd.hasExtension(LDAPStoreManager.MAPPING_STRATEGY_EXTENSON)) { // User has specified the mapping-strategy explicitly via extension String mappingStrategy = mmd.getValueForExtension(LDAPStoreManager.MAPPING_STRATEGY_EXTENSON); if (mappingStrategy != null) { if (mappingStrategy.equalsIgnoreCase("attribute")) { return true; } else if (mappingStrategy.equalsIgnoreCase("dn")) { return false; } } } // Fallback to the check based on "join" return new RelationByAttributeMetaData(mmd, mmgr).joinMetaData != null; } }
private static Object intOrLongToInternalKey( String kind, Class<?> pkType, AbstractMemberMetaData pkMemberMetaData, Class<?> cls, Object val) { Object result = null; Key keyWithId = KeyFactory.createKey(kind, ((Number) val).longValue()); if (pkType.equals(String.class)) { if (pkMemberMetaData.hasExtension(DatastoreManager.ENCODED_PK)) { result = KeyFactory.keyToString(keyWithId); } else { throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is an unencoded String. However, the provided value is of type " + val.getClass().getName() + "."); } } else if (pkType.equals(Long.class) || pkType.equals(long.class)) { result = keyWithId.getId(); } else if (pkType.equals(Key.class)) { result = keyWithId; } return result; }
if (ammd.hasExtension("namespace")) if (ammd.hasExtension("nillable")) if (ammd.hasExtension("required"))
/** * Initialize this JavaTypeMapping for the specified field/property. * @param mmd AbstractMemberMetaData for the field to be mapped (if any) * @param table The datastore container storing this mapping (if any) * @param clr the ClassLoaderResolver */ public void initialize(AbstractMemberMetaData mmd, Table table, ClassLoaderResolver clr) { if (mmd.hasExtension("mapping-strategy")) { String strategy = mmd.getValueForExtension("mapping-strategy"); if (strategy.equalsIgnoreCase("identity")) { mappingStrategy = ID_MAPPING; } else if (strategy.equalsIgnoreCase("xcalia")) { mappingStrategy = XCALIA_MAPPING; } } numberOfDatastoreMappings = 0; // Reset indicator for datastore fields super.initialize(mmd, table, clr); prepareDatastoreMapping(clr); }
if (ammd.hasExtension("namespace")) if (ammd.hasExtension("type"))
private void verifyOneToManyOrderBy(AbstractMemberMetaData ammd, AbstractClassMetaData childAcmd) { OrderMetaData omd = ammd.getOrderMetaData(); OrderMetaData.FieldOrder[] fieldOrders = omd.getFieldOrders(); if (fieldOrders == null) { return; } for (OrderMetaData.FieldOrder fieldOrder : omd.getFieldOrders()) { String propertyName = fieldOrder.getFieldName(); AbstractMemberMetaData orderField = childAcmd.getMetaDataForMember(propertyName); if (orderField.hasExtension(DatastoreManager.PK_ID) || orderField.hasExtension(DatastoreManager.PK_NAME)) { throw new InvalidMetaDataException(GAE_LOCALISER, "AppEngine.MetaData.OrderPartOfPK", ammd.getFullFieldName(), propertyName); } } }
if (mmd.hasExtension(EXTENSION_CHECK_CONSTRAINT) && mmd.getValueForExtension(EXTENSION_CHECK_CONSTRAINT).equals("true"))
/** * Convenience method for whether a PK is required for the join table. * Makes use of the extension "primary-key" (within <field> or <join>) to allow turning off PK generation. * @return Whether a PK is required */ protected boolean requiresPrimaryKey() { boolean pkRequired = true; if (mmd.hasExtension("primary-key") && mmd.getValueForExtension("primary-key").equals("false")) { // User has explicitly defined the field owning this join table to have no primary-key return false; } if (mmd.getJoinMetaData() != null && mmd.getJoinMetaData().hasExtension("primary-key") && mmd.getJoinMetaData().getValueForExtension("primary-key").equalsIgnoreCase("false")) { // User has explicitly define the join table to have no primary-key pkRequired = false; } return pkRequired; }
/** * Accessor for the (LDAP) attribute name for the specified field. Uses the extension "dn" if specified * (deprecated), else the extension "attribute" if specified, else the "column" if specified, else uses the field * name. * @param mmd MetaData for the field * @return The attribute */ public static String getAttributeNameForField(AbstractMemberMetaData mmd) { String name = mmd.getName(); if (mmd.hasExtension("dn")) { name = mmd.getValueForExtension("dn"); } else if (mmd.hasExtension("attribute")) { name = mmd.getValueForExtension("attribute"); } else if (mmd.getColumnMetaData() != null && mmd.getColumnMetaData().length > 0) { name = mmd.getColumnMetaData()[0].getName(); } return name; }
protected void addColumns() { boolean singleColumn = true; if (mmd != null) { ColumnMetaData[] colmds = mmd.getColumnMetaData(); if (colmds != null && colmds.length == 2) { // 2 columns specified so use that handling singleColumn = false; } else if (mmd.hasExtension(MetaData.EXTENSION_MEMBER_CALENDAR_ONE_COLUMN) && mmd.getValueForExtension(MetaData.EXTENSION_MEMBER_CALENDAR_ONE_COLUMN).equals("false")) { singleColumn = false; } } if (singleColumn) { // (Timestamp) implementation addColumns(ClassNameConstants.JAVA_SQL_TIMESTAMP); } else { // (Timestamp millisecs, Timezone) implementation addColumns(ClassNameConstants.LONG); // Timestamp millisecs addColumns(ClassNameConstants.JAVA_LANG_STRING); // Timezone } }
/** * Method to return the type of the XML element to use for the specified field/property. * Null implies no value defined * @param mmd Metadata for the field/property * @param clr ClassLoader resolver * @return The type */ public static Class getElementTypeForMember(AbstractMemberMetaData mmd, ClassLoaderResolver clr) { try { if (mmd.hasExtension("type")) { return clr.classForName(mmd.getValueForExtension("type")); } else if (mmd.hasCollection()) { // Collection but no "type" known so impose element type return clr.classForName(mmd.getCollection().getElementType()); } } catch (ClassNotResolvedException e) { throw new RuntimeException(e.getMessage()); } return null; }
public static boolean isRelationByDn(AbstractMemberMetaData mmd, MetaDataManager mmgr) if (mmd.hasExtension(LDAPStoreManager.MAPPING_STRATEGY_EXTENSON))
private String determinePropertyName(AbstractMemberMetaData ammd) { if (ammd.hasExtension(DatastoreManager.PK_ID) || ammd.hasExtension(DatastoreManager.PK_NAME)) { // the datsatore doesn't support filtering or sorting by the individual // components of the key, so if the field corresponds to one of these // components it's a mistake by the user throw new org.datanucleus.exceptions.NucleusFatalUserException(query.getSingleStringQuery() + ": Field " + ammd.getFullFieldName() + " is a sub-component of the primary key. The " + "datastore does not support filtering or sorting by primary key components, only the " + "entire primary key."); } if (ammd.getColumn() != null) { return ammd.getColumn(); } else if (ammd.getColumnMetaData() != null && ammd.getColumnMetaData().length != 0) { return ammd.getColumnMetaData()[0].getName(); } else if (ammd.getElementMetaData() != null && ammd.getElementMetaData().getColumnMetaData() != null && ammd.getElementMetaData().getColumnMetaData().length != 0) { return ammd.getElementMetaData().getColumnMetaData()[0].getName(); } else { return getIdentifierFactory().newDatastoreFieldIdentifier(ammd.getName()).getIdentifierName(); } }