/**
* Returns the property key with the given name. If automatic type making is enabled, it will make the property key
* using the configured default type maker if a key with the given name does not exist.
*
* #param name name of the property key to return
* #return the property key with the given name
* #throws IllegalArgumentException if a property key with the given name does not exist or if the
* type with the given name is not a property key
* #see PropertyKey
*/
public PropertyKey getPropertyKey(String name);
getPropertyKey method will always return a prpertyKey.
To check for if a key exists in the database use:
mgmt.containsRelationType(keyToCheck)
In case of the latest version of Titan (1.0.0) you can use com.thinkaurelius.titan.core.TitanTransaction to check if property key exists in Titan DB schema. http://thinkaurelius.github.io/titan/javadoc/1.0.0/com/thinkaurelius/titan/core/TitanTransaction.html
Example:
TitanTransaction tt = TitanGraph.newTransaction();
boolean exists = tt.containsPropertyKey("keyName");
Related
I am trying to enter unique values to the Contact object. Here is the code:
List<Contact> conList = new List<Contact> {
new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
new Contact()};
// Caroline Roth already exists so I want this code to update her record, not insert another Caroline Roth record
Database.UpsertResult[] srList = Database.upsert(conList, Contact.Fields.Name, false);
Salesforce's documentation states
"The upsert statement matches the sObjects with existing records by comparing values of one field. If you don’t specify a field when calling this statement, the upsert statement uses the sObject’s ID to match the sObject with existing records in Salesforce. Alternatively, you can specify a field to use for matching. For custom objects, specify a custom field marked as external ID. For standard objects, you can specify any field that has the idLookup property set to true. For example, the Email field of Contact or User has the idLookup property set."
I have two questions:
1) how can we see which fields on the Contact object have their idLookup property set to true
2) why am I getting the error in the subject line when I execute the code?
1:
Map<String, Schema.SObjectField> contacFieldsMap = Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap();
for (Schema.SObjectField field : contacFieldsMap.values()) {
Schema.DescribeFieldResult fieldResult = field.getDescribe();
if (fieldResult.isIdLookup()) System.debug(fieldResult.getName() + ' IS idLookup');
}
2: System.debug(Contact.Name.getDescribe().isIdLookup()); // false
I want to find out what key name provided from an external provider my database is using in an encrypted database.
This is an example taken from Microsoft website.
CREATE ASYMMETRIC KEY EKM_askey1
FROM PROVIDER EKM_Provider1
WITH
ALGORITHM = RSA_2048,
CREATION_DISPOSITION = CREATE_NEW
, PROVIDER_KEY_NAME = 'key10_user1' ;
GO
But I don't know how to learn whether this is CREATE_NEW or OPEN_EXISTING and have no clue what view contains information about this key10_user1 as mentioned in the example.
Could you try:
SELECT * FROM sys.cryptographic_providers;
to get the provider id and then query using sys.dm_cryptographic_provider_keys:
SELECT * FROM sys.dm_cryptographic_provider_keys(1234567);
GO
I tried cascade remove on the 'file' entity that keeps my 'expanse' entity from removing. But this doesn't work.
The error:
Cannot delete or update a parent row: a foreign key constraint fails (zioo.files, CONSTRAINT FK_6354059F395DB7B FOREIGN KEY (expense_id) REFERENCES expenses (id))
The file entity code:
/**
* #ORM\ManyToOne(targetEntity="Expense", inversedBy="files", cascade={"remove"})
* #ORM\JoinColumn(name="expense_id", referencedColumnName="id")
*/
private $expense;
The expanse entity code:
/**
* #ORM\OneToOne(targetEntity="File", cascade={"persist"})
* #ORM\JoinColumn(name="file_id", referencedColumnName="id")
*/
private $file = null;
/**
* #ORM\OneToMany(targetEntity="File", mappedBy="expense", cascade={"remove"})
*/
protected $files;
If a expanse gets deleted the file associated with it should be deleted too.
Using cascade={"remove"} the entity won't be deleted if it is owned by something else. The issue seems to be caused by doctrine, as the expanse entity has 2 relations to file entity and this causes doctrine to "think" that your file entity is owned by something else and not send a delete to database for it, before trying to delete the expanse.
As a result when it tries to delete the expanse this error is thrown.
To test it, remove private $file = null;relation and will see that it will work.
To overcome this, I suggest to use onDelete="CASCADE" on the owning side:
/**
* #ORM\ManyToOne(targetEntity="Expense", inversedBy="files", cascade={"remove"})
* #ORM\JoinColumn(name="expense_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $expense;
In this case, you no longer need cascade={"remove"}:
/**
* #ORM\OneToMany(targetEntity="File", mappedBy="expense")
*/
protected $files;
Doctrine delete relation options
I am trying to save a new object to the database using petapoco.
I have an object that uses a Guid for the primary key.
Here is an example of the objects primary key property.
<PetaPoco.Column()> _
Public ReadOnly Property Primkey() As Guid Implements IStandardDocument.Primkey
Get
Return (_primkey)
End Get
End Property
Here is an example of the save method.
database.Save("Reservations", "Primkey", reservation)
The sql that is generated is an update with a primkey of 00000000-0000-0000-0000-000000000000 instead of an insert. So new records are never inserted.
If I have an existing object with a valid guid the update and delete all work correctly.
What am I doing wrong for the save case?
Most likely it's too late to answer this for the original poster, but for others out there...
My understanding is the Save doesn't work for Guid columns. The way petaPoco knows if it's an insert vs update is if the key value is different from default. In case if numeric it would be 0, in the case of Guid it would be '00000000-0000-0000-0000-000000000000'.
Here's an extract of IsNew method
// Common primary key types
if (type == typeof(long))
return (long)pk == 0;
else if (type == typeof(ulong))
return (ulong)pk == 0;
else if (type == typeof(int))
return (int)pk == 0;
else if (type == typeof(uint))
return (uint)pk == 0;
// Create a default instance and compare
return pk == Activator.CreateInstance(pk.GetType());
In the case of Guid the last statement would always return false, even if your primary key is all zeros. There should really be another else if as such:
else if (type == typeof(Guid))
return Guid.Equals(pk, Activator.CreateInstance(pk.GetType()));
However, I didn't check if this is the only thing that has to be changed for the GUID key to work. After inserting the record, PetaPoco tries to check the key value of the newly inserted record and it might fail on that too.
I was able to make this work by removing the type from the primkey property.
Setting the primkey to null will now return null rather than an empty guid.
PetaPoco now sees the primarykey field is a null and generate the correct insert statement rather than generating an update statement for primkey 00000000-0000-0000-0000-000000000000.
I've never worked with petapoco but a few things I would try first are:-
Primkey column's Data Type in sql is 'Uniqueidentifier'
Primkey column's Default Value is (newid())
Change the PrimKey to a Get/Set value and do 'Primkey = Guid.NewGuid' before saving.
EDIT: I just thought, when you declare a New Reservation does it allow you to pass an ID ect on the constructor?
The test class is as follows:
I am trying to set the RecordType.Name in the test class but it gives me the message "System.NullPointerException: Attempt to de-reference a null object
class.TestAcctHierWarnDisplay.tstWarningDisplay1: line 45, column 3 External entry point". The record types exist.
I am not sure what I am missing.
Gets the exception at
myacct.RecordType.Name = 'Master Account';
You should set the record type by ID, not by name:
id idRT = [select Id from RecordType where SobjectType = 'Account' and DeveloperName = 'RTDevName].Id;
Account sAcct = new Account();
sAcct.RecordTypeId = idRT;
Also, note that I'm using developer name, this is the equivalent of the API name on object fields, the idea being that the actual name is a label and could be changed for frontend purposes.
FYI:
The reason you're getting an exception is because the account is not assigned a record type at this stage, so myacct.RecordType is null, which you're trying to dereference when accessing the Name field on it.