检查Appcelerator区域设置数据库是否存在(Check if Appcelerator locale database exists)
我需要知道应用程序中是否存在区域应用程序加速器/钛数据库,以便能够将数据从该数据库迁移到ArrowDB。
有没有办法找出数据库的名称是否存在?
我试着回答这个问题,但没有成功。 https://archive.appcelerator.com/question/143890/check-if-local-database-already-exists
// SDK 5.5.0 GA。 iOS和Android
I need to know if a locale appcelerator/titanium database exist in an app to be able to migrate data from that DB to ArrowDB.
Is there any way of finding out if a DB exist by its name?
I tried following this answer but didn't succeed. https://archive.appcelerator.com/question/143890/check-if-local-database-already-exists
// SDK 5.5.0 GA. iOS & Android
原文:https://stackoverflow.com/questions/39747084
最满意答案
你确实使用单身。 简单来说,有两种常见的单例实现,另一种是实例化类,并有一个静态成员引用这个实例。
您的实施使呼叫更简单IMO:
PageAccessChecker.CheckIfRoleAllowed(path);
代替:
PageAccessChecker._default.CheckIfRoleAllowed(path);
You do use a singleton. Simply, there are 2 usual implementations for singletons, the other being instantiating the class and having a static member referencing this instance.
Your implementation makes calls simpler IMO :
PageAccessChecker.CheckIfRoleAllowed(path);
instead of:
PageAccessChecker._default.CheckIfRoleAllowed(path);
相关问答
更多-
选择单身优于静态类的一个很好的理由(假设你没有更好的模式可供使用)),就是将一个单例实例与另一个实例交换。 例如,如果我有这样的日志类: public static class Logger { public static void Log(string s) { ... } } public class Client { public void DoSomething() { Logger.Log("DoSomething called"); } } 它工作得很 ...
-
与Singleton类崩溃(Crash with Singleton Class)[2022-04-08]
NullPointerException引用您的Boolean而不是单例实例。 您将boolean的初始值设置为null,那么可能发生的是您的GameData被创建,但布尔值尚未设置。 使用默认值更改为基本类型布尔值应该可以解决此问题。 可能导致这种情况的一种可能的情况是例如方向改变。 这将删除无效的GameData对象,强制它被重新创建(当调用getInstance() )。 但布尔可能不会在下次访问它时设置。 The NullPointerException is referring to your B ... -
简短的回答: 没有 。 单身人士解决资源争用问题。 对于SQL连接没有争用,您可以根据需要创建任意数量的连接。 关于使用单身人士的更多细节在这里:单身人士有什么不好? 正如其他人所说,使用连接池更好。 连接池也会获得更好的性能。 关于连接池的好处: 为什么我们需要连接池用于JDBC? Short answer: No. Singletons solve Resource Contention problem. For SQL connection there is no contention, you ca ...
-
这不是真的是一种情况。 单身人士是具有静态获取者的实例,以及一个私有构造函数。 它们不是静态类。 带有某些限制条件的单身人士是确保你只有一个班级实例的一种方法。 所以第一个问题是。 你是否需要一个实例,即这个事物是否有状态,第二个问题是他们进行单元测试有多困难,你是否想要一个实例。 例如,查看Service Locator模式。 This is not really an either or scenario. Singletons are instances with a static getter, a ...
-
链接静态单例类(Linking static singleton class)[2022-08-22]
您需要从cpp文件中的定义中移除static :编译器已经知道Singleton::Instance和Singleton::Destroy从它们的声明中是static的。 其他一切都看起来不错 You need to remove static from the definitions in the cpp file: the compiler already knows the Singleton::Instance and Singleton::Destroy are static from their ... -
显然,第一种方法更简单,更短 - 无论是阅读还是性能和记忆方面。 在第二个代码中,两个额外的构造将导致一点开销。 Clearly the first approach is simpler and shorter - both for reading and definitely in performance and memory aspects. In the second code, the two extra constructs will cause a little overhead.
-
Singleton vs Static Class用于暴露从xml读取的数据(Singleton vs Static Class for exposing data read from xml)[2023-08-30]
你确实使用单身。 简单来说,有两种常见的单例实现,另一种是实例化类,并有一个静态成员引用这个实例。 您的实施使呼叫更简单IMO: PageAccessChecker.CheckIfRoleAllowed(path); 代替: PageAccessChecker._default.CheckIfRoleAllowed(path); You do use a singleton. Simply, there are 2 usual implementations for singletons, the ot ... -
Singleton Class iPhone(Singleton Class iPhone)[2022-12-08]
你需要首先分配和初始化数组。 就个人而言,我会在内容类的init方法中这样做: -(id)init{ if(self = [super init]){ …the rest of your init code… contentArray = [[NSMutableArray alloc] init]; } return self; } You need to alloc and init the array first. Personally I' ... -
带有静态数据的iOS单例(iOS singleton with static data)[2021-10-12]
Yoy说“单身类”,我认为你的意思是这个类只有类方法。 没关系,你仍然可以使用它,因为类对象仍然是对象。 也就是说,你可能需要保持状态。 每个委托调用都将包含一些允许对象识别发件人的参数。 我自己可能会做的是在“initialize”方法中创建一个NSMutableDictionary,然后在发送委托方法之前让对象注册自己,当他们注册时创建另一个mutableDictionary,并在第一个以发送对象作为键保存它(或其他一些独特的标识符)。 每个委托调用都必须包含发件人,然后您可以检索与该对象关联的字典。 ... -
拥有静态属性并没有错,但在单例中它是多余的。 此外,如果您有静态属性,稍后您需要将类更改为不再是单例,您还需要更改属性(作为访问它的每个代码)。 所以除非真的需要,否则我建议你不要标记为静态。 It's not wrong to have static properties, but it's redundant in a singleton. Also, if you have static properties, and later you need to change the class to not ...