How to show all settings in database? - aspnetboilerplate

I found that the table dbo.AbpSettings in the database only stored changed settings (the new value is different from default value). So how to make it insert all settings to the database?

You can implement a custom ISettingManager - in particular, skip this check:
if (value == defaultValue)
{
// ...
return null;
}
And replace the service in your module's PreInitialize() method:
Configuration.ReplaceService<ISettingManager, MySettingManager>();

Related

How to retrieve data by property in Couchbase Lite?

My documents have the property docType that separated them based on the purpose of each type, in the specific case template or audit. However, when I do the following:
document.getProperty("docType").equals("template");
document.getProperty("docType").equals("audit");
The results of them are always the same, it returns every time all documents stored without filtering them by the docType.
Below, you can check the query function.
public static Query getData(Database database, final String type) {
View view = database.getView("data");
if (view.getMap() == null) {
view.setMap(new Mapper() {
#Override
public void map(Map<String, Object> document, Emitter emitter) {
if(String.valueOf(document.get("docType")).equals(type)){
emitter.emit(document.get("_id"), null);
}
}
}, "4");
}
return view.createQuery();
}
Any hint?
This is not a valid way to do it. Your view function must be pure (it cannot reference external state such as "type"). Once that is created you can then query it for what you want by setting start and end keys, or just a set of keys in general to filter on.

Cast between Oracle Table field and Entity framework fails

Within a WCF web service I make a query on a ORACLE 11g database and I use entity framework as model. The target field is of type Numeric, while in the entity framework is Int64.
When I try to update the field I get the following exception: The specified cast from a materialized 'System.Decimal' type to the 'System.Int64' type is not valid.
The method generating the error is below, in particular for the line within the else statement: result = _context.ExecuteStoreQuery(query).FirstOrDefault();
public string GetDatabaseTimestamp(Type timestampFieldType, string query)
{
object result;
if (timestampFieldType == typeof(string))
{
result = _context.ExecuteStoreQuery<string>(query).FirstOrDefault();
}
else
{
result = _context.ExecuteStoreQuery<long>(query).FirstOrDefault();
}
return result.ToString();
}
Would it be possible to define at the EF level a converter or something similar? The option of changing the Database is not feasible, therefore I have to edit code.
In The EF I already changed the type into decimal. Problem is that the query was executed directly on the Oracle database and this was generating the exception.
I solved the issue by using attributes for the target entity and changed the method into:
public string GetDatabaseTimestamp(Type timestampFieldType, string query)
{
object result;
if (timestampFieldType == typeof(string))
{
result = _context.ExecuteStoreQuery<string>(query).FirstOrDefault();
}
else if (timestampFieldType == typeof(decimal))
{
result = _context.ExecuteStoreQuery<decimal>(query).FirstOrDefault();
}
else
{
result = _context.ExecuteStoreQuery<long>(query).FirstOrDefault();
}
return result.ToString();
}
In this way the passed timestampFieldType is of type decimal and the proper cast is selected. This issue is due to different data types used for similar fields (as example Update fields) in the Oracle DB (legacy database).

Guid values in Oracle with fluentnhibernate

I've only been using fluent nhibernate a few days and its been going fine until trying to deal with guid values and Oracle. I have read a good few posts on the subject but none that help me solve the problem I am seeing.
I am using Oracle 10g express edition.
I have a simple test table in oracle
CREATE TABLE test (Field RAW(16));
I have a simple class and interface for mapping to the table
public class Test : ITest
{
public virtual Guid Field { get; set; }
}
public interface ITest
{
Guid Field { get; set; }
}
Class map is simple
public class TestMap : ClassMap<Test>
{
public TestMap()
{
Id(x => x.Field);
}
}
I start trying to insert a simple easily recognised guid value
00112233445566778899AABBCCDDEEFF
Heres the code
var test = new Test {Field = new Guid("00112233445566778899AABBCCDDEEFF")};
// test.Field == 00112233445566778899AABBCCDDEEFF here.
session.Save(test);
// after save guid is changed, test.Field == 09a3f4eefebc4cdb8c239f5300edfd82
// this value is different for each run so I pressume nhibernate is assigning
// a value internally.
transaction.Commit();
IQuery query = session.CreateQuery("from Test");
// or
// IQuery query = session.CreateSQLQuery("select * from Test").AddEntity(typeof(Test));
var t in query.List<Test>().Single();
// t.Field == 8ef8a3b10e704e4dae5d9f5300e77098
// this value never changes between runs.
The value actually stored in the database differs each time also, for the run above it was
EEF4A309BCFEDB4C8C239F5300EDFD82
Truly confused....
Any help much appreciated.
EDIT: I always delete data from the table before each test run. Also using ADO directly works no problem.
EDIT: OK, my first problem was that even though I thought I was dropping the data from the table via SQL command line for oracle when I viewed the table via oracle UI it still had data and the first guid was as I should have expected 8ef8a3b10e704e4dae5d9f5300e77098.
Fnhibernate still appears to be altering the guid value on save. it alters it to the value it stores in the database but I'm still not sure why it is doing this or how\if I can control it.
If you intend on assigning the id yourself you will need to use a different id generator than the default which is Guid.comb. You should be using assigned instead. So your mapping would look something like this:
Id(x => x.Field).GeneratedBy.Assigned();
You can read more about id generators in the nhibernate documentation here:
http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-id-generator

#UniqueConstraints failing on update

I have an Entity class in which I put uniqueconstraint annotation
#Table(uniqueConstraints={#UniqueConstraint(columnNames={"staffRecord_id", "defaultLabel_id","company_id","keyCode"})})
public class AllowanceDeduction implements Serializable{
---
What I have noticed that is when I try to save on the table
using
if (allowanceDeduction.getId() == null) {
this.entityManager.persist(allowanceDeduction);
} else {
this.entityManager.merge(allowanceDeduction);
}
when the save or update fails due to a unique constraint. Isn't it only supposed to fail when trying to save a new record that is identical to a record that already exist.
Why would it fail when trying to merge or update?
Please help needed
I can't say for sure but it looks like you're trying to persist a null id
if (allowanceDeduction.getId() == null) {
this.entityManager.persist(allowanceDeduction);
/* don't you need the id set to a non-null value in order to persist it? */
} else {

How to set the oracle.jdbc.V8Compatible property

I am using Oracle 10g with a Grails 1.3.2 application. I am targeting a legacy schema with all Date columns types used where time is stored. I believe I need to set the oracle.jdbc.V8Compatible property to true somewhere in order to use Groovy's Sql.rows instance method (which uses ResultSet.getObject under the hood) to get java.sql.Timestamp objects with time components preserved instead java.sql.Date objects with time component truncated (see this). Where is the right / best place to set / how do I set the oracle.jdbc.V8Compatible property in a Grails application?
we use DataSource.groovy for development, and a JBoss JNDI configuration for production.
For the development environment I suggest to specify it in DataSource.groovy:
dataSource {
// common settings
}
environments {
development {
dataSource {
properties = "oracle.jdbc.V8Compatible=true"
}
}
}
For production you have to put this in the connection-property field for the datasource.
I abandoned the Sql.rows / V8Compatibility approach and instead am just using a custom function:
public static java.sql.Timestamp sqlScalarTimestamp(dataSource, query, params) {
Sql sql;
try {
sql = new Sql(dataSource)
def result = null
sql.query(query, params) { rs ->
if(rs.next())
result = rs.getTimestamp(1)
}
return result
} finally {
if(sql != null)
sql.close()
}
}

Resources