关于xmpp用户属性扩展JDBCUserPropertyProvider的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android属性之build.prop,及property_get
关于xmpp 用户属性扩展 JDBCUserPropertyProvider的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android 属性之 build.prop,及 property_get/property_set、App Engine中的db.ReferenceProperty()与ndb.KeyProperty、Big impact when set property type in-properly、com.intellij.uiDesigner.propertyInspector.properties.BorderProperty的实例源码等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- xmpp 用户属性扩展 JDBCUserPropertyProvider
- Android 属性之 build.prop,及 property_get/property_set
- App Engine中的db.ReferenceProperty()与ndb.KeyProperty
- Big impact when set property type in-properly
- com.intellij.uiDesigner.propertyInspector.properties.BorderProperty的实例源码
xmpp 用户属性扩展 JDBCUserPropertyProvider
/*
* Copyright 2017 IgniteRealtime.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.user.property;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
/**
* The JDBC user property provider allows you to use an external database to define the user properties. It is best used
* with the JDBCUserProvider, JDBCAuthProvider & JDBCGroupProvider to provide integration between your external
* system and Openfire. All data is treated as read-only so any set operations will result in an exception.
*
* This implementation will not explicitly verify if a user exists, when operating on its properties. The methods of
* this implementation will <em>not</em> throw {@link org.jivesoftware.openfire.user.UserNotFoundException}.
*
* To enable this provider, set the following in the system properties:
*
* <ul>
* <li>{@code provider.userproperty.className = org.jivesoftware.openfire.user.property.JDBCUserPropertyProvider}</li>
* </ul>
*
* Then you need to set your driver, connection string and SQL statements:
*
* <ul>
* <li>{@code jdbcUserPropertyProvider.driver = com.mysql.jdbc.Driver}</li>
* <li>{@code jdbcUserPropertyProvider.connectionString = jdbc:mysql://localhost/dbname?user=username&password=secret}</li>
* <li>{@code jdbcUserPropertyProvider.loadPropertySQL = SELECT propName, propValue FROM myUser WHERE user = ? AND propName = ?}</li>
* <li>{@code jdbcUserPropertyProvider.loadPropertiesSQL = SELECT propValue FROM myUser WHERE user = ?}</li>
* </ul>
*
* In order to use the configured JDBC connection provider do not use a JDBCconnection string, set the following
* property:
*
* {@code jdbcUserPropertyProvider.useConnectionProvider = true}
*
* @author Guus der Kinderen, guus.der.kinderen@gmail.com
*/
public class JDBCUserPropertyProvider implements UserPropertyProvider
{
private static final Logger Log = LoggerFactory.getLogger( JDBCUserPropertyProvider.class );
private String loadPropertySQL;
private String loadPropertiesSQL;
private String connectionString;
private boolean useConnectionProvider;
/**
* Constructs a new JDBC user property provider.
*/
public JDBCUserPropertyProvider()
{
// Convert XML based provider setup to Database based
JiveGlobals.migrateProperty( "jdbcUserPropertyProvider.driver" );
JiveGlobals.migrateProperty( "jdbcUserPropertyProvider.connectionString" );
JiveGlobals.migrateProperty( "jdbcUserPropertyProvider.loadPropertySQL" );
JiveGlobals.migrateProperty( "jdbcUserPropertyProvider.loadPropertiesSQL" );
useConnectionProvider = JiveGlobals.getBooleanProperty( "jdbcUserProvider.useConnectionProvider" );
// Load the JDBC driver and connection string.
if ( !useConnectionProvider )
{
String jdbcDriver = JiveGlobals.getProperty( "jdbcUserPropertyProvider.driver" );
try
{
Class.forName( jdbcDriver ).newInstance();
}
catch ( Exception e )
{
Log.error( "Unable to load JDBC driver: " + jdbcDriver, e );
return;
}
connectionString = JiveGlobals.getProperty( "jdbcProvider.connectionString" );
}
// Load database statements for user data.
loadPropertySQL = JiveGlobals.getProperty( "jdbcUserPropertyProvider.loadPropertySQL" );
loadPropertiesSQL = JiveGlobals.getProperty( "jdbcUserPropertyProvider.loadPropertiesSQL" );
}
private Connection getConnection() throws SQLException
{
if ( useConnectionProvider )
{
return DbConnectionManager.getConnection();
}
else
{
return DriverManager.getConnection( connectionString );
}
}
@Override
public Map<String, String> loadProperties( String username ) throws UnsupportedOperationException
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
con = getConnection();
pstmt = con.prepareStatement( loadPropertiesSQL );
pstmt.setString( 1, username );
rs = pstmt.executeQuery();
final Map<String, String> result = new HashMap<>();
while ( rs.next() )
{
final String propName = rs.getString( 1 );
final String propValue = rs.getString( 2 );
result.put( propName, propValue );
}
return result;
}
catch ( Exception e )
{
throw new UnsupportedOperationException( e );
}
finally
{
DbConnectionManager.closeConnection( rs, pstmt, con );
}
}
@Override
public String loadProperty( String username, String propName )
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
con = getConnection();
pstmt = con.prepareStatement( loadPropertySQL );
pstmt.setString( 1, username );
pstmt.setString( 2, propName );
rs = pstmt.executeQuery();
final Map<String, String> result = new HashMap<>();
if ( rs.next() )
{
return rs.getString( 1 );
}
return null;
}
catch ( Exception e )
{
throw new UnsupportedOperationException( e );
}
finally
{
DbConnectionManager.closeConnection( rs, pstmt, con );
}
}
@Override
public void insertProperty( String username, String propName, String propValue ) throws UnsupportedOperationException
{
throw new UnsupportedOperationException();
}
@Override
public void updateProperty( String username, String propName, String propValue ) throws UnsupportedOperationException
{
throw new UnsupportedOperationException();
}
@Override
public void deleteProperty( String username, String propName ) throws UnsupportedOperationException
{
throw new UnsupportedOperationException();
}
@Override
public boolean isReadOnly()
{
return true;
}
}
Android 属性之 build.prop,及 property_get/property_set
简要分析一下 build.prop 是如何生成的。Android 的 build.prop 文件是在 Android 编译时收集的各种 property(LCD density / 语言 / 编译时间,etc.),编译完成之后,文件生成在 out/target/product/<board>/system/ 目录下。在 Android 运行时可以通过 property_get ()[c/c++ 域] / SystemProperties_get*()[Java 域] 读取这些属性值。
(1)build.prop 的生成是由 make 系统解析 build/core/Makefile 完成。Makefile 中首先定义各种变量,这在下一步执行时会用到。比如:
[cpp] view plaincopy- ...
- PRODUCT_DEFAULT_LANGUAGE="$(calldefault-locale-language,$(PRODUCT_LOCALES))" \
- PRODUCT_DEFAULT_REGION="$(calldefault-locale-region,$(PRODUCT_LOCALES))" \
- ...
(2)Makefile 中调用 build/tools/buildinfo.sh 执行脚本,并输出到 build.prop。Buildinfo.sh 很简单,只是 echo 一些属性,比如:
[cpp] view plaincopy- ...
- echo"ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
- echo"ro.product.locale.region=$PRODUCT_DEFAULT_REGION"
- ...
ro.product.locale.language/ro.product.locale.region 就是些属性,等号后面是值。
(3)Makefile 中直接把 $(TARGET_DEVICE_DIR)/system.prop 的内容追加到 build.prop 中,还会收集 ADDITIONAL_BUILD_PROPERTIES 中的属性,追加到 build.prop 中。
ADDITIONAL_BUILD_PROPERTIES 又会收集 PRODUCT_PROPERTY_OVERRIDES 中定义的属性,如下:
[cpp] view plaincopy- ADDITIONAL_BUILD_PROPERTIES:= \
- $(ADDITIONAL_BUILD_PROPERTIES)\
- $(PRODUCT_PROPERTY_OVERRIDES)
通过 build.prop 生成过程的分析,可知哪里可以修改原有的属性或加入自己定义属性,那就是 2) buildinfo.sh; 3) system.prop; 4) ADDITIONAL_BUILD_PROPERTIES 或 PRODUCT_PROPERTY_OVERRIDES。
(4)属性(property)都有一个名称和值,他们都是字符串格式,用来记录系统设置或进程之间的信息交换。属性是在整个系统中全局可见的。
在系统初始化时,Android 将分配一个共享内存区来存储的属性。这些是由 “init” 守护进程完成的,“init” 守护进程将启动一个属性服务。任何客户端想获得属性信息,可以从共享内存直接读取。客户端应用程序可以调用 libcutils 中的 API 函数以 GET/SET 属性信息:
int property_get(const char *key, char *value, const char *default_value);
int property_set(const char *key, const char *value);
当启动属性服务时,将从以下文件中加载默认属性:
/default.prop
/system/build.prop
/system/default.prop
/data/local.prop
属性将会以上述顺序加载,后加载的属性将覆盖原先的值。特别属性如果属性名称以 “ro.” 开头,那么这个属性被视为只读属性,比如 ro.mediatek.version.release=ALPS.ICS2.MP.V1 就是指示版本号,应用中用 property_get ("ro.mediatek.version.release", val, "unknown"); 即可用来获得版本信息;属性 “ ctrl.start ” 和 “ ctrl.stop ” 是用来启动和停止服务。每一项服务必须在 /init.rc 中定义,系统启动时 init 守护进程将解析 init.rc 和启动属性服务。一旦收到设置 “ ctrl.start ” 属性的请求,属性服务将使用该属性值作为服务名找到该服务,启动该服务。客户端应用程序可以轮询那个属性值,以确定结果。
App Engine中的db.ReferenceProperty()与ndb.KeyProperty
ReferenceProperty在处理两个模块之间的引用时非常有帮助。福克斯的例子:
class UserProf(db.Model): name = db.StringProperty(required=True)class Team(db.Model): manager_name = db.ReferenceProperty(UserProf, collection_name=''teams'') name = db.StringProperty(required=True)
- 要使用团队实例获取“ manager_name”,我们使用team_ins.manager_name。
- 为了获得由特定用户实例管理的“团队”,我们使用user_instance.teams并进行迭代。
看起来不容易理解吗?
使用NDB做同样的事情时,我们必须修改
db.ReferenceProperty(UserProf, collection_name=''teams'')
->ndb.KeyProperty(kind=UserProf)
team_ins.manager_name.get()
会给你经理的名字- 要获得所有由特定用户管理的团队,我们必须
for team in Team.query(Team.manager_name == user_ins.key): print "team name:", team.name
如您所见,在db中处理这种情况比在ndb中看起来更容易理解。
- 在ndb中删除ReferenceProperty的原因是什么?
- 甚至数据库的查询user_instance.teams也会做与ndb的for循环相同的事情。但是在ndb中,我们明确提到使用for循环。
- 当我们执行user_instance.teams时,幕后发生了什么?
提前致谢..
答案1
小编典典蒂姆讲得很好。我们发现,一个常见的反模式正在使用引用属性并一次加载一个引用属性,因为符号“
entity.property1.property2”不能清楚地表明第一个点会导致数据库“获取”操作。因此,通过强迫您编写“
entity.property1.get()。property2”,我们变得更加明显,并且通过简单地说“
entity.property1.get_async”,使批量预取变得更加容易(没有Nick博客的复杂解决方案)。 ()”一堆实体-
这会在不影响结果的情况下将单个批处理get操作排队,并且当您下次使用“
entity.property1.get()。property2”引用这些属性中的任何一个时,这不会启动另一个获取操作,但只等待该批处理完成(第二次您这样做时,
__完成)。 同样,这种进程内和内存缓存集成是免费的。
Big impact when set property type in-properly
In sqlserver DB,for the string,we have types: NVARCHR,VARCHAR.
In mapping class,if you use default set the type to "string" but the column type is varchar in DB,that will cause a transfer in DB side when searching comparing,if unfortunately you have a huge data in the table,the DB transer will be more huge,it will deadblock you DB.
To solve it if in DB its type is VARCHAR,in Mapping class should use:
[Property(Type = "AnsiString")] instead.
com.intellij.uiDesigner.propertyInspector.properties.BorderProperty的实例源码
@NotNull @Override protected BorderProperty compute() { return new BorderProperty(null); }
private static boolean isPropertyDescriptor(final IProperty prop) { return !prop.getName().equals(BorderProperty.NAME) && !prop.getName().equals(RadTabbedPane.TAB_TITLE_PROPERTY) && !prop.getName().equals(RadTabbedPane.TAB_TOOLTIP_PROPERTY); }
@NotNull @Override protected BorderProperty compute() { return new BorderProperty(null); }
private static boolean isPropertyDescriptor(final IProperty prop) { return !prop.getName().equals(BorderProperty.NAME) && !prop.getName().equals(RadTabbedPane.TAB_TITLE_PROPERTY) && !prop.getName().equals(RadTabbedPane.TAB_TOOLTIP_PROPERTY); }
@NotNull @Override protected BorderProperty compute() { return new BorderProperty(null); }
private static boolean isPropertyDescriptor(final IProperty prop) { return !prop.getName().equals(BorderProperty.NAME) && !prop.getName().equals(RadTabbedPane.TAB_TITLE_PROPERTY) && !prop.getName().equals(RadTabbedPane.TAB_TOOLTIP_PROPERTY); }
今天关于xmpp 用户属性扩展 JDBCUserPropertyProvider的讲解已经结束,谢谢您的阅读,如果想了解更多关于Android 属性之 build.prop,及 property_get/property_set、App Engine中的db.ReferenceProperty()与ndb.KeyProperty、Big impact when set property type in-properly、com.intellij.uiDesigner.propertyInspector.properties.BorderProperty的实例源码的相关知识,请在本站搜索。
本文标签: